Why in the world?... You came here to learn how to program, right? Not learn about how languages grew up, died, and influenced each other. You just want to get hacking or learn enough of a marketable language to add to your resume. If you're the hacker, try this language and if you're one of the bit-pusher wannabes, try this language. If you're neither, but just want to do something, then just start the next tutorial. If, however, you're willing to take some time and learn how the current languages have come about, and where they might be going, read on.
Back in the dark ages of programming, programs were built byte by byte, directly entering the machine readable code into the computer. It was long and tedious, to say in the least. To make the system a little more readable, assemblers, and assembly, was cooked up. Instead of entering numbers in the computer, an equivalent assembly 'program' would be fed into an assembler which would spit out the program in machine code. It was still slow, but it was better. However, each assembler had to be tailored to a certain chip, which made writing the same code for different chips an even more tedious process. The following example of x861 assembly is the traditional 'Hello World'2 program in assembly:
p>dosseg .model small .stack 100h.data hello_message db 'Hello, World!',0dh,0ah,'$'
.code main proc mov ax,@data mov ds,ax
mov ah,9 mov dx,offset hello_message int 21h
mov ax,4C00h int 21h main endp end main
I cannot think of a sane reason to use assembly, unless you're writing a program for a radical new chip (unlikely), writing games for calculators (more likely), or are trying to optimize a graphics engine (still unlikely). It might be an interesting exercise to learn how to program assembly, but seriously, there is not too much merit to using it.
Now, we come to the grandfather of most of the modern languages, brought about from around 19543. Fortran was the first language to translate human-readable code into machine code efficently, meaning a fortran program was shorter and quicker to write than an equivalent assembly program. Let's take a look at the same revered 'Hello World' example, this time in modern fortran4:
p>PROGRAM HELLO DO 10, I=1,10 PRINT *,'Hello World' 10 CONTINUE STOP END
Looking back at the assembly example, the fortran example is heavenly. Fortran also introduced the concept of a compiler, the which was a program that would write programs. Genius, eh?
Lisp is kind of a black sheep. Of programming languages. It's creator5 didn't even intend for it to be a programming language. It was more of a mathematical... thing. Nevertheless, a student made an interpreter, and lisp was born in 1958. It was very different from fortran, for one. An example in ansi common lisp:
p>(defun hello-world () (format t "Hello world!"))
We'll be looking at lisp last in our set of programming tutorials, but if you can't contain yourself, it's here.
BASIC is a clever little acronym, Beginner's All-purpose Symbolic Instruction Code6. As it says, the language was geared for beginners, shown in the fact that Windows markets their Visual Basic as an easy to use and learn programming solution. The inevitable hello world example7 in general basic:
p>10 print"Hello World!" 20 goto 10
There are alot of sorts of basics: Visual Basic is one, and most of them differ in some form or fashion(all basics are not created equal!). But, we don't suggest you learn basic if you're serious about programming.
Yet another language, it's probably most notable for being used for teaching introductory programming8. The standard bit of code:
p>Program Hello (Input, Output);Begin
Writeln ('Hello World!'); End.
This is a juggernaut of a language. Until recently, it has been the most popular language to program in. Today, if you walk into large enterprise operations, they still might use C or his son, C++. Many are moving to java, though. Systems processes are still written in C/C++ (for example, the Linux kernel is C). If you want to be able to read some legacy code or just want that extra bit of speed over other recently born languages, C++ is your man. Here's an example of C++:
p>#includeint main() { std::cout << "Hello, world!\n"; }
We have a tutorial on C++ here.
A part of the lisp family (essentially everything else on this page is descended from algol, a now defunct language), this language represents an attempt to make the smallest core language possible. If you care for a comparison, a lisper once used Buddha as a comparative object: Schemer: "Buddha is small, clean, and serious. Lispnik: Buddha is big, has hairy armpits, and laughs."9 For a shaved version of lisp:
p>(define hello-world (display "Hello World!"))
If you talk to smalltalk enthusiasts, they'll be the ones to tell you that smalltalk is the language that really kicked off the idea of object orientation. Object oriented programming is a style of programming that puts everything to a higher level of abstraction. Instead of having a bunch of code that would operate on a bunch information that was a bank account, object oriented code would make a bank account object and define the data as part of the object and define methods to work on the data (like a withdraw method). Don't worry if it doesn't make sense now: we'll be covering oop in depth in the java tutorial. And I almost forgot some code:
p>publish Transcript show: 'Hello, World!'
Perl is, well, an interesting language. Perl is an acronym for 'practical extraction and report language', and it started out as just that. It wasn't a real programming language. But Larry Wall started extending it, and eventually ended up with a terse and somewhat innovative language(their battle call is "there's more than one way to do it!"). Here's a not so scary example:
p>sub hello-world { print "Hello World!"; }
We'll be looking at perl in a tutorial, if for nothing more than reading deprecated cgi scripts10.
If you are linguistically inclined, you might have noticed the close relationship between perl and python as words11. That's where any semblance of similarity ends, though. In contrast to perl, python was designed in 1990, not hacked together, to be readable12. Also, python enthusiasts, if you shout the perl slogan at them, will respond with a spoof: "there's only one way to do it!" There are also interesting ideas to be gained from python, but we won't be looking at it in our tutorial cycle13. There's some code:
p>def helloWorld(): print "Hello world!"
This is one of the only computers that I know about that originated from Asia, Japan specifically. This is a fully object oriented programming language, like smalltalk. If it explains anything, the creator of Ruby, Yukihiro Matsumoto, describes the language, among other things, as 'fun'. As is fun to program in. Joyful, get-up-in-the-morning, hug-a-stranger-today fun14. Some fun-inspiring code:
p>puts "Hello World!"
For some reason, this is a semi-popular language, probably for the same reason BASIC was invented. PHP was kind of a 'easier perl', and eventhough you can use it as a desktop language, the vast majority of people use PHP as a website scripting language. You can mix html and php code. In fact, that's the way things are done most of the time. All sorts sites are written in it, but if you were to design a serious site from the ground up, I would recomend some other language15. Some <?php ?> code:
p><?php echo 'Hello World'; ?>
Recently, Java became the most popular language. Who knows why? Maybe it has something to do with the fact everyone teaches it, it's not hard to learn, it's better than C++ (it's predecessor) and it's fully object oriented. To the core. Java is quite the startup - it's relatively young (1995), but it's already very popular. If you want to make money programming, you'll probably want to at least know java:
p>public class main { public static void main(String args[]) { System.out.println("Hello World!"); } }
We'll be teaching you this industry-standard language in our tutorial cycle.
Now, java was developed by Sun Microsystems, and it turned out better than C++. Microsoft, who didn't want to be stuck using someone else's language16, developed C# (pronounced C Sharp) and it's said to be better than Java, depending on who you ask. Let's C some C# code:
p>class HelloWorld { static void Main () { System.Console.Write("Hello World!"); } }
We'll be covering C# after Java and C.
Okay, yes, it has a bad word in the title. And it almost fits here: C# was made in 2000, and bf was made in 1993. No, it's not a 'real' programming language, more of an oddity and sideshow. Really. There are just eight commands as part of the language. Its meant to "challenge and amuse programmers"17, and it just goes to show programmers aren't all stuffy and serious18. Also, who ever heard of a 200 byte compiler? Let's not let our brains melt with some bf code:
p>>+++++++++[<++++++++>-]<.>++++++[<+++++>-]<-.+++++++..++ +. >>+++++++[<++++++>-]<++.------------.<++++++++.--------. +++.------.--------.>+.>++++++++++.
I am quite serious. That will print out hello world. No, I am not joking. You can stop laughing now.
Now that we're done with our language survey, let's move on to actual programming.