Choosing your first programming language
Choosing your first language is a bit like, I imagine, choosing your first knives as a chef: should it be some kind of advanced Japanese steel knives that are folded 7 times under a full moon, or perhaps some German efficient ones machined inside a big Alpine mountain, or maybe something cheap, but useful from China?
When you are a beginner, alas you realistically do not have access to the full selection, but must instead contend yourself with the languages that are easiest to learn. Fortunately in our times, the languages that a beginner can hope to learn are in many cases the same that are used in the industry (even if this author hopes that some more, let us say expressive languages will eventually become more widely used).
From a pure functionalist viewpoint it does not matter much which language you start with, they will all allow you to solve the same problems in the end. That is, if they are Turing complete, but most are. When a language is Turing complete it can solve all the kinds of problems that you normally think a computer should be able to solve. In short it has memory, it can make decisions and it can do basic arithmetic.
Turing completeness is of course not a sufficient criteria to choose a language by; it can still be very hard to learn, or at least hard to learn to write good programs in it — Brainfuck or Malbolge are cases in point.
Leaving these not so serious languages aside, as a beginner, the main choices are between Python, C# and Java. Of course there are many more, but I have restricted myself to languages that are widely used outside the ivory towers of the universities. To compare the languages I am using two small examples, the canonical Hello World and a little program which reads two numbers from the keyboard and adds them together.
Python
Python is maybe the easiest to get started with and is the one I would recommend to get a basic understanding of programming. It is a dynamical language, which means that variables do not have a fixed type over the life of the program, but can change, so at one point i may be an integer, while later the same i may become a string.
First the two examples:
Python has many things going for it: It does not require the programmer to explicitly declare types in many cases, it does not have so many brackets, instead using indentation to structure the code and it does not rigidly enforce a specific way of programming, but allows you to get started writing simple code right away. In Python, as we see in example (1), you can just write print(“Hello world!”)
and not have to worry about declaring a function, a class or anything else. That one line is a valid program! Based on friends learning programming it really seems that Python is a lot easier to get started with, than say Java. Adding two numbers together is also pretty straightforward as we can see in example (2).
The main problem with Python is that it is not used that much to build big systems as it lends itself more readily to “scripting” or writing short programs with a very focused purpose. I do not think this should discourage anyone from starting with it though, since learning any other language after Python will be much easier, and it is a good stepping stone to the heavier languages.
Java
Java is a bit more complicated. It is a static language, which means that once a variable has a type, the same variable cannot get a new type. This may seem constraining, but it is a sensible restriction which avoids some classes of errors. It is also object-oriented, which means that everything (well almost) in Java has to be an instance of a class — an object. This is not a problem when you write bigger programs and have a bit more experience, but it may seem overly cumbersome when you are just trying to write a short program. Now for the examples:
(3) Hello World is a good example of Javas unsuitability to write very short programs, but already in (4) we can see some of its power. Admittedly I have written a more complicated program in Java, but I wanted to show off some of its more flattering sides. Here we define a class NumberReader, which has a method getNumber(), which can be used to get an integer from the terminal/console. After we have an instance of that, all we have to do is sum the two numbers, convert them to a string for printing and we are done.
Java is not exactly pretty, but it is a workhorse of the industry and there are countless Java jobs out there (I have one of them). It has a reasonably expressive type system, which is still not too complicated, which seems to be a good balance when you are learning to program. The standard libraries are a pain and so are many other things, like configuring the virtual machine, profiling and much more. The main redeeming factor is that it mostly works well, its versatility and that it is not too difficult for beginners. I think Java can be a reasonable choice for a second, or even first programming language, and if you are going to study programming, odds are that Java will be in the package of languages you are introduced to very early on.
C#
C# is kind of a descendant of Java and it improves upon many of Java’s faults, in my opinion. The main drawback? It is almost exclusively used on the Microsoft platform. It is very similar to Java, but is in many ways more elegant. I do not think it makes a very big difference when you are starting programming, or even when you are at the intermediate level, but as you get better, you may begin to appreciate the many small ways in which C# improves on Java.
An simple one is that in C# you can write var instead of the type name, if the type can be inferenced (more or less synonymous with guessed) by the compiler. An example is instead of writing String s = “What is your name?”
in C# you could write var s = “What is your name?”.
This is just one way in which C# is more elegant in my opinion. The standard libraries also tend to be a bit simpler, and like Java, C# is very versatile and can be used for almost any programming task you can think of.
Example (5) is not much different from the Java one, although we can see that System.out.println is now replaced with the rather more sensibly named Console.WriteLine.
Example (6) shows a couple of things: reading from the keyboard can be accomplished with the simple Console.ReadLine (how do they do it?) and we do not have to write type names where they are obvious, but can get away with just writing var. One final thing of note is that sum is automatically converted to a string when appended to a string, so that “The sum: “ + sum becomes a string.
Conclusion
I hope I have given you some idea of the relative merits of the three languages. To paraphrase a Jewish joke, ask two computer scientists, and you will get three opinions; this is certainly true when asked about programming languages, so you may very well find very well educated people who disagree vehemently with what I wrote here, but I hope it can work as a starting point.