Monday, October 23, 2017

Which Programming Language Should I Learn?


Subscribe by Email!
Investing time into learning a first (or new) programming language is a seriously-time-consuming endeavor. For me it wasn't something to take lightly, as I knew I'd be investing thousands of hours into any given single language when I began. When people ask which programming languages they should learn or use, a great way to make recommendations is to consider these 3 things:
  1. Popularity
  2. Is it a scripted (interpreted) or compiled language, and how does that affect what I want to do with it?
  3. Which languages are most used in my industry or application?

1) Consider the popularity of languages. The more popular the language, the higher the priority it should be, within reason, since that's what industry uses and that's where you're going to find the most resources, help and support, compatibility with others, and jobs. The TIOBE index is the place to check:
"TIOBE programming community index is a measure of popularity of programming languages, created and maintained by the TIOBE Company based in Eindhoven, the Netherlands.[1] TIOBE stands for 'The Importance of Being Earnest' which is taken from the name of a comedy play written by Oscar Wilde at the end of the nineteenth century.[2]" (https://en.wikipedia.org/wiki/TIOBE_index).



Here's the index for 2017: https://www.tiobe.com/tiobe-index/. As shown above, the top 6, in this order, are:
  1. Java
  2. C
  3. C++
  4. C#
  5. Python, and 
  6. JavaScript. 
My top 3 recommendations are Java, C++, and Python, but not necessarily in that order. When it comes to you and your personal needs, goals, and desires, however, you need to choose for yourself! Here's some tips to help you make that decision.


Java and C++ are high on my list because they are both compiled programming languages instead of scripted, or "interpreted" programming languages. This means they generally run 10~400x faster than scripted languages, can be used for low-level programming like writing operating systems, and can be used for very large applications like games and large office programs, since they run efficiently. Python is a scripted (or "interpreted") language, and so is generally 10~400x slower than a program written in C++ for instance. It's pros are that it is super popular today and is a great prototyping language since it is so high-level it can be used to quickly write small programs you want to get done in a short period of time. Python is generally a poor choice, however, for embedded systems. For many embedded systems, including nearly all microcontrollers such as Arduino/AVR, PIC, ST, etc, however, Python isn't even a choice at all, with very few exceptions such as MicroPython.

Other positives of Java, C++, and Python that make me recommend these three above all others are they can all be run on any operating system, including Windows, Mac, and Linux, and all three can be written entirely using free and open source (note that "free" here does *not* mean "no-cost"), and no-cost tools. This includes compilers, interpreters (as applicable--ex: for Python), and IDEs (Integrated Development Environments).

The reason I recommend C++ over C is because C is a subset of C++ and if you properly learn C++ you are also learning C. C++ is also a higher-level language and includes things such as the STL (Standard Template Library), which conveniently houses a lot of very useful, fundamental data structures and algorithms used today. Also, most games today are written in C++. Keep in mind, however, that the inventor of Linux, Linus Torvalds, loves C and hates C++. That's ok, however, as we don't have to believe everything smart people say. In the "War of Currents", for example, Thomas Edison was stubbornly opposed to Tesla, treated him lousy, and hated AC current, and Tesla personally thought Einstein's theory of relativity was "a mass of error and deceptive ideas and opposed to common sense," and that "not a single one of the relativity propositions [had] been proven" (The New York Sun, July 10, 1935, and as cited on Quora). So again, we don't have to listen to the naysayers.

The reason I recommend C++ over C# (pronounced "C sharp") is because C# is a Microsoft-developed programming language originally intended for Windows only (which I don't like since I use Linux a lot too), and it is *not* completely free and open source, which I also don't like (Google "is C# open source?").

I also love writing code for microcontrollers, which means that the (almost exclusive) options are C, C++, and Assembly language, though some people have written compiled C or C++ interpreters which run on microcontrollers for running Lua, JavaScript, MicroPython, or other scripted languages.

ADVERTISEMENT:
Keep in mind also that when you write Arduino code you are simply writing in C and C++, with additional "Arduino" functions and libraries written in...guess what?--C and C++. To prove this for yourself you can start by reading the Arduino reference pages: "The Arduino language is based on C/C++. It links against AVR Libc and allows the use of any of its functions; see its user manual for details" (https://www.arduino.cc/en/Reference/HomePage). You can then read and study about AVR Libc to see that it is Atmel's implementation of the "C" programming language for their AVR-core microcontrollers, and you can read and study the Arduino C and C++ .h, .c, and .cpp ("C Plus Plus") source files here (which I've spent many hours doing), and finally, for kicks you can go to the Arduino IDE --> File --> Preferences --> and check the box for "Show verbose output during" compilation, so that when you compile code you can see all of the "avr-g++" (C++ compiler) and "avr-gcc" (C compiler) statements being called to compile your C and C++ code for the Arduino.

2) Scripted/interpreted vs. compiled programming languages (& run-time speed vs development speed): The two main types of programming languages are "compiled" and "scripted" (AKA "interpreted"). In both cases you usually write text-based source code, but for "scripted" languages your source code can be called a "script." Therefore, a script is a type of source code, but source code is not necessarily a script (just like a square is a special type of rectangle, but a rectangle is not necessarily a square). Java and C++ are compiled languages, whereas Python is a scripted or interpreted language.

Compiled languages require a very special type of program called a "compiler" to convert plain text source code into machine code (or "bytecode" in the case of Java). Compiling generally happens *one single time.* This means that once you compile your source code you just need to run the executable file. Since it's already in machine language that your computer understands, it can run lightning-fast.

Interpreted languages require a very special type of program called an "interpreter," which has to read and interpret your source code, line by line, on the fly, (usually) each and every time the interpreter gets to a line of code. Interpreters themselves are compiled programs and are frequently written in C or C++. Since interpreters interpret source code (scripts in this case) on-the-fly, interpreted languages run really slow--usually 10~400x slower than compiled languages, at best. Scripted languages are usually (but not always) more portable, however, since they don't require re-compiling for each new operating system, so a single Python script, for example, can often be run successfully on multiple operating systems without needing to be changed, unless of course it is accessing operating-system-specific function calls.

When selecting a language to learn, consider the trade-off between run time vs development time. Java and C++, for example, as compiled languages run very fast, but are usually slower to develop new applications. Python runs comparatively very slow, but as a generally-recognized higher-level language than C or C++ (since it abstracts away things like variable types, memory management, and pointers, and has a slew of high-level functionality built-in) it can be used to develop applications more quickly. For this reason, small applications with low processing power requirements may frequently be written using scripted languages, like Python, but large applications, where speed is important, will likely be written using compiled languages, like C, C++, or Java, which are more time-consuming to use to write software, but which create software which runs much faster in the end.

Do you need low-level access to hardware? If you need to access I/O (Input/Output) hardware lines directly, or if you need to write code running on a real-time operating system (RTOS) you may find yourself further constrained. C, C++, and Java are all good for writing operating systems (ex: C for Linux; Java, C, and C++ for Android; and C and C++ for microcontrollers), and C or C++ (with self-enforced coding style and library limitations if using C++) are good for embedded systems and RTOSs.

3) What does your particular field, application, or industry use? Use the languages most commonly used with your field or application. Ex: Embedded systems developers (like me) frequently use C and C++, software developers (writing software intended for a PC as opposed to software or firmware for an embedded system) frequently favor Java, and Python is frequently used for small desktop apps, quick prototyping, data analysis and plotting, and basic (but relatively slow) Raspberry Pi apps or programs.

Engineers love MATLAB (another super slow, scripted programming language, like Python, but unlike Python it is *very expensive* in $$ and *not* free and open source), data scientists and statisticians may favor R (another interpreted programming language, but that *is* free and open source!), and web developers frequently use scripted (interpreted) languages such as JavaScript, CSS/HTML, Python, and PHP, or compiled languages such as Java, C++, C, or Go, or languages which can kinda-sorta be either, such as Ruby (source).

If you're using Arduino, you really need to wrap your head around the fact that you're not writing scripts (you're writing non-script source code for compilation by the GNU GCC free and open source compiler), and you're not using the "Arduino programming language" (since no such thing exists), rather, you're using C and C++ with additional C and C++ Arduino functions and libraries available. And if you think Arduino code is Java, I'm sorry: you're wrong again. The Arduino IDE, however, *is* written in Java ("Arduino" Wikipedia article).


If you're using Raspberry Pi, feel free to use any programming language you want, including Java, C++, or Python, as all three of those have full GPIO (General Purpose Input/Output) pin control and access on a Raspberry Pi. See the following Google searches to get started:

Additional reading:

By Gabriel Staples
Written: 23 Oct. 2017
Last Updated: 23 Oct. 2017

END

Keywords: computer programming, best programming languages, most recommended programming language, which programming language should I learn?, which programming language should I use?, which programming language should I study next?, which programming language to study next? should I learn Java, C, or C++?, scripted vs compiled programming languages, interpreted vs compiled programming languages, Arduino is not a language, Arduino is not Java, Arduino is C and C++, Arduino is C/C++

Draft Time: 4+ hrs.

***Subscribe by Email!***

No comments:

Post a Comment

Thanks for your comment or question! If it is a question, I will try to get back to you quickly. Notice to spammers: I personally remove all spam promptly and report spammers to Google, so please don't do it.

Note: some HTML tags are allowed in your comments. To learn how to add bold (<b>...</b>), italics (<i>...</i>), or hyperlinks (<a href="URL">NAME</a>) to your comments, read here.

~Sincerely, Gabriel Staples.

P.S. Yo hablo español también. Je parle français aussi. (I speak Spanish & French too).