DEV Community

Cover image for Introduction to modern Python
Paul Nasdaq
Paul Nasdaq

Posted on

Introduction to modern Python

Wait, wait.... So what really is Python?

Python is a popular high level general purpose programming language. It has garnered reputation for being an elegant and easy to use language,(compared to other popular languages like C, C++ and Java) with clean and easy to read source code and easy to use data structures. This makes it ideal for newcomers to the world of programming and the perfect language for people who want to get a program up and running real quick but don't really want to get deep into software engineering territories. (e.g Data scientist, script writers, automation etc). Python is interpreted and supports multiple programming paradigms. Because of all this, Python has found successful uses in various fields of computing such as

  1. Data science
  2. Software engineering

Python : The good parts

1. It is dynamically typed

Dynamic languages are easier to work with. You do not have to explicitly specify the data types of variables in your program. This makes your source code more concise and less verbose. You also write less code, and this translates to increased productivity. You do not have perform any explicit type casting, conversion or coercion. (Some type conversions can result in loss of precision, and others are just not possible).

2. It it multi-paradigm

Python allows you to write your program in pretty much any style you may desire. A language like C is strictly procedural. You break down the programming tasks into functions (procedures) and call those functions to complete your programming task. A language like Java is strictly Object-Oriented. Everything has to be defined in a class. Python on the other hand allows you to mix these styles, and supports others, such as functional and asynchronous programming.

3. It has a rich standard library

The Python's standard library is massive, arguably one of the largest. It comes with packages and modules for some of the most common programming tasks such as network I/O,file manipulation, data persistence, data compression, cryptography, concurrency etc, out of the box. Furthermore, more specialized packages can be downloaded from the internet (usually for free) through PIP, Python's easy to use package manager.

Python: The bad parts

1. It is slow

It is safe to say that Python is slower on average compared to other popular programming languages on the market today. This is actually expected, due to a number reasons. It is interpreted, meaning that it cannot be optimized for a particular CPU architecture like compiled languages can. Plus there is a small overhead of running an interpreter below your code. Pretty much all primitive data types are immutable in Python. As such, modifying such values once created is usually a very expensive operation. Compiled and statically typed languages directly manipulate the bytes in a computer memory when they need to modify a variable, and this is magnitudes faster.

2. It is not the most memory efficient language

It is not uncommon for a Python variable to occupy way more memory than is ever going to be used during runtime. In comparison, a language like Go allow a programmer to specify how much memory a variable will occupy. For example, through constructs such as int8, int16, int32 and int64, a programmer can explicitly state that an integer variable should take 8 bits, 16 bits, 32 bits and 64 bits of memory respectively. This level of control allows a programmer to craft arguably more efficient programs.
This is also the reason (if you asked me) as to why Python is not gaining much traction in mobile computing and embedded systems, as these platforms are relatively resource constraint

3. It is dynamically typed

Dynamic typing as a feature of a language is a double edged sword. On one hand it allows you to quickly get up and running with programming, and on the other hand it becomes a problem in really large software projects. It is possible to assign to a variable a value with a type that should NEVER be assigned to said variable. A hypothetical age variable in a program can be assigned a string value, and this will go undetected until runtime. Static types are also self documenting. From a function's signature, you can quickly know what types of values a function/method expects and what type of values it returns (if any). You won't have to explicitly document this, for example, using Python's docstrings.
The good news is that Python provides built-in support for type annotations through it's typing module. This allows you to annotate the data types of variables and arguments that a function/method takes. It is therefore a good idea to use this in really large Python projects.

The take away

All programming languages are nothing but tools.
Said pretty much any experienced programmer out there

And in this regard, Python too, is nothing else but a tool. Like any tool out there, it is specifically designed to be really good at some tasks, and not so good at others. It probably isn't a good idea to use a screwdriver to drive nails into wood(even though, with enough determination, you can)
It is therefore wise, as a programmer, to select and use languages that are fit for particular problems.
Scripting, prototyping and small scale to medium scale software projects.. Python is a good bet.
Large enterprise applications, applications with need for speed, resource starved platforms.... I'd be more than happy to switch.

Top comments (0)