Basic – a case for my favorite !

Basic ! Oh, how foolish one must be to use such an old fashioned language, right ? Wrong !

It is time to put to rest the idea that Basic is old fashioned, obsolete and a dead programming language.

Not your fathers Basic.

Basic has come a long way since the days of GW-Basic or QBasic. It has changed. It has matured. It has grown. What remains of the Basic many remember are two things.

Basic is based on a more Natural (English like) syntax than any other language.

Core Basic hasn’t changed (ie. SUB / FUNCTION / IF THEN / LOOP)

Beyond this, Basic has changed, has matured. How ? By taking the best from other languages, such as Pascal, C or Fortran, and adding it to Basic, while maintaining the Basic style of naturalness. Any new features added to Basic, must feel natural, for it to be truly considered Basic. Terse syntax from other languages is avoided if possible.

Programming bias.

Despite Basics maturity today, some programmers who may like Basic, still avoid it. Not because it is a bad language, but because of programming bias. Especially C++ and C# programmers will carry this bias, as if Basic is as bad as the plaque. Now why should programmers be afraid to use a programming language, which is capable of giving them the power they are looking for from such a language, simply because of bias ? Now that is sad and a shame.

Oh, give me a break !

Now, I won’t say that any programming language is the perfect language, since programmers are individuals with different styles and needs, so it would not be right or fair to say that Basic is the only language one should use. But I do believe the unfair bias of many programmers may prevent some from benefiting from a language which just could make a real difference in their software development. Does it make sense to let bias prevent you from using a tool which can help your business ? Even if Basic is not the primary language you prefer to use, it can still be a secondary tool to be used when it could really make a difference (meaning you don’t have to give up for day job, just to use Basic).

PowerBasic, the one I know.

I have mentioned PowerBasic in previous articles I have written, because it is what I have used for the last ten years and it is what I know. So its about time I introduce you to PowerBasic and tell those who read my articles, why I use it and how Basic has matured over the years. PowerBasic is definitely not your fathers Basic.

PowerBasic, is what C should have been years ago.

There is a reason why many of the Microsoft frameworks needed to come into existance. Simply put, the Windows API was a pain to write applications for. It just was not easy to write Windows applications in the days of Windows 95. You most likely would have to use C and write things like window classes, message loops, window or dialog procedures and you would definitely have to write a lot of SendMessage (API) calls just to make controls do something. It was slow going and a bother to many.

So Microsoft came up with MFC (Microsoft Foundation Classes) so make things easier, which it did to a degree. But even MFC was not a panacea for some. Over the years, Microsoft programming languages have tried to improve productivity, by adding new frameworks, particularly dot.net. Yes, productivity is much better now, when it comes to writing Windows applications. But at a cost. Herb Sutter in is talk “Why C++?” says it all. Simply put, he brings out that such productivity was at the cost of performance. That is his viewpoint, so don’t argue with me about it.

But something strange happened. PowerBasic came from obscurity and progressively built a strong base of users. In the old days (back with Powerbasic version 5.0) there was no GUI tools, no GUI command set. Those, like me, who were programming with PowerBasic had to learn how to use the raw Windows API. There was no MFC for PowerBasic. No dot.net. Just the raw Windows API. The strange thing though, was that PowerBasic programmers had two things going for them, that gave them an advantage over the C programmers of days gone by (before MFC).

(1) The PowerBasic peer to peer forum with a world wide group of excellent programmers.

(2) PowerBasic, was Basic, so code was more readable, easier to maintain.

The first challenge of grasping the Windows API, was dealt with because of PowerBasic’s online forum. The forum brought together the best of the best, the cream of the crop. To this day I am deeply impressed with the knowledge of many who visit these forums. Powerbasic takes this forum so seriously, you can not use an alias. Yes, some of have actually lost their privilige to use this forum, simply because they tried to get away with using an alias. This forum is a professional forum, where programmers take seriously sharing with one another the secrets of tapping into the Windows API. They do not hide who they are, but they share their knowledge of the Windows API. Because of this, over the years, a number of these forum users have become experts of a sort in specific aspects of Windows. From these, some have become third party developers of tools which make Powerbasic even better.

Because Basic is so much more readable and natural than C, code using the Windows API actually is more readable and makes more sense when you see it in Powerbasic syntax, compared to C syntax. PowerBasic is what C should have been, when Windows first came along. Programmers would have had less problems in writing applications and would not have needed bloated frameworks, which may help productivity, but also slow down applications and also make them resource hungry. In the days of Windows 95, you could live with just 8 or 16 meg of RAM. Today, Windows is so resource hungry that it requires at least 1 gigabyte of memory. Powerbasic is so efficient a language, you can still write apps for a Windows 95 computer with little memory, so imagine how well they run on Windows 7 (or 8) with 2 gigabytes memory.

The power is in the compiler.

You may laugh, when I say that the people at Powerbasic count CPU cycles, but in the end they get the last laugh. Programmers have wasted the power of the PC for years, simply because they assumed the computer was so powerful they didn’t have to care about the size or execution speed of an application. Computers have gottem more powerful, but we don’t see the benefits, because Programmers have not cared about writing efficient software. Well, at PowerBasic they do care and now with the advent of the tablet computer, they get the last laugh. Because tablet computers have minimal hardware, the bloat in most applications shows up now. As Herb Sutter so well put it, “the free lunch is over”.

There are two things PowerBasic programmers are confident of when they write software. First, they know the compiler was designed to generate the fastest, smallest possible applications. Second, they are confident that the compiler generates reliable machine code. But the real power in Powerbasic is the language.

The power is in the language.

While, PowerBasic programmers may seem at a disadvantage because they have to resort to writing applications using the Windows API, the strength of Powerbasic is the language itself and how it makes it possible to do some amazing things. Access to the Windows API is easy because the language was designed to tap into the API. Powerbasic can make calls into the Windows API, into DLL’s written using C or C++ or Pascal or other languages and it even handles low level COM, which allows it to integrate itself with all sorts of other languages. I am not a COM expert, but there are those who use Powerbasic who grasp COM very well and PowerBasic’s latest compiler (version 10) has strong support for COM interfaces. Powerbasic also has its own object oriented features (classes) built on the COM features of the Windows API. So if you prefer writing classes or using COM, then PowerBasic has features for you.

But you don’t have to write applications using classes or any OOP at all if you don’t want to. Like me, there are those who prefer 100% procedural style code and you can still do powerful things with Windows, without any OOP at all. The choice is yours though.

When it comes to building the user interface for applications, PowerBasic for awhile was at a disavantage, but once again their peer to peer forums saved the day. It was from these forums that programmers began to encourage drag and drop design and from this a number of solutions came forward. Powerbasic developed their own Visual Designer and their own simpler UI command set, so anyone can build a Windows application using their proprietary DDT (Dynamic Dialog Tools) command set. It just makes things easier. Then some third party developers, built drag and drop designers which emulates Visual Basic in some ways, but using the pure Windows API for UI coding, which provides an alternate way to develop applications. Third party developers began to create custom controls, such as grid controls and even powerful graphic engines and skin engines. Myself, I went the route of building a GUI engine (a GUI framework) as a third party developer.

The reason such third party tools became possible though, was the power of the language in the first place. With some other languages, like Visual Basic (5/6) extensions to the language often were written in C++ and not the language itself. With PowerBasic, the majority of third party addons are written in PowerBasic and not C++. We extend the language using the same language.

Low level is the name of the game.

The compiler itself generates very fast machine code, but the language was designed with many of the power constructs one would expect from C or C++. For example, PowerBasic can be very, very low level when you need it. You can work with pointers, pointers to pointers, etc. You can have code pointers as well, so it makes it very easy to dynamically call Windows API’s without having the application be totally dependent upon those API’s. I use this often myself. For example, how do you make a DLL, capable of accessing features unique to say Windows 7, but yet still able to run on Windows XP ? Simple. In Powerbasic you just call a few API’s to see if an API exists and what operating system it is, then if it exists you can dynamically load a DLL and call the functions via an address (CALL DWORD command in Basic). If the API is not present then you simply provide an alternate way of handling the task.

Powerbasic allows you to define specific variables as Register variables for improved speed and it is completely under the programmers control. PowerBasic can even do inline assembler, so you can combine Basic and assembler together.

PowerBasics string command set is as good as it gets, both ANSI and Unicode. The string functions are optimised for speed as well. Powerbasic uses Windows OLE API’s for storing strings, so you can have huge strings in memory (how about a 100, 200 or 500 megabyte string ?). One nice feature I like is the ability to define structures (TYPE in Basic) via pointers, so I can actually use a string to store the data, but simply access the data via a pointer.

PowerBasic has functions for working with bits and bit flags. You can even have bit arrays. It has a wide variety of built in data types, even QUAD based integers, 80 bit floating point and variants. You can even do unions and overlay one data type over another.

Advanced command set.

PowerBasic has a number of matrix commands for high speed access of a matrix (ARRAY in Basic). For example you can sort an array, but have the indexes to each item (in the proper order) written to a second array so you don’t modify the original array. And it is fast !

Powerbasic can do TCP and UDP communications, which is a very popular feature of the language. Building applications which interface with external hardware is also popular using serial communications, which is also built into the language. PowerBasic has its Dynamic Dialog command set (for UI’s), graphic command set and printing command set too.

PowerBasic comes with its own COM browser for generating pure PowerBasic code for accessing external COM objects.

And if one can’t do it with native PowerBasic commands, then one still has access to the pure Windows API and PowerBasic programmers are known for doing all sorts of things, even if the language does not directly support something.

What have I done with Powerbasic ?

While I don’t want to go into detail about my own work with PowerBasic in this article, this much I can say. I keep being amazed at what I can make the Windows API do. There is always new stuff I find that I can do. I started out building a simple GUI engine, to make it possible to build PowerBasic applications without using the Windows API. Today, I do stuff, using PowerBasic, that demonstrates that the Windows API is a powerful thing and still quite viable even with Windows 8. I have learned how to tap into the Windows DIB engine and built my own Canvas control, with low level DIB support and a proprietary 2D sprite engine (no DirectX needed). I have learned how to tap into features like Ownerdraw, so I don’t have to buy a number of third party OCX controls like Visual Basic programmers were known to do, but I can build controls to my own exact specifications. From this I built my own Files Listbox control and Property Listbox control and others. I work with things like threads, complex window regions (you know those apps which are not rectangular, but are shaped like an object), image filters, superclassing and subclassing. I built my own drag and drop engine, just so I could build my own visual designer using it. My most recent task, was to build a real OpenGL based control. You aren’t limited t just one graphic window, but you can have multiple 3D OpenGL child windows all on the same form. It even has its own proprietary 3D scripting languge and can display STL 3D file format models with thousands of polygons. Not bad for Basic !

This much I can say is that much of the credit of what I have developed goes to the amazing PowerBasic compiler. To be able to produce applications and libraries with an amazingly small footprint, highly reliable and fast, just could not have been done without Powerbasic.

Can’t do it justice.

What I say here, just can not do justice to Powerbasic. So if you are thinking of something like GW Basic or QBasic and spaggetti code from Basics of old, when I mention Basic, please realize that Basic has grown up. Basic has matured. Basic today can be on par even with the latest C compilers (Powerbasic is more akin to C, than C++). So when someone comments about Basic being a dead language, Basic being old fashioned or Basic being obsolete, then just remember, they really don’t know what they are talking about.