As a developer, you pride yourself on your ability to explain the tools you create. You methodically think out the path you want users to follow. As you begin to write content, however, you have a decision to make: which language should you write your examples in? It seems like a tough choice, as your application may support multiple languages. As with your children, it may be difficult to pick a favorite.
We come back to Python because:
- It is easy to read, even if you aren’t fluent
- The environment is straightforward to set up
- Python is popular and growing quickly
There is not a “best” language for all uses. Personal posts are probably best written with sample code in your strongest programming language. Or, your audience of developers may primarily use something other than Python. However, when it comes to choosing a single language to provide examples to a broad audience, you want a popular language with straightforward and easy-to-read syntax. You want Python.
Python Has Easy-To-Read Syntax
Whatever your reason for writing developer content, it stems from the general desire to help others learn something. Whether that be a getting started guide for your application or just a general tutorial, you want your readers to understand the concepts. And just like how long, verbose sentences can obfuscate their meanings, verbose languages can obfuscate the concepts your example code is trying to show.
Let’s look at the most popular example in the world, printing “Hello World.” Here’s that written in C:
#include <stdio.h> int main() { printf("Hello World."); return 0; }
If a user isn’t familiar with C, the nuances of the language will distract from the explanation of the concepts. Why is the main function set as an integer? And why is it returning 0 if we’re just printing a string? And while not a major issue in this particular example, curly brackets and semicolons add a lot of busyness that makes examples harder to glance at.
Now let’s look at printing “Hello World” in Python:
print("Hello World")
That’s it. A user immediately understands the purpose of the example. C developers can apply the concepts to work in C. A Python user trying to extract the sample’s concept from C code would be a much harder task. With your examples in Python, users from all backgrounds will understand what you’re trying to say. Not only that, but users from all backgrounds can easily set up and replicate your code in Python, regardless of their Python experience.
Python Setup Is Straightforward and Easy to Reproduce
Your examples are most useful if the reader can follow along. To make that task easy on your users, the language you’re using should be easy to set up. You also don’t want to waste too much time or space explaining how to install your content’s prerequisites. Developers can be quite an impatient bunch, after all. You want to get to the point, and Python’s simple setup lets you do just that. Installing Python and getting into a Python environment can be done in three steps:
- Go to the Python website and download it for your system
- Download the necessary packages via the command line:
pip install <package>
From the command line, enter
python
You are now in a Python environment ready to follow the example.
Just like that, someone who wasn’t using Python now has a complete working setup. But honestly, nowadays this won’t be necessary for many users. After all, Python is quickly becoming one of the most popular languages.
Python’s Rapid Popularity Growth
It’s appealing to pick the most popular language for your examples. It makes sense to use the language the most people are familiar with, regardless of how simple its syntax is. Luckily with Python, you don’t have to choose between simple syntax and popularity; Python offers both.
For example, coming in second (and tied with Java) on the January 2020 RedMonk programming language rankings is Python.
These rankings are determined by a language’s popularity on Stack Overflow and Github.
Even Stack Overflow acknowledges Python’s popularity. Note the first key result from their 2019 survey:
Python is already one of the most popular languages in the world and it’s not done growing. Used in a wide variety of fields from data science to academia, if you want your content to be applicable for people from all backgrounds, Python isn’t a bad bet.
Let’s Write Some Python Tutorials
With its popularity, ease-of-use, and easy-to-read syntax, Python seems tailor-made for presenting examples. That’s why we use it in many of our client projects. If you’d like help reaching Python developers with your code samples and tutorials, you can work with EveryDeveloper.