You may have seen from some of my previous writings that I am a big admirer of Node.js. While this is true and has been my go-to language for a while, it is not always appropriate for everyone.
It might be difficult to get started in programming and computer science. What language should you choose? What is the best IDE to use? And, maybe more importantly, why?
The most important thing to accomplish while programming, in my opinion, is to choose the correct tool for the job. The second most critical factor is to select the tool with which you are most familiar. If I told you that you should use C++ since it’s one of the quickest languages available, it might not be appropriate advice if you’ve never dealt with memory management or created your own data structures. You’d most likely struggle through it and have a negative experience.
Python, on the other hand, handles many of these issues for you. It is slower than C++, but it is also considerably simpler to write. And as a novice, you probably don’t care about how fast it is; all you want to do is design something cool and learn the fundamental concepts.
The first decision you must make is the language you wish to study. Why should novices study Python out of the hundreds of languages available? There are a few reasons for this…
Part of the language’s underlying philosophy (as stated by PEP 20, “The Zen of Python”) comprises the following:
Beautiful is preferable to ugly.
Simple is preferable to complex.
Readability is important.
As you can see, Python was created with simplicity in mind from the start. This was a breath of fresh air at the time because the popular languages at the time were C and C++, which aren’t particularly user friendly.
Let’s compare Python syntax to C++ syntax with a basic ‘Hello, World’ example:
That’s a significant difference, yet all we did was print a string to the terminal. Let’s conduct another syntactic comparison, this time using PHP, for good measure:
Python strives hard to eliminate ‘fluff’ and only requires what is absolutely necessary, which is why it was designed to be used without curly brackets and line-ending semicolons. Look at the difference it makes (this is the final syntactic comparison I promise):
I’m not trying to belittle other languages here. All of the other languages mentioned are excellent and have numerous applications, but they are not suitable for beginners.
A well-written Python script can nearly be read like plain English with keywords like is, not, and with. This is especially true for if statement conditions, which can become difficult to read if they become too long:
The conditional statement above is substantially cleaner than the standard conditional statement.
if ((a != null) && (b != null))
Simple to Set Up and Use
Many beginners who attempt to learn a language fail before writing a single line of code. Some languages, such as Java, need you to install and configure complex project folders before compiling your code.
To get started with Python, simply download and execute the installer, and then run the programme.
There is no need to build a convoluted directory structure or to compile anything.
Although it is becoming less common in current languages, compiling your code can be much more difficult than you might expect (although, it is a necessary evil). Take a look at this little C makefile:
And I consider this to be a straightforward makefile. I’d rather use Python than this.
Python helps you to learn the fundamentals of programming before delving into the gritty details of how high-level code is transformed into machine-level code, which you should absolutely understand, but not when you’re just getting started.
Massive Standard Library
Python’s standard library is one of its most lauded assets, and for good reason. It includes approximately 300 modules (as of version 3.5), ranging from a basic HTTP server (BaseHTTPServer) through databases (sqlite3) and compression libraries (gzip).
The great majority of everything you’ll want to perform with Python is usually already taken care of in these standard libraries. So you can start making exciting things like apps with machine learning with minimum effort.
Every now and then, I’ll have to remind myself to go through the modules and check what’s available so that I don’t have to rewrite the code myself.
So, before you start writing a url parsing library, make sure it doesn’t already exist!
One of the most appealing aspects of not having to create all of this code yourself is knowing that it has been properly tested and is bug-free. Much of this code has been around for a while and is used at top companies (which we’ll discuss later), so you know it’s been tested.
Two things are implied by a large and engaged community:
There are numerous third-party libraries.
There are numerous persons available to assist you.
These are perhaps some of the most compelling reasons to use Python, regardless of your skill level. This means you’ll have access to a plethora of additional documentation, tutorials, and code to help you learn the language.
Python has continuously been ranked highly as a top programming language by a variety of sites, including Redmonk (#4) and Tiobe (#5).
Employer demand is even more significant than language popularity. The graph below (from Indeed) shows that Python is the second most in-demand language among employers, which means you have a better chance of making a career out of your programming talents.
Debugging is simple.
Debugging is one of the most difficult skills for a newbie to master. This is where you truly learn a language and its inner workings. Sometimes you’ll uncover simple issues that are simply syntax errors, and other times you’ll find really difficult-to-detect bugs that only appear 1 out of every 100 times you run your software.
This is where you’ll truly learn to know your debugger and typical language errors.
Python, fortunately for you, has very good error handling and reporting, whereas many other languages do not.
In C++, for example, if something goes wrong (such as derefencing an invalid pointer or accessing an array element that is out of bounds), you’ll be lucky if the programme crashes. That way, you’ll know there’s an issue somewhere in your programme, but you won’t know where it is (and debuggers aren’t always easy to use for a beginning). If you’re unfortunate, the software will not crash (or will only crash at odd times) and instead will display obscure problems that aren’t immediately visible.
Okay, I didn’t think it would be fair to write a nice post about Python without mentioning its flaws. It’s not flawless, like any other language, and there are plenty of things you shouldn’t use it for.
Python, as I’ve noted several times, is slow. When compared to compiled languages like C/C++ or Go, it is extremely sluggish. This is due to the fact that it has several features that slow it down, such as being dynamically typed and having trash collection.
This indicates that you shouldn’t use pure Python to process large amounts of data; instead, you should use C++ hooks (which we’ll discuss another time).
Furthermore, because to Python’s trash collection, it cannot be used for real-time systems. This is because garbage collection causes code to run in a non-deterministic manner, so you won’t know if your function will take 1ms or 100ms to complete. There are simply far too many unknowns. Instead, you’ll need to choose a language with manual memory management, such as C or C++, for these real-time projects.
Similarly, because Python uses so many system resources and contains an interpreter, you can typically (I say ‘usually’ because there are alternative options) only run Python code on top of a system with an operating system (meaning no microcontrollers or other embedded systems).
These are just a handful of the benefits of Python for beginners. There are so many resources available these days to get started that it will be a little time investment to begin programming with Python.
Which language did you learn initially, and why did you choose it? Tell us in the comments!
To find out more about Python Programming Lessons, feel free to contact us at [email protected]
Or WhatsApp us at +65-8351-8517