Categories
long Software and Programming

Programming and me

This started as a review of Free C/C++ Windows programming tools,
but became a rambling rant about my “history as a programmer”. You can skip that if you just want the beef…

1K Days.

I started programming with the Sinclair ZX-81, when writing programs in basic was the only thing to do with a home computer. Then came the Apple II, and like a lot of kids I went to courses teaching basic, and Pascal, and assembler. But when I got an Apple, it was obvious that you could now do something more then write programs on the damn thing: You could also play games. The advent of the floppy disk and cheap game copying made typing in the damn programs line by line unnecessary.

Then I got an IBM PC, and with it came a printer, and the home computer was converted from a game-machine to a word-processor. It took me time to make the shift, since at the time PC printers were horrible dot-matrix things that would mangle their threaded paper, while my typewriter fetish had reached it’s apex with a lovely Brother electric typewriter, with a preview window and white-out tape, exchangeable daisywheels (so I could have both Hebrew and English on the same machine – typing direction could be changed by flicking a switch). However, moving to a word-processor was a breakthrough, letting me edit and re-edit and recycle my drafts endlessly.

Pascal and Skinner’s Box

But back to programming. A friend brought me a collection of Role-Playing texts garnered from usenet and mailing lists. As an afterthought he installed Turbo Pascal, just to get a decent editor (I was using a partially-damaged version of WordStar, which had problems with his UNIX-based texts). Years later, as a 2nd year biology student, I wrote a small program to demonstrate something we’d learned in an Ethology course: A “skinner box” is a device that can be used to train a pigeon inside it by reinforcing certain behaviors – the bird gets a treat whenever it does something. It could also be used to stop certain behavior by providing negative reinforcement, the nature of which I leave to your imagination. A peculiar phenomena is that, if the box is run unsupervised in a way that reinforces behavior “randomly”, you still end up with a pigeon that acts in a very elaborate, “trained” manner. This is just an example of Darwinian selection in action, except that here behavior rather then genetics is selected. The concept seemed neat and powerful to me, so I fiddled with Turbo Pascal and wrote a program that wrote endless numbers to the screen (each in a different color, once I got more sophisticated); Each number had an equal chance of being selected initially, but there was another function that would randomly “reinforce” a specific number by increasing it’s chance to re-appear. Soon the screen would be awash with blobs of 2-3 numbers (and colors – it was quite entrancing to watch).

As a graduate biology student, I discovered the Internet on the lab’s Mac. This allowed me to while away the time waiting for my gels to gel, or run, or blot, or for my reactions to react. I would waste tremendous amounts of time reading newsgroups and later browsing the web. I also discovered e-mail, an incredibly powerful tool (which I used to interview religious Jewish SF fans in America for my what was my “breakthrough” story in my limited journalistic side-career) and fine time-waster in it’s own right (I discovered this by being drawn into a far-ranging and long-winded e-mail exchange with one of my interviewees).

Javascript Rocks

Facing the prospect of having to pay rent, I got myself a job as a technical writer at a friend’s company. I was also put in charge of the company’s website, which meant I had to learn HTML. This was the period where all the Internet pages were gray, at least until everyone discovered Netscape’s proprietary extensions. Browsing the Netscape documentation about these, I discovered Javascript.

Wow.

It’s easy to put down Javascript, but this was a blow between the eyes for me at the time. I was working with Netscape 2.0 on Windows 3.11; I had never written a Macro or seen Visual Basic or any non-DOS programming tool (the people I worked for developed on UNIX, using vi and GNU development tools. They worked in QVTTerm telnet windows on their 3.11 desktops). In Javascript, your code was built on top of the user-interface you’d made in HTML. It was an incredible toy.

It also taught me C.

When I took a course to learn “programming”, the basic syntax used in C and C++ was already familiar because of Javascript. It was also useful when I learned Perl, to write some CGI for the company website.

But Javascript and Perl, cool as they were, were not tools you could write “Real” programs in. By real, I mean things like foo.exe, which would run without a web browser or a Perl (or Python or Tcl) interpreter. I mean things that had a GUI, not just a command line and teletype-style input/output. Don’t get me wrong, I love the command line, I think scripts and filters and typing is cool, and web programming is wonderful, but that’s not the way to make the masses quake in their boots and understand you’re a REAL programmer.

At my “programming” course, they taught us C/C++ using Turbo C++; They taught us Visual Basic (very cool, I think); They only showed us Visual C++ in a “supplementary” lesson, and there we just modified a wizard-generated MFC App (something like the “Scribble” example, if you know Studio). There are plenty of other places to learn Windows programming if you’re into self-study though (I’d borrowed Petzold from my workplace), but as far as a compiler was concerned, when I was being drawn to this subject, Visual C++ was the only WIN32 compiler I knew of that I could get my hands on.

I now work as a programmer (in a different company). I work on Windows (Visual Studio) but also on UNIX (makefiles & native compilers), and my team doesn’t do any GUI work, so I’m mostly ignorant of both MFC and the Windows API. But I’d still be interested in tinkering with a Windows program sometime, so I’d like to have a compiler on my own home machine to play with.

Free C/C++ Compilers for Win32


The first free C++ compiler I got was one I’d discovered almost as an afterthought. I’m a regular follower of the Mozilla project, ever since the original source code release. I built both the first release and further releases whenever I had the time and the system (I actually installed Windows NT on my home computer because I wanted to build Mozilla. (this was after a disk death took my more standard Windows 95 installation to oblivion – this was the horrid Western Digital 3.x Gb series, and like a serial suicide, the replacement disk also died after a while). It’s fascinating to watch this massive piece of programming compile into a recognizable application, very similar to the one I spend most of my time in (and I imagine, eventually I’ll spend most of my time in Mozilla itself).

I’d come to my new workplace around the time I was re-installing my harddrive (for the SECOND time – I mentioned Western Digital disks keep dying on me…). I was eager to build Mozilla again on the powerful machine I got at work, so I downloaded the source and all the needed utilities. One of these utilities was Cygnus Solutions’ port of all the GNU UNIX tools to Windows. The Mozilla build requires some of the UNIX utilities, but rather than making a minimal list, they recommend downloading the “Full” distribution. This is a cool package to have on your computer (for example, I keep switching from UNIX telnet sessions to DOS consoles, but with Cygnus GNU Tools, it doesn’t matter if I type ‘ls’, ‘cp’ or ‘rm’ in the DOS window…). But what I didn’t realize at first is that it also included a complete C/C++ compiler for Windows.

The GNU Compiler

The GNU Win32 compiler (gcc) is a port of a UNIX compiler. It does let you use the Windows API, call DLLs, etc, and compile normal GUI applications. Executables compiled with the Cygnus compiler have a dependency on a runtime DLL Cygnus provides, but there’s something called mingw which replaces it with a dependency on Microsoft’s version of the same thing, which should be found on practically any Windows machine. I’m actually not sure what exactly constitutes “mingw”, but this guy does. I downloaded his libraries and include files and his FAQs, and following his directions I compiled
a number of good Windows C++ sample programs that worked fine.

A note on the samples: They come from a very worthwhile site: Reliable Software, which include a good tutorial to building C++ programs using the Windows API (the C system calls), not MFC. In fact, he has a good rant about why MFC is bloated and horrible. However, since I’m discussing free, non-Microsoft compilers, we can forget about MFC anyway.

A benefit of the gcc compiler (for a while there were two versions, the older GCC and the more experimental and advanced spin-off egcs, but the two projects have now re-merged) has the benefit of following the C++ standards very closely (I think it’s probably the most compliant compiler on the x86 architecture). This means you can use STL and various advanced C++ features in your code.

The disadvantage of the GNU compiler is that this is primarily a “port” of the UNIX tools. This can be broken down into two:

  1. The Windows API support seems shaky and partial. For example, support for COM and the Shell features (like the Directory browsing control you see sometimes) is missing. You can download libraries and includes that add this support, but I haven’t tried them yet.
  2. It’s pure command line. I’d spent my first weeks in my current job learning what the hell makefiles were, so I didn’t have great difficulty using GNU’s commands (gcc or c++ compile source files to object files, windres to compile resources). But this isn’t for everyone, and more importantly, there are things that you need to do on Windows that you don’t want to do via command line or by editing text files, for example designing dialog boxes. Sure, you could edit the .rc files by hand, but why? I figured the best strategy would probably be to design my dialogs in Microsoft Visual Studio (at work), then bring the file home to use. Hardly self-contained and far from ideal.

And then I discovered lcc.

A Labor of Love

Digging for more Windows-specific stuff for the GNU compiler, I stumbled across the lcc compiler: http://www.cs.virginia.edu/~lcc-win32/. Lcc is not just a compiler, it’s a complete IDE, with projects, source code browsers, wizards, compiler, debugger, and a resource editor. In fact, it’s a remarkable IDE. The resource editor in it’s own is worth the download, letting you put together dialogs by dragging controls from a palette and adjusting their properties with handy property sheets. You can also test your dialogs in the editor.

The project wizard is also very impressive, creating the framework for you (but since this is a Windows API framework, not an MFC-based framework, you have a much clearer idea what is actually taking place.

Then there are the source browsers – look at a list of all the functions, see what functions are called in each, see what include files are included in each file. There’s a wizard to add comments and descriptions for code documentation, and something to convert the code documentation into windows help files.

And there’s an entire versioning system built in! I have a product called CS-RCS from ComponentSoftware (an Israeli company, interestingly enough), that welds GNU-RCS seamlessly into the Windows Explorer and has a free single user license, but having a versioning system embedded in the IDE is a spectacular feature. Visual Studio (not free…) requires SourceSafe, a separate product (also not free – you can use CS-RCS instead, if you’re one person).

One more feature where the lcc IDE, which has the uninspiring name wedit, beats Visual Studio is the simple, even Spartan interface. Studio’s “dockable anything” sub-windows and toolbars can easily be moved about to make the entire work environment unusable, and constantly jostle each other for screen-space. Wedit has menus (no toolbars) and a very clean MDI interface.

The main drawback of lcc is that it is a straight C compiler. It has some support for Objective C, Fortran and Eifell hinted at in it’s interface and web pages, but there’s no sign of C++ support anywhere. If you want objects and templates and utility classes, if you want abstract data types and containers, or if you want constructors and destructors to take care of resource allocation and de-allocation for you (a methodology promoted in the Reliable Software samples mentioned above), lcc isn’t the compiler for you. If you admire the stark elegance of C as opposed to the obfuscated over-elaboration of C++, you will be very happy with lcc.

The best choice would probably be to use both tools together. Lcc can be used to design dialogs and other resources and to build the GUI skeleton. Then gcc can be used to integrate all this with the heavier logic of the program, written in C++. One annoying bit is that lcc probably has the best COM support, but all the COM examples you’ll find are in C++, so they need to be translated (or the gcc include files need to be updated).

It’s interesting to contrast the two compiler suites. Gcc (and especially mingw) looks like a clever hack, done for convenience’s sake by UNIX folk forced to do some work on Win32 machines. Two good examples are the origin of mingw itself, and the port of the GIMP (a Linux graphic program) to Win32, along with it’s attendant GUI toolkit and libraries, just so the guy could use his scanner (it seemed easier to him then writing a device driver for Linux). Lcc on the other hand is a dedicated labor of love, and it shows. The guy who wrote it (Jacob Navia) actually first designed an IDE (wedit) and figured he needed to throw in a compiler to make people want to use the editor. He ported the lcc compiler from DOS to Win32 (see his page for full credits, and my apology for using “lcc” throughout as the name of the application, when it’s properly lcc-win32). He also wrote an assembler and a linker – an entire “tool-chain” to make his product complete.

If you enjoy software with a personal voice (and if you follow Scripting News you probably do), then the documentation of lcc is worth looking into, especially the technical manual, which goes into extensive detail about what makes a C compiler tick, what design decisions were made at each stage, what hacking gcc feels like (Navia considered using some parts of it, but decided against that, for reasons he explains). He discusses his problems and his solutions with refreshing candor and a genuine interest of his subject. I spent more time browsing this very technical document then I did playing with a piece of 3D software I downloaded the same night.

So, lcc-win32 is a remarkable and free product (but NOT GPLed – the source is available for money), and the GNU-Win32 developers are Linux guys passing by. Both tools are worth looking at if you want to write “real” Windows programs.