What comes to mind when you hear the phrase “close to the metal”? Once upon a time not too long ago, in fact, back when I was a little kid, computational power came at a premium. The games I grew up playing on the NES, which ran on the 6502 processor running at a whopping 21mhz, were honestly very impressive for their time. If you’ve ever taken a look at one of the many NES disassembly projects, you’ll notice how very different the programming language looks compared to some of the code you’ve been working with. These are programmed using assembly langauge, which is barely a stone’s throw from 1’s and 0’s. In fact, as opposed to decompiling machine code into C or C++, disassembling machine code into the more human readable assembly is a relatively simple process. Making sense of it all is the real challenge as any comments that may have been written by the original programmer will be gone. In assembly we are instructing the computer to do every single tedious step. Do you want to print out a simple “hello world” string on the screen? That wont be quick or easy to program. Many computers of the era, including the Japanese version of the NES, could understand a language called BASIC, which allowed the user to write programs in a more human readable way. The issue being that the programs ran very slowly. BASIC is an interpretted language, but more on that later. A program can be written in a compiled language like C or C++, but the speed loss was usually unacceptable for some of these early CPU’s, especially in game consoles. Usually a “low level language” is necessary for these applications. Next we have Medium-level languages. Some examples in this category in order from lowest to highest level are C, C++, and Java. These languages use a compiler to convert the code into machine language that the CPU can understand. In C, you get to skip a lot of the tedious instructions that the compiler figures out for you, but you are responsible things like memory management in a lot of cases. C++ is a superset of C and adds many capabilities, some of which can be too inefficient for lower powered computers. Java gets compiled into a much lower level language called byte-code that is interpreted, or compiled on the fly by a virtual machine. This enables the same code to be run on any architecture that is capable of running a Java Virtual Machine. This comes with speed penalties though, which will become a pattern as we move further and further from “the metal”. Lastly, we get to the high level language category. Some examples of these are Javascript, Ruby, Php, Perl and Python. These are generally “interpreted” languages, although some newer compiled languages such as Swift are starting to bridge the gap. These languages tend to have a much more elegant and readable syntax, and for the most part are a good choice for your first language. Sounds like a no brainer right? Yes and No. Using a high level language comes with severe speed penaties. You can write a game in Javascript that runs inside a web browser, but it will never be capable of utilizing the maximum performance that the hardware has to offer. As time goes on, this becomes less and less important since the smart phone you have in your pocket is tens of thousands of times faster than the computers in Apollo era spacecrafts. Can you get any higher-level? Sure can. All popular high-level languages have numerous libraries and frameworks such as React or Rails, that abstract even further from the CPU. Why would I use a “slow language” when I could just use a “fast language”? The reason is that in pretty much all cases, as “execution speed” decreases, “write speed” increases. You can get a whole lot more done with less code in a high level language. You don’t have to worry about accidentally overwriting a memory register that you needed to read later on. You don’t need to worry about destabilizing an entire system with your code. Every type of language still has it’s place in today’s computing. Using the correct one for your application is just as important as the code you write with it.
Comment Below: