Friday, 24 of May of 2013

Tag » compiler

The power of Basic and the WIN32 API’s !

It is so easy for a programmer to want the programming language to do all the work for them, but for myself I just want a core compiler which allows me to build what I want, the way I want it. I have noticed that my style of coding doesn’t actually use many of the more current features of the PowerBasic compiler. What is most important to me is the ability to access the Windows API (WIN32) and the core Basic command set necessary for most logic and low level coding.  Few may realize that I have been programming using PowerBasic since version 5.0 (current version is 10), when it was still called PBDLL rather than PBWIN. My latest software, EZGUI 5.0, was written using PowerBasic 9.0, but it almost was written using a much older version which was 6.1. I actually started coding EZGUI 5.0 using the 6.1 compiler, but I maxed out the compiler (meaning it could not handle the size of the source code I had), so I was forced to move to a newer compiler. I decided on jumping straight to the 9.0 version, since I would have the benefit of a few new features which would compensate for the larger embeded runtime code of the compiler. Each new version of the PowerBasic compiler has added a few kilobytes to its embeded runtime code. I was trying to keep the EZGUI runtime DLL’s as small as possible so this mattered a lot to me.

The point of this discussion is that even a much older version of PowerBasic had the majority of features I required. While some PowerBasic users are always looking to the next version of the compiler to solve their problems, I have been learning how to maximize the use of the core parts of the language which have been there for years. PowerBasic has been so rich of a language for so long that there aren’t many new features that turn out to be a “must have” for me. I upgrade to the new versions only to be current, but I can live with a much older version of the compiler.

The real power of Powerbasic is its core language and the ability to access the Windows API. Things like the OLE string engine (for variable length strings), memory management built in (no need to allocate and deallocate memory), rich logic command set (ie. IF THEN, DO LOOP, FOR NEXT), rich string command set and plenty of low level stuff (ie. pointers) and I am happy.

The real challenge when using PowerBasic has been the GUI (graphic user interface) stuff. That is why I created EZGUI. By tapping into the power of the Windows API and building a reusable library which simplifies coding (aka. RAD), I have the best of both worlds. EZGUI taps into features of Windows that most PowerBasic programmers aren’t even using right now. One good example is the ownerdraw engine in EZGUI. The ability to be able to customize the look of existing controls is so very useful.

The problem with programming today is that it is too “plug and play”. Programmers want the programming language to do all the work. True, building reusable code makes sense, but I have always felt that reusable code is something the programmer does for himself according to his own needs. For me, I wrote my own GUI library so I didn’t have to “reinvent the wheel” as they say. Even with a high level library like EZGUI, I also made it quite low level too, since I felt that it would not make sense for me to try to build everything a customer would want, but instead provide the tools for them to build what ever they required. There is no way to build a library which does everything. At best it can be a stepping stone which gets you closer to what you want.

At first glance, programming languages which allow you to quickly drag and drop components seem so productive. That was the allure of Visual Basic. It was a great tool for designing a user interface, but at some point you have to start writing some real code to get some work done and that is where problems may occur. Experienced Visual Basic programmers often found themselves having to tap into the Windows API to solve many a problem. The real power was the ability to go beyond what was considered standard user interface design to create something totally new.

This is why even with an addon tool like my own EZGUI, it does not limit the programmers ability to customize and to go beyond what the library may provide. Even though EZGUI is a GUI framework of sorts, it was designed so you can easily integrate pure WIN32 API’s into it. I actually want customers to go beyond EZGUI it they have to, to solve a problem. EZGUI is just a stepping stone getting you closer to the power of the Windows API. Yet, I also designed EZGUI so it has plenty of its own low level features, so you can do an amazing amount of customizing without having to resort to the Windows API. The rule is, “try to do it with EZGUI first, but if you can’t then there is always the Windows API”. This has worked well for my customers.

The BASIC language makes the code more readable (more natural) as well. Modular design is easy using simple, standard subroutines and functions. While PowerBasic can do some degree of OOP and classes, I don’t require it. I find OOP only gets in the way of clean simple code. The idea that everything needs to be in a class is just wrong in my opinion. Purely procedural code produces faster and smaller applications and is easier to debug.

I am sure some who read this blog may object and think “what can you do with a simple language like Basic ?”. Yet I have been very pleased with what I have been able to accomplish with EZGUI 5.0 Professional. The feature continues to get more and more advanced.  One of my favorites has been the new OpenGL based glCanvas control, which makes 3D so easy to do. Yes, PowerBasic has done me well. As Bob Zale put it, one can “compile without compromise”. !

 

 


Comments Off

Compile without compromise !

I wrote an article once for Betanews. com ( http://betanews.com/2012/04/20/take-away-developers-pcs-and-send-them-to-walmart/ ) where I humorously suggested that programmers should have their computers taken away and be forced to buy the replacements at Walmart (mass market PC’s). While I never really expect programmers to do this, I was trying to make a point.

The main stream programming world is stuck on development tools like Visual Studio and the reality is that you really do need a power house computer to get decent compile times. For example I came across this blog (and no disrespect for the author) ( http://successfulsoftware.net/2012/10/25/lean-mean-compiling-machine/ )and he specs out what he considers a reasonable PC for development. I give him credit for opting for a more cost effective Core i5 CPU, when many programmers likely would not want anything less than an Core i7 CPU. I did have to giggle a bit when I saw the specs for RAM was 16 gigabytes.

For a long time PowerBasic programmer, like myself, this is humorous. Why ? Nothing against the programmers, but Visual Studio is simply a resource hog, especially compared to a compiler like PowerBasic. Ok, PowerBasic doesn’t have all the bells and whistles of Visual Studio, but it does have one thing which makes it different.

As Bob Zale said about PowerBasic ( http://www.powerbasic.com/aboutpb.asp ), it lets you “compile without compromise” !

What does that mean to me ?

I just compiled (while also running IE 9.0 at the same time with my wordpress blog up) EZGUI 5.0 Pro and the compiler reports that it took only 2.3 seconds to compile 63,194 lines of source code. If that sounds fast to you, you may be wondering what powerhouse of a computer am I using ?

This is my Vista Home Basic PC which I upgraded this  last year just so I could test the Windows 8 preview on it. I installed memory, a new CPU and a decent 3D video card. So what does this powerhouse computer have in it ?

  • Vista Home Basic (32 bit)
  • 3.2 ghz Pentium D CPU
  • 2 gig memory
  • 150 gig hard drive
  • 3D Video card (comparible to those in the $50 range)

This PC has a Windows Performance number of only 3.4, so compared to the typical programmers development PC, this is not really a powerhouse (just for me it is).

Now this is a real powerhouse PC for me, since I only recently moved to it after my trusty Windows XP computer crashed. Up until recently all my development was done on that computer and it only had a 2.5 ghz Celeron CPU, 40 gig hard drive and 768 meg (not gig) memory. Even on that computer it only took a few seconds more to compile EZGUI 5.0.

The PowerBasic core compiler was written in assembler and it shows. My old PC was about comparible to todays lowliest Atom CPU and how many programmers today would use a PC with an Atom CPU as their main development machine ?

Yes, PowerBasic does allow you to “compile without compromise“. The speed of their compiler is just amazing, in my opinion. For PowerBasic programmers compiling is done in seconds, not minutes.

 

 


Comments Off

The Windows weakness !

Now don’t think I don’t like Windows 8 from the title of this article. I just think that one of the key issues Windows faces right now, may be the product of this weakness.

Everything is going mobile and for mobile battery life is everything. The question of whether to use ARM over Intel all comes down to battery life. Now Intel CPU’s seem to not look so good because power usage, but maybe the real problem is with Windows and how software is developed. What do I mean ?

Because I started programming in the days of DOS (even before that), 640 KB memory and no hard drives, using the resources of a computer efficiently were a high priority. Compiled code had to be small. Compilers had to be fast and produce small executables. Apps had to use memory careful, even disk space carefully. The new generation of programmers have grown up on computers with huge amounts of memory and diskspace. They grew up on processors which had their speeds defined in gigahertz, rather than megahertz. They have been spoiled.

To add to this, somehow object oriented programming design, rather than simply providing one more tool for programmers has somehow become the core model for programming, as if anything else is the product of ignorance. I hate to burst the OOP bubble, but it has not produced the benefits everyone thought it would and I believe it may be at the core of the Windows problem. One has to appreciate how human readable code is converted to machine language to appreciate this. If you mention to programmers that OOP requires a few extra “hoops” to jump through to accomplish a task (aka. pointer to a pointer to a pointer), their first reaction is “big deal”. Computers are so fast that it makes little difference. It is that mindset which actually makes programmers fail to appreciate the value of performance.

The problem is, that this may be true for a single line of code, but when you multiple this by millions upon millions then it adds up to a lot of waste. Also the nature of object design does not lend itself to minimal machine code generation. Objects are so complex at times that they can actually lose efficiency.

You may say this it does not matter anymore, but I think it does. Herb Sutter in his talk “Why C++ ?” discussed how both in mobile and in large data centers (which service all this mobile stuff), performance once again has become critical. I will go one further, even C++ because it leans towards OOP more than C, may slow things down because the more you depend upon OOP, the slower things can become.

I had an interesting experience. I was talking to a friend, who I learned used to work in the software industry years back. He asked me what programming language I use and I said Powerbasic. He was surprised when I said I don’t even use OOP at all. I was describing what I was able to do with PowerBasic and the GUI engine I built using it (EZGUI is non-OOP based and relies totally on the WIN32 APIs). As usual I noted how fast my code ran and how small it was (both vital to performance), because of how it was created and because of using PowerBasic.

I started to tell him about all the features in this library. Just think, EZGUI is actually a GUI framework of sorts (a middleman between your app and the WIN32) and it contains the following:

  • GUI engine for forms and controls (all the standard WIN32 controls and most of the common controls) and support for most often used features
  • Common dialogs, even being able to customize them
  • thread engine
  • subclassing engine
  • superclassing engine
  • ownerdraw engine
  • customdraw engine
  • graphics engine (GDI and proprietary)
  • 2D sprite engine
  • 3D OpenGL engine
  • multimonitor support
  • theme support
  • drag and drop engine (ie. build your own visual designer)

it also has a number of custom controls built in, which go beyond the ones provided by Windows such as:

  • masked edit control
  • shape/hot spot/splitterbar control
  • drag handle control
  • turtle graphic (vector graphics) control with built in turtle graphics macro language
  • canvas control with built in proprietary 2D Sprite engine
  • opengl canvas control with built in proprietary 3D OpenGL scripting language
  • files listbox control
  • property listbox control

There are a number of important features not provided by Windows which I had to design myself, such as the Sprite engine, 3D engine,  the autosize engine (autosize controls when form is resized) and layer engine (show and display controls on separate layers. Now of course EZGUI does not do everything, but it does a lot and if you need to extend it you can easily integrate pure API code calls to compliment it.

When I gave an overview of what EZGUI does to this friend I posed the question of how big do you think it is ? I told him the main runtime (which has 90% or more of the functionality) is only about 700 KB in size. His response ? (paraphrased)

“You mean 7 megabytes, right” ?

I said, “no, I mean 700 Kilobytes. The total of all the runtimes (DLLs) together come to about 1 megabyte”.

His response was “that’s impossible”!

Just think, when describing all the features first, this friend who was more familiar with OOP than procedural style coding, could not believe that my library could do all it does and be only 1 megabyte in size.

To add to this, years back I was beta testing a product called MediaForge, which was an amazing multimedia development tool and I communicated a lot with its sole developer, Rob Adamson. Rob was a really, really good C programmer and knew his stuff. MediaForge could be extended using plugins written as DLLs, so I wrote my original Turtle Graphics engine as a plugin for MediaForge. It was just an experiment to see if I could do it and how well Powerbasic would do in creating such a plugin. It worked quite. The thing that struck me was that Rob was impressed with the size of the DLL’s I could produce with PowerBasic. It was on par with what he was doing with C.

The problem with Windows today, I believe, is how we write software. Software is bloated and slow, so no wonder the hardware has a tough time keeping up with it. The software is what makes the hardware look bad and this does not appear to be limited to Windows, but even IOS and Android (everybody uses OOP today). According to Herb Sutters talk, he commented how all these platforms have had problems dealing with performance. Why do you think all the mobile devices today are going the route of mult-core CPU’s ? Even dual core is not enough anymore, but now quad cores are becoming the norm. I see a mindset of “well the software is not fast enough, so let’s just add a couple more cores to the CPU and all will be fine”. So what about the software ?

Also look at the problems created by over eager hardware designs of computing devices. Everybody touts “retina” displays and PPI. The 3rd/4th generation IPads quadruples the pixels on the screen and everybody is excited. As a programmer who has been around awhile my first reaction is “the hardware has to do four times as much work now”. If software was slow before, it will be even worse now. Everybody touted the 4th generation IPad with its new more powerful CPU. “Wow”, they added so much more power. Has anyone ever considered that maybe they had to ? When they switched to the retina display, the CPU had to work a lot harder than before. Maybe Apple realized they need to spice up the IPad CPU even more to better compensate. The real question is, “is the performance today any better than in the previous years, overall” ?

Maybe we need to go back to basics and learn how to write better software. Software needs to be more efficient. Performance needs to be a high priority.

I also feel that programming has been made too complex. In the old days, many turned a hobby into a trade by learning programming on their own. Languages like BASIC introduced many to programming. I really don’t feel that many who moved on from BASIC to C eventually, did this because they did not like the language. I feel they likely felt they needed more power and the only languages touted as high performance were things like C. C does not have a natural syntax to it, like BASIC does. C is harder to learn. Even VB.NET has destroyed the BASIC language syntax by moving closer to its C# cousin. OOP has taken over languages to the point where they are not naturally any more, but more complex.

What we need today is programming languages with a more natural, easy to understand syntax (like Basic). We need programming languages which compile lightning fast and produce tiny executables. We need to get away from the overuse of OOP (OOP adds too much overhead and complexity). We need to produce simpler, less complex API’s for programmers to access. API’s need to be built in multiple levels, starting from low level to medium level and then to high level, building on each previous level. Modular design is not limited to OOP, but has to do with the layout and levels one builds into an API (or Library). IMO, Procedural based libraries can be written in such a way that we could likely double the performance of many of our computers todays by just writing software better.

Would you like to see what a programmer is really made of ?

If the average programmer using say “dot.net” likely has a computer with at least a Core i7 CPU, 8 gigs of memory and terrabytes of disk space, then why not make him (or her) , for a couple weeks, be forced to use a computer with an Atom CPU, 1 gig of memory and a 32 gig SSD ? Now see how quickly they start crying out “it’s all too slow, what do I do now” ?

Now many will say, “that is not realistic and it can’t be done”.

I say to you, yes it can. While I just recently switched to a better PC (Pentium D 3.2 ghz CPU and 2 gig memory) because my long time trusty XP PC experienced system crashes multiple times and I had to move to something more reliable, for the previous 6 years or more I have been developing all my Windows software on a Windows XP computer, with a 2.5 ghz Celeron CPU with only 768 megabytes of memory. Celeron CPUs have the same reputation as Atom and have not been known for power. The current Atom CPUs are more powerful today than my XP computers Celeron CPU. The Atom dual cores are extremely powerful compared to the desktops found in the early 2000′s (when XP was released).

How many programmers today would be willing to use a PC with an Atom CPU as their primary development computer ?

I have no problem with such a computer. I can easily compile 60,000 lines of code in just a few seconds using PowerBasic on such a computer.

My entire development system (PowerBasic compiler and EZGUI 5.0 Pro) only take about 20 megabytes of disk space and will run fine on about any PC made in the last 15 years. Visual Studio weighs in at 2 gigabytes or more of disk space. That means I am developing software with a set of tools that take up 1/100th the space of Visual Studio. I even designed EZGUI so one could even hand code their apps (like we used too) if they didn’t like working in a Visual Design environment.

I do like some aspects of Windows 8, even Metro (even though I prefer the desktop), but maybe we need a real programming renaissance today. The power of native coding using native API’s using better compilers could produce some amazing results. If less hardware is required to run the software, cheaper laptops and tablets could be manufactured, since the software would require less.

 

 

 

 

 


Comments Off