Programming Languages Q&A - getfutureproof/fp_guides_wiki GitHub Wiki

The Million Dollar Question

Q: Which languages should I learn?

A: It doesn't really matter! Concepts over syntax!

There are hundreds (in the region of 700 according to Wikipedia) of programming languages out there! Learning a language really well is fun and depending on your work/school/project, you may be focusing on a specific one at any given time but the skills you are learning whilst doing that will apply to hundreds more! The thing to focus on when learning any language is the concepts, not the syntax. Whatever language you are using, the trinity of Data, Logic and Actions will always be in play. For example, knowing what the concept of iteration is, will help you in any language. Knowing the syntax for iterating in LOLCODE off the top of your head will probably only help you in LOLCODE. As long as you know the concept, you can always Google 'iteration in LOLCODE' or search the docs.

A Very Short History of Programming Languages

Computers, at their heart, have not changed. They monitor voltage switches from 0v to 5v and based on those combinations of signals, do different things. A bit like Morse code (see this interesting post to consider the similarities and differences)! The computer reads a 0v current as a 0 and a 5v current as a 1. Since there are only two possible values, this is called binary code. At the outset, engineers had to actually compose binary code and soon Assembly (asm) languages were created in which engineers could write line by line instructions which were then 'assembled' into the 0s and 1s for the computer to understand. These assembly languages are still very 'low-level' and not much easier than simply writing the binary code.

So if assembly languages are 'low-level', what would be considered 'high-level'? As time went on, more and more versions of these languages were created at increasingly higher levels of abstraction and these days, we have many languages which require no mathematical notations, come bundled with lots of useful extras to make our lives easier, and feel almost like writing in plain English.

But it all comes down to 0s and 1s in the end.


Useful Definitions

It is worth having a basic understanding of the most common definitions that you may come across when categorising languages:


Compiled vs Interpreted

Q: Okay, so if computers only understand 0s and 1s? How will they know how to run my code?

A: Regardless of how you wrote your code, it will at some point need to be turned into binary. A compiled language needs to be, well, compiled, before running. The compilation stage will produce a binary translation of your code that any computer can run. An interpreted language can use an interpreter program (yep, that's a program to run your program) which will do the 'translation' in realtime as the code is run.

There is a great example of compiled vs interpreted languages using hummus available here, courtesy of FreeCodeCamp.


Weakly vs Strongly Typed

Q: What is 2 + "2"?

A: Well, it could be 22, 4, or just a big old error. If you are working with a weakly typed language, it will do its best to implicitly convert types in order to achieve its goal. This can be very useful in some cases and a disaster in others. If you are working with a strongly typed language, your code will flat out refuse to even try to convert a number into a string or vice versa without explicit instruction.

Note that 'typed' does not refer to keyboard typing here, but data types!

Statically vs Dynamically Typed

As the name suggests, this is also related to data types. It refers to the moment in time that our code is checked over to see if all the declared data is of the expected type. Statically typed languages check for this during compilation. Dynamically typed languages check at runtime. What that means for us is that in a dynamically typed language, we don't have to state what data type is going to be in a variable when we declare it, and in fact the data type can change over time if required. In a statically typed language, when we declare a variable, we must also state what type of data will be stored inside, and once defined, cannot be changed.

A good description of Weakly/Strongly/Dynamically/Statically Typed is available here, courtesy of edspresso.


Paradigms: Functional vs Object Oriented vs Procedural

Q: What is a paradigm?

A: Essentially a paradigm is just a model or an approach. Three of the common programming paradigms are 'functional', 'object oriented' (OOP) and 'procedural'

  • OOP is an approach where we can create and access Objects that can model real world items or services eg. Cat or Order.

  • Procedural programming makes use of 'subroutines' (functions!) to group together a set of instructions to produce a result. These subroutines can be stored and used at any time. In procedural programming, our functions can update the state of a program eg. change a variable.

  • Functional programming is similar in look to procedural programming but the functions created cannot update the state of a program eg. change variables.

Note: many languages allow you to work in more than one paradigm. Often your use case is more likely to be the decider when choosing a paradigm, although different languages do tend to be more commonly used in certain paradigms.


Examples

JavaScript: weakly, dynamically typed, interpreted language that can be used in all the above paradigms
Python: strongly, dynamically typed, interpreted language that can be used in all the above paradigms
Java: strongly, statically typed, compiled language that can be used in all the above paradigms
C: weakly, statically typed, compiled language that can be used in all the above paradigms