return 42;

by Jan Wedel

Programming Languages

My personal programming language experience

Here, I'm going to share my experience with programming languages I've worked with.

Disclaimer: This is purely written from my point of view and maybe - no, most probably - I will get something wrong so don't take it as a scientific article. I'm trying to maintain a chronological order, as far as possible.

10 PRINT "BASIC" - GOTO 10

Actually BASIC was the first language I've learned so I think I need to credit it for introducing me to the wonderful world of programming. When I was about 11 years old (around 1993), our family got a - by the time already outdated - Genie II computer with a nice monochrome display from my uncle. It had a BASIC interpreter. So I walked into the library and got myself some Books with BASIC code listings. I was amazed by the fact, that I can tell the computer to do what I want when I want it and how I want it!

The first program I've entered that actually did something useful was a lotto number generator. Wow, incredible technology, right? Spoiler: We've never made a million out of it.

Very soon, my parents recognised my interest in computers and bought a Highscreen 486 SX 25 - at that time top of the line consumer computer running DOS and Windows 3.11, if I remember correctly. And it shipped with:

QBASIC, Snakes & Explosive Bananas

Yeah right. QBASIC! It had some kind kind of very rudimentary IDE where you could write and execute your programs. The best thing: it shipped with a few example programs, such as Nibbles which was a Snake clone and Gorillas which was a turn-based game were two gorillas were standing on skyscrapers and throwing explosive bananas to the opponent. Very nice games. Gorillas even had pixel graphics.

SUB EraseSnake (snake() AS snaketype, snakeBod() AS snakeBody, snakeNum)

    FOR c = 0 TO 9
        FOR b = snake(snakeNum).length - c TO 0 STEP -10
            tail = (snake(snakeNum).head + MAXSNAKELENGTH - b) MOD MAXSNAKELENGTH
            Set snakeBod(tail, snakeNum).row, snakeBod(tail, snakeNum).col, colorTable(4)
        NEXT b
    NEXT c

END SUB

I studied both source codes very diligently to apply some tiny modifications that allowed me to cheat when I wanted to.

Despite all the fun, QBASIC was interpreted and very very slow. Especially when it comes to graphics or just refreshing text on the screen very quickly. That's probably why they removed the "uick" from QuickBASIC.

Need for Speed - Turbo Pascal

I actually can't remember how I came to Turbo Pascal but I know that I ordered it from some based on some ad in a computer magazine. It came in a large box shipping a variety of printed documentation such as language guide, compiler and linker manual etc.

One of my larger projects was actually writing a Norton Commander clone, a split screen DOS file manager. I was using Norton Commander all the time so I wanted to know, how to write it by myself. I think was able to actually browse files and directories in both panes and probably even copying files. The rest were just dummies. I actually wonder, how my code looked like. It must have been pretty much messy, most probably one large spaghetti code but maybe I'm doing wrong by my older me.

Another project was reading a book that explained how the very popular DOOM graphics engine worked and actually reimplemented it in Turbo Pascal and mostly Assembler for the high performance parts. The engine was still much slower that DOOM but it was really impressive. The first time, I bought books about mathematics and vector calculations on my own free will and before this was introduced in school. But it didn't help much since I still wasn't able to understand how this works, especially not if it was written in Assembler.

MOV AX, BX - Assembler

I tried to learn assembler because I saw that it was really fast. I started to get some Assembler Book on Intels 486 and started two write some programs. After it took me days to get a "Hello world" working which, as far as I could remember used some BIOS calls which were terribly slow as well, killed the project.

So what were the cool guys using?

C++

So, I got a Turbo C++ for Windows compiler including the mentioned nice big box with a huge pile of documentation, again. Wow, book shelf was pretty much nerdy, even by todays standards!

I remember that I tried hard to learn the language but didn't get the strange "class thing" right. Sorry C++, it's not going to work out. But we can stay friends!

C++-- == C

At the university when I decided to study electrical engineering, we had to learn C to program an 8-Bit Atmel micro controller. At that time it wasn't really hard for me to learn the language and it was actually to fun to program something that can light up an LED or scan a button. One of my original projects was a nice little sound generator. I was synthesising a square wave, hard-coded a few songs and used buttons to playback them. I think, you could even used the buttons as a keyboard to play your own songs.

Later during the studies, I started working at Siemens were, after weeks of soldering SMD components under a microscope, they let me actually program a micro controller. The best thing was, I could combine all that I was good at. C, C++ & Assembler. I wrote a C sniffer program that implemented I2C and SPI protocols on the micro controller recognising, that it was too slow for full-speed SPI. So I needed to rewrite the time critical parts in inline Assembler, calculating the required clock cycles of every instruction. As a bonus, I needed to make a Windows GUI in Visual C++ 6.0 to display the sniffed data in real-time.

Access violation party hard.

Later during my careeer, I had to meet C++ again. I was doing consulting at a company that was using C++. So I got myself a book, learned some more advanced C++ techniques and jumped into the pool of qt, vim, make files, compiling and linking and I it felt like 90s again.

Cup of coffee - Java

Since I needed it at work, I learned Java as well. This must have been 2007. You might laugh, but wow, by that time I felt that I saw the light. It was so much easier and faster to achieve the same goal compared to C and C++. It was syntactically similar to what I knew and it thankfully doomed pointers (which I have learned to hate using C++) although it mysteriously still had a NullPointerException without having pointers. But this is not going to happen to me, right?

Over the years until today, I'm still writing mostly Java. I read a lot of books on Java and Software Engineering, learned a lot things the hard way, saw a lot of very ugly code that taught me how not to do it and written a lot of more or less sophisticated applications and libraries that I am at least a bit proud of.

Using wonderful tools like IntelliJ with it's code completion, refactoring, debugging and testing facilities, Java development can almost be called fun, at least from my point of view. All the usual boiler-plate-code-writing can be automated with a few keyboard shortcuts. The IDE infers types for you, derives sensible names for variables, creates getters and setters and what not. This is really really amazing. Especially because, as I mentioned before, when there was a period of time where I was writing C++ code in vim which, at best, had very limited auto-completion functionality. When I was back at my Java developers desk, it felt like I was developing at speed of light.

The only thing that is really painful in Java is concurrency. And there is not IDE at your side that helps you with that. The best thing you could do when you're planning to introduce concurrency is don't. The second best thing is still don't. But when I started developing a framework for embedded application, I though concurrency might be a great idea. And theoretically, it was. But the reality struck back quite fast and hard. We've had some really bad and hard to find dead locks at locations where you would have never expected them. One of the first things I learned was never to call back listeners inside a synchronized block (yeah, i did). The natural evolution of the code driven by trial and error developed a kind of message passing state machines from itself. And when I started to read some articles and books about concurrency I came across Erlang. I started read more about it and to experiment with the language and its concurrency model.

Since there was no way to run Erlang on out embedded devices, I wrote a very light-weight actor and re-actor library for Java (No way to use Akka if you're wondering) and started everything that I wrote from this point on to use that library instead of starting threads directly. That was a very interesting project and it was successful after all. I could spawn thousands of parallel actors that use only a few Java threads and that would only run when a message is actually received, it had great performance, even on out embedded target device.

Because of some requirements and as a proof of concept, I wrote a Python interpreter in Java based on the stripped down C implementation of Python-on-a-chip. It actually ran and interpreted a pre-compiled python byte code programs on an embedded Java module that interpreted the Java program. Sounds like the right way to do it, huh? When you're thinking hell no, WTF, you're probably right. But it did work although it was terribly slow - as expected. The good thing was, that it introduced me to the Python language. What would be better and more fun to learn a language, that to write an interpreter for it? Ok, there might be a few things including knocking a rusty nail into ones foot. But remember my nerdy book shelf? This is the continuation.

The sneaky snake - Python

I was amazed by the elegance of the interpreter. Everything was an object. Numbers, byte code instructions, methods, modules, classes. So I started to use Python for some less important tools, but with great success! Python programs were much much shorter than the Java equivalents because of the dynamic type system and because of some nice syntax sugar and because of libraries that make use of the prior.

In the end, I've written some pretty large productive applications including THAT, for god's sake. Despite the fact that I had to work with Microsoft COM (Again, I suggest the rusty nail instead), it was pretty awesome what you could do with python. But don't drink too much cool-aid: The same fact that makes Python awesome also makes it difficult sometimes: The dynamic type system. You could write a large amount of code that actually compiles and runs for quite a while but then crashes out of the blue. And that might happen simply because of a typo.

foo = 4
bar = get_bar()
if bar > 1000:
    print boo

What you need to do is using an IDE or Editor that does some static type checking to warn you about that boo isn't defined anywhere. Moreover, you need to to unit testing a lot to make sure you've executed every line of code once. This is even more important that in statically types languages.

The cryptic language - Perl

There was some new project that required some large scale text file parsing. And which programming language is known to be very good at this job? Unfortunately Perl. So in the spirit of learning a new language and because my boss liked it, I decided to give it a try.

I knew that it was said to be very unreadable so I tried to apply all my knowledge to it, read some style guides and so forth I tried to keep it as readable as possible which actually worked pretty good. It looked a bit like C code with inline regular expressions but it worked. One down side was that classes were not supported and you had to use some very ugly error prone and redundant code to write some pseudo class like constructors:

package Person;
sub new
{
    my $class = shift;
    my $self = {
        _firstName => shift,
        _lastName  => shift,
        _ssn       => shift,
    };
    bless $self, $class;
    return $self;
}

It gets even worse when you try to achieve default values and a map that contains all class attributes. But not enough. Perl has some more or less hidden global variables starting with "$" that may actually lead to very strange behaviour and errors.

The only thing that I actually really liked and the only thing from perl that am still missing in other languages is having regular expressions as a syntax element.

 print "It matches\n" if "Hello World" =~ /World/;

Degenerated Bastard - JavaScript

Ohh, I can't say that I like Web development very much at all. That includes JavaScript, CSS and HTML.

I wrote quite a bit of JavaScript code here and here. The first one tries to concurrently solve a Nonogram using Web Workers where the second one is a web site to view historic maps of Berlin.

The Nonogram solver was an interesting and fun project even though I took much too much computing power when it comes to solving larger Nonograms. The biggest benefit of using JavaScript within a browser was, that the UI comes almost for free.

The historic maps project was a bit larger project where I tried to have a well-structured code. I read a JavaScript book that explained three ways to mimic Classes that were all equally ugly to read and write:

// A class constructor
function TimelineView(element, model) {
    // Self reference
    var self = this;

    // Class attributes
    this.element = element;
    this.model = model;
    this.mapClicked = new Event(this);
    this.maps = [];
    this.clusters = [];

    // Class methods
    function update() {
    }

    function buildCluster(totalWidthPixel, startOfTimeline, timeSpan) {
    }

    function findClusterWithId(id) {

    }

    function sortMaps() {
    }
}

// Class "constants"
TimelineView.TIME_LINE_RESOLUTION = 50;
TimelineView.MAX_CLUSTER_SIZE = 3;
TimelineView.MIN_DOT_SPACE = 20;

One of the strangest things is scoping in JavaScript. This a guaranteed error that everyone makes when trying to capture variables from a loop and attach it to some callbacks:

for(var i = 0; i < 10; i++) {
    // Create a link
    mapLink = $(document.createElement('a'));

    mapLink.click(
        (function(id) {
            return function() {
                self.mapClicked.notify({id:id});
            };
        })(i));
         // (...)
}

Pretty, isn't it? Creating an inline function that takes a parameter to capture the id and then return another function that is the actual click handler and than calling the first function so that the closure is created with i being captured.

Now I could start ranting about how fucked-up CSS and HTML are but they aren't programming languages, so i'll spare it.

spawn(zombie, kill, [all]) - Erlang

I know, I know, you don't like the Syntax, right? But that's a lame excuse not to try Erlang. Ok, using full stops, semi-colons and commas is a bit confusing and tedious to write but once you get that, the rest is quite awesome. I read Fred H├ębert's wonderful and free book Learn You some Erlang (and actually bought the printed version later on) and it was so much fun to read. one of the greatest books on programming with the right mix of interesting content, good structure, a lot of sarcasm and great (even more sarcastic) illustrations.

And you have to watch this! I laughed so hard, but if you take away the 90ies telephones and Joe Armstrong's pull-over, it is very amazing technology.

Next to concurrency, pattern matching is really one of my favorite features that I learned to love. Since I haven't used any functional programming languages before, this was all new to me.

Hot-code loading, supervisors, "let it crash" philosophy, there is just so much knowledge condensed into Erlang that I am wondering all the time that these features haven't made its way into the more popular langues yet.

If you#re still not bought, maybe Elixir is something for you. It is a completely new language that has some Rubyish syntax and compiles to Erlang byte code (BEAM) and runs on the Erlang VM.

Haskell

T.B.D.

HTML

Just kidding. I left this here for the knows-it-all guys and girls complaining that HTML isn't a programming language.