Programming

my faceChris Foley is a computer programming enthusiast. He loves exploring new programming languages and crafting nice solutions. He lives in Glasgow, Scotland and works as a software developer.

Hello in Ten Languages

I woke up surrounded by the debris of the night before. I pushed past the empty coke cans and brought my laptop out of hibernation. As the hard drive spun into action, the screen flicked on revealing a desktop littered with used language installers.

Welcome to day two of my project. I have set out to learn ten programming languages and the first step was to get them up and running and write "Hello World!" In each.

None of the languages presented any real problems. I already had Ruby installed. A quick puts "Hello World!" and I'm done.

Python was up next. I went for 3.2.2, thinking I might as well learn for the future, even if it's not the industry standard yet. The windows installer did everything except set the path variable. Hardly a biggie but in a language that's supposed to be so easy and intuitive, it seems like a silly hurdle to present a newbie. Erlang was the only other language that needed this set. print("Hello World!") was simple enough, and probably my favourite "Hello World".

Haskell's installation was straightforward as was main = putStrLn "Hello World!", though I'm sure there's a monad in there somewhere.

Erlang was straightforward too but I will have trouble finding the recommended browser for viewing their documentation: Netscape.

-module(hello).
-export([hello_world/0]).

hello_world() -> io:fwrite("Hello world!\n").
GCC was already installed so all I had to do was write and run my first C program.
#include <stdio.h>

int main() {
	printf("Hello World, from c!\n");
	return 0;
}

There is no shortage of tutorials showing me various ways to write that and tell me what all the lines do. But most of them don't mention that I should save it in a .c file, nor do they guide me through using the compiler. I found a good tutorial before long and all was right with the world.

C# came with visual studio. After a lengthy installation, it took me about 5 seconds to throw a program together. I bet I don't need the imports it auto generated for me but, hey:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hello_World
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
}

JavaScript was simple. Just saved a quick file and dragged it into my browser:

<html>
	<body>
		<script type="text/javascript">
			alert("Hello World!");
		</script>
	</body>
</html>

BASH on Windows? Actually, there are lots of options including Cygwin, SSH to a university linux computer or turning on the linux netbook that was right next to me. What I did though was use GIT BASH which was only a right click away. It worked fine for this:

#!/bin/bash
echo "Hello World! from BASH"

For Smalltalk I went with Squeak. I've never used an environment like it before but it looks fun to use. Transcript show: 'hello world' did the job.

I was persuaded to add Lua to my list of languages. It is intended as an embeddable scripting language so most of the releases are source code. That doesn't interest me right now so I found luaforwindows which is an all-in-one solution. The installer gave me the option of watching a quick language demo and ~35 very quick slides later, I felt I could already write some code. I'm very impressed with this and would like to see more languages follow suite. print("Hello World!")

So, there we go. Ten languages all set up and ready to go. Next, I have to find some tutorial questions to work though...

13 October 2011

Comments