Friday, 24 of May of 2013

Tag » easy

What is missing in programming today ?

To answer this question in one word:

Simplicity !

What do I mean ?

To be honest I get tired of negative comments by mainstream programmers when I ever mention that I program in Basic. Actually I program in a modern high powered Basic called PowerBasic.  Everybody today seems to program in C#, Javascript or some other cryptic language. The majority assume that variations on C (C++, C#,Java) provide the most power when it comes to programming, but they miss the boat on one key aspect which is simplicity. This is why I prefer Basic over other languages. The code is readable and simple. There is no need for brackets to align code. It uses operators which are very similar to we learn in school when learning math (of course X is a alphabetic character so it needs to be replaced with something else such as * for multiplication). The one thing which I have always felt is important when coding is simplicity. The less lines of code necessary to accomplish a task the better. The closer code is to human language the better. The easier it is to remember code syntax and common parameters the better. The simpler a library is the better.

This is one reason I also object to the overuse of OOP (Object Oriented Programming). Don’t get me wrong, the ability to write classes and to create reusable objects is a valuable asset to a programming language, which is why PowerBasic added it to its compilers. The problem is that while objects have their place, they should not rule the language. In todays modern languages, it seems everything is an object, everything is written in classes. This is a big mistake and I strongly feel that it leads to two serious problems with modern software.

(1) Overly complex software.

The more complex software is the harder it is to write and the harder it is to maintain. Some would argue that OOP makes software easier to work with not harder, but I do not believe this. I strongly feel that procedural based API’s produce easier to understand code and can be written more quickly and they can be more easily maintained. For OOP to work it requires too much thought up front and often it produces an overly complex solution for something which could have been done using a much simpler solution using a procedural method. The obvious proof of how OOP has made software overly complex is the fact that most software today is bloated and slow, despite the improvements made in computer hardware. I really don’t think this can be denied.

There is another aspect to this which I think is important. The more exposure one has to how a computer really works at its lowest level the more one can appreciate what a higher level language really must and is doing. Before the IBM PC became popular, I was learning programming on a Commodore 64. I used interpreted Basic. I also used the Abacus Basic compiler (yes, there were Basic compilers in those days). But I also finally started learning 6502 machine language (not assembler, but real machine language). Learning machine language was extremely valuable in appreciating what the higher level programming languages were actually doing. I wrote some extensions to the Basic interpreter to add more commands to the language. I even wrote my own compiler, so I could write the fastest software possible. The compiler was very BASIC like in nature too.

Having worked with machine language it helps me appreciate why many programmers today don’t full appreciate the effects OOP has produced on programming languages. While I do not understand why so many programmers are drawn to languages which are overly abstract (like C++, C#), I do feel that maybe it would be good to encourage the software industry to rethink its love affair with the abtsract. Have you ever notice that when programmers talk about the superiority of C++ over other languages they often refer to the term “abtraction”. Herb Sutter in one of his talks about C++ likes to use the term abtraction as if it is good thing.

One definition of Abstract is:

“Existing only in concept and not in reality”

So why do programmers think that an abtraction is closer to reality ? Now I can see how an abtraction (OOP) may be useful for something that does not actually exist yet, but why would one want to use abstractions to explain the real world or to do real world tasks all the time ?

If I have to write software which does accounting , which is a real world concept, then writing simple code which does accounting math is all I need. Even accounting data does not require objects. Data is data. Accounting data can easily be defined using data types or structures, which is what most closely resembles it. If the data can change, then simply use dynamic data types to allow such changes, but data is still data.

The overuse of OOP , as well as other overly complex development methods has also causes us to lose a precious thing in our software and that is performance.

(2) Lack of Performance.

Simplicity is also key to performance. Simply put, the less work a CPU has to do to accomplish a task, the faster the task is finished. The more complex our code is the more work the computer has to do. Now many would likely take issue with this and say “we are more productive today and our software is plenty fast enough”. I would strongly disagree. Do we really appreciate how powerful computers (even a phone) are today ? I was developing software when computers only had floppy drives (no harddrive), had only 640 KB memory and CPU’s which were less than 25 mhz in speed. Even in the early days of DOS, harddrives were only a few megabytes in size (ie. 20 meg), memory was less than 1 megabyte and CPU’s were slow. Yet programmers could write applications which handled many complex real world tasks. Today the average computer has a CPU which is 1 to 2 ghz in speed and multicore, with really fast GPU’s or Graphic cards, with 2 to 4 gigabytes of memory and harddrives with half a terabyte of space. Yet software is bloated and slow.

Obviously something is wrong. The only answer is how we write software. Possibly OOP plays a big part. Maybe system frameworks are poorly designed. The point is that software need not be so poorly written that it requires huge hardware resources. Maybe all the extra abtraction added to programming languages is producing slow and bloated software.

Having spent the last ten years writing a GUI engine I can appreciate the value of “small and fast”. The original version of EZGUI had a runtime DLL which was 122 KB in size. Now that is kilobytes, not megabytes. Oh how I thought that was so huge ! Today the main EZGUI 5.0 runtime DLL is about 700 KB in size and again felt it was too big by my own standards. Yet when I think about how many features are compacted into that DLL it is amazing that it is as small as it is. I give the credit to Powerbasic for their wonderful compiler. But I also have to say that because it was written using a purely procedural style of coding with no OOP (abtraction) used at all, this I believe was a significant reason why it is as small as it is. Now when you combine the EZGUI 5.0 main runtime with the few other secondary DLL’s that come with it, the total is about 1 megabyte.

Now compare this with say the Visual Basic 5.0 runtimes:

msvbvm50.dll – 1324 KB

comdlg32.ocx – 150 KB

comctl32.ocx – 595 KB

comct232.ocx – 161 KB

mscomct2.ocx – 633 KB

richtx32.ocx – 208 KB

Just to be able to have the support for basic forms and controls plus some of the standard common controls and dialogs, these runtimes totaled  3071 KB (over 3 meg)

Yet at about 1 megabyte (or 1/3 the size of the above VB runtimes) EZGUI has the support for the basic GUI features of the VB runtime, plus the following:

  • Thread engine
  • Subclass engine
  • Drag and Drop engine (build your own WYSIWYG Visual Designer)
  • Graphics engine (ie. DIB’s, image rotation, 22 image filters, RTF text, bitmaps, imagelists, icons, polygons)
  • 2D Sprite engine with alphablending and antialiasing
  • 3D OpenGL based control with 3D scripting language
  • STL 3D file format support
  • Turtle Graphics scripting language
  • MCI control with easy media scripting language
  • OwnerDraw engine
  • CustomDraw engine
  • customize common dialogs
  • dynamic region generation (non-rectangular windows)
  • game loop engine with precision timing
  • low level graphics (ie. direct window DC drawing or copying)
  • print engine
  • built in custom controls – Canvas, Turtle Graphic, 3D buttons, shape/hotspot/splitterbar,property listbox, files listbox, masked edit
  • Theme support
  • multimonitor support
  • autosize engine
  • control search functions
  • Layers engine
  • Registry access

Now all of that, but at one third the size of the above VB runtimes. Yes it was written using Basic, a simple and easy to understand language. It was written without a single bit of OOP, purely procedural style code. It executes fast.

Now don’t underestimate the PowerBasic compiler I used. The EZGUI runtimes internally uses things like complex data types (structures), code pointers, data pointers, dynamic memory allocation, register variables (for faster code). It directly accesses both the Windows API (WIN32) and the OpenGL API. The point is that software can be written to be faster and smaller, while still being readable using an easy to understand language like Basic, without the need to use OOP. Now PowerBasic does support OOP in those cases where it really is necessary, but I find it is rarely needed.

So why should programing be complex ? It doesn’t have to be.

So why should software be slow and bloated ? It doesn’t have to be.

So why does software have to be hard to maintain ? It doesn’t have to be.

Yes, software development today is missing the key ingredient, simplicity! But it doesn’t have to be that way.


Comments Off

Coding is dead !

Does this sound like a strange thing to say ?

I don’t think so and here is why.  As a long time WIN32 programmer (using PowerBasic) I at times have tried to look into other programming languages used by the mainstream. I purchased an older version of C# just to play with and decided to watch some beginner videos online to see if I can make sense of how to use it. Remember, that I am a coder. When I say coder, I mean coder. I can build complex applications even without the need for a Visual Designer or a Code editor with a ton of wizards and intellisense.  Now I am not against the use of Visual Design tools. A good RAD visual designer makes UI layout quick and easy and is a must for most development, particularly when an app has a lot of forms in it. But for a simple app with say one form and a limited number of controls there is no reason why a programmer shouldn’t be able to code the entire thing by hand without the need for a Visual Designer. I also feel that library code should be as small as possible so one does not have to always resort to some kind of intellisense based code editor just to be able to use the language.

The sad thing is though is that Microsofts current mainstream programming languages (aka. Visual Studio) are less of a coders tool and more of an application builder where the user does more drag and drop and select from lists (intellisense) than actual coding. Just watching a few videos online trying to learn C# is quite daunting. I have to pose the question. If developers spend more time dragging and dropping and selecting namespaces, classes and methods from drop down lists than actually writing code, how good is the code they eventually have to write ? Personally, I feel that the art of coding may be dying. But does it have to be ?

I find that before using a RAD development tool, a programmer should be able to write a workable app without such an environment. One should be able to write an app using just a simple code editor (no intellisense required) and a minimal help document for reference. One should fully understand how the app really works at a low level, but also how the code execution really flows. Where does you app start ? How does the app create a window and populate it with controls ? How do those controls send events to the app ? How do you respond to those events ? How do you make the controls do something ?

The overuse of OOP has turned programming into a complex mass of classes and objects so that programming itself seems to disappear.

Now you might say, but what I suggest is impossible, nobody would be able to build anything in Windows ! Not only is what I suggest possible but I and my customers do this.

When I designed EZGUI (GUI engine for use with PowerBasic), I designed it do one could actually hand code an entire app. I actually have some customers who prefer to hand code the entire app and they do a very good job of it. I did also add a Visual Designer to the mix, but only because a RAD tool like a visual designer really does make sense, but not as the only option, but simply as an addon for those who need faster development. Yet being able to handle code the app helps one learn how things really work. You understand the code flow better too.

There is another advantage to learning how to hand code things. Programmers who are simply glued to a RAD environment will tend to have too great of expectations of the design environment and will more likely be poorer coders. Why ? Because instead first considering how to write some quick code to solve problems, they will tend to expect more from the RAD tool expecting it to do all the work. Nothing surprises me more when an end user requests some new feature for the RAD environment which could easily be done with justa  few lines of hand written code. If a RAD tool has to solve all problems so programmers don’t even want to write just two or three lines of code, then definitelly “coding is dead” and maybe this is part of the problem with programming today.

I am curious too. Those who strongly defend object oriented programming as the only way to code, do they say this because OOP is so proficient when it comes to coding or possibly do they say this because of one of two other reasons. Reason #1, they want the language and libraries to do all the work, so rather than write some code themselves they simply want a new object to be created to solve their problems (aka. don’t want to write any code themselves). Reason #2, maybe the idea of writing everything using classes and objects is more preferable since so much thinking has to go into design of the object first and this means that actually writing code is a much slower process. One can take all day to create that amazing object class, which only does some simple task, where a procedural programmer who is a real coder would have written 50 or 100 lines of code to do the same task in about 30 minutes.

Ok, maybe what I am saying is a bit strong and surely there are many good coders out there. Yet I do wonder about the state of programming today, when a seasoned procedural style programmer like myself finds even the simplist tutorials on a new language just totally confusing.  I really do not see what all the fuss is about with todays managed languages. Visual Studio is not friendly to new users.  Who came up with XAML anyway ? Have we been forced to go back to scripting languages again ? (XAML is a form of scripting and a very complex one at that) ?

Yes. maybe coding is dead !

Coding can be fun ! Coding is powerful ! Coding can actually be fast too !

Coding need not be overly complex either. It is possible to define a library for coding which is small in size, easy to understand and does not require documentation the size of an encyclopedia.

 


Comments Off

What is it with the love affair with C ?

I was just reading a blog today with an article about what the next big programming language should be. What gets me though is how often those who ponder a better programming language use C (or C++) as the basis or foundation of what the next language should be. My question is why this love affair with C++ ?

As a long time BASIC programmer, I can understand why some may have negative views of BASIC, since they often equate BASIC with the old interpreters of old from the 80′s rather than the new generation of Basic compilers. What few seem to appreciate is that, BASIC has grown, even borrowing from other languages like Pascal or C, but using its own style of syntax. Why is the BASIC syntax so important ?

Because it removes the cryptic syntax found in most programming languages today (like C++ or Java) and replaces it with something more akin to the language we speak. I don’t know why programmers are often drawn to the cryptic rather than the simple. Personally, I find even good old assembler easier to understand than C++.

So why is syntax so important ?

Two problems plague all software. First is code readability. Most software eventually has to be updated and things added. The easier it is to be able to read source code, the faster and easier it will be to add new code to it. Now I will say though that good modular design is a must, no matter what language ones uses, so even BASIC code can be a mess if not written correctly. But when written using good modular design, BASIC source code can be so easy to read that a programmer can write something and then come back to it a couple years later and more easily make sense of it.  The second problem is debugging. Again the easier it is to read source code, it makes it easier to find the errors in the code.

I am sure plenty who read this article will likely say, “but you can’t do the things I do with a BASIC language, like you can with C++”.  While not all BASIC’s are created equal, I use PowerBasic and it has many power features which rival any C++ compiler in my opinion. To be honest though, PowerBasic is more of a coders language than a visual language. But when it comes to coding, you would be surprised at the things you can do with it.

Two areas where I really find PowerBasic to be just right for me are with strings and pointers. PowerBasics unique use of the Windows OLE engine for handling variable length strings is just downright perfect for many. You can work with variable length strings just like you did using old time Basics. No need to worry about defining an array of characters or some other technique. No need to worry about garbage collection. The compiler handles it all. You just use strings like they were meant to be used, but they can now be huge in size. Now add to this the fantastic selection of string functions PowerBasic provides and you have a powerful tool for handling large amounts of text with excellent performance. The second area which is a favorite is pointers. PowerBasics implimentation of pointers rivals anything you would find with C. I use pointers a lot. PowerBasic provides multiple syntaxes for handling pointers in different ways, so there are many options for solving problems while providing clean readable code. PowerBasic can even let you define an array into a block of memory (DIM AT an address) so the array looks like a normal array in code, but it actually is a pointer to a block of memory from something else. For example I could have a string variable and put any data I want into it and then get the address of the string and Dimension a numeric array inside that string. When you add PowerBasics rich set of data types with the use of pointers some really amazing things can be done.

In the old days, using the Windows API (WIN32) was too hard for many programmers, so Microsoft moved on to alternatives like MFC, ATL, etc. The interesting thing I have found as a WIN32 programmer is that the Windows API is not as confusing as you would think when you see an app written using PowerBasic syntax rather than C. Because BASIC is simpler in syntax and easier to read, API source code actually makes a lot more sense. True the Windows API is not easy to learn, but using PowerBasic it is a lot easier to learn and use than using C.

Now consider this. The Windows API documentation is all written with examples in C or C++ and not BASIC. PowerBasic programmers have had to spend time translating most of this info into Basic source code. Yet when you see the PowerBasic version side by side with the C version, interestingly the PowerBasic version makes a lot more sense. Someone who never dabbled with the Windows API would likely be able to make sense of the PowerBasic version quicker than the C version, at least in my opinion I believe so.

We don’t need more cryptic programming languages today. What we need is more languages which follow the rule of “keep it simple” like Basic has done. Code should be more readble, not less. Add to this a compiler like PowerBasic which produces fast (and small) executables which rival anything you can build with a C compiler and you have a powerful combination.

For more info about PowerBasic check out their web site:  http://powerbasic.com

 


Comments Off