Python for Fun and Profit: Why You Should Learn Python
Python is one of the world’s top programming languages in terms of popularity. It is the leading language taught at universities and other secondary educational institutions. It is often the first choice for applications as wide-ranging as statistical analysis, artificial intelligence, web application development, and simple batch processing or scripting.
That’s also why Python should be the first language you learn:
Python has been around since 1991 and its most recent version, 3.0, since 2008. It doesn’t contain the powerful memory management features of a language like C, nor does it have the robust object-oriented interface requirements of Java or C#. It doesn’t even compile natively to your system for the most efficient run speed. So, why is Python such a popular choice?
It’s those things I just mentioned that make it SO popular. Python’s syntax is much cleaner and easier to pick up for new and experienced programmers, without complicated pointers and memory management. Without the overweight libraries that back up C# and Java, Python is deployable to a wide variety of environments and platforms. That includes embedded devices where resources are highly constrained. Finally, its lack of native run-time compilation means that Python can target a wide variety of platforms with little to no additional work on a developer’s part.
Easy to Write, Easy to Read
Python’s clean syntax and heavily opinionated run-time environment handle much of the dirty grunt work for us. Automated memory management, garbage collection, and dynamic name resolution are all Python features that the interpreter takes for us, without any additional coding on our end. More complex programming languages may offer us extra flexibility and power by putting those things in our hands. At the same time, Python allows us to write simpler, cleaner syntax with more dependable results. See the example below:
A Simple “Hello World” Program
The above line of code, a single line, is a Python program in its entirety. Even if you’ve never written a line of code before in your life, you can probably guess what this will do (it will print the words “Hello, world!” onto the screen). That code cleanliness helps developers focus on what the code needs to accomplish functionally, without spending too much time on the boring under-the-hood stuff that helps make it work.
A Lightweight and Portable Language
In a modern setting, the devices we deploy code to are no longer limited to desktop and laptop computers. We write and run code on tablets and smartphones, Chromebooks, and iPads. We also run code on various household devices, including cars, refrigerators, and even lightbulbs! These consumables often need to be made as physically small and inexpensively as possible. They don’t have the large-capacity RAM and hard disk drives of our computers. Their processors are simple and slow, designed to do a minimal number of tasks.
Python’s native libraries are small and concise, while still offering a wide variety of features you would expect in a modern programming language. Compare this to Java or C#, which come with physically large and syntactically complex libraries, functions, and other features. Those additions make Java and C# incredibly powerful, but bloated. Even when you’re not using them in the final product, the libraries are included, creating large executables that rely on a large run-time environment already installed on the target device.
Python’s relatively lightweight deployments make it ideal for various embedded devices and consumer electronics that now require programming. The idea of shipping a Python program on a lightbulb is much more feasible and cost-effective than trying to squeeze a C# program into the same constrained space.
You need to compile software before you can run it on a target system. Whether it’s C, Java, Python, or Assembly, you need to convert the code you write into binary instructions before you can execute it. Traditional languages perform that compilation step before the software is shipped. This step indicates that the final code, the executable, is efficiently written for a specific target environment and will execute well in that environment. It also means that you’ll need to recompile for that environment and ship a different executable for every additional type of environment you wish to support. Windows requires another compilation versus Mac, which is different from Android, separate from iOS.
Python uses a method called just-in-time compilation. This method indicates you can’t compile the code until it’s already running on the target system. You can develop and ship a single program, with zero changes, to every different platform you wish to support. On those platforms is a separate program, the Python run-time environment, which reads that Python code and compiles it while it’s running. Any platform that has a Python run-time available will be able to execute Python code just-in-time. Because Python is open source, you can develop it for any platform.
For developers, this means writing and distributing a single code-base. It’s much easier to maintain and update and track versus the separate individual code-bases traditionally compiled software requires. It also means that you can deploy to a wide variety of different platforms. Any system that the community has developed a Python run-time for is available to you for executing your Python code. It opens up a much wider world of target systems and devices.
Python is an excellent language for many reasons. The three I listed above are, in my opinion, some of its most robust features and the things that have contributed most directly to its widespread adoption. If you’re learning to program for the first time, Python’s ease and simplicity make it the perfect choice. If you’re an experienced programmer, Python’s industry-wide acceptance means it’s an essential skill to have in your pocket.
And if you’re developing a new program, Python makes for an easy answer due to its wide use and many deployable environments you can target. Pick up Python programming today; you won’t be sorry.