Python - An analysis

.

Let me know what I should add to this, in my opinion, Python is a good language to start off with, as it is very easy to learn with. However, people make the argument, “Python is better than x”, but most of the time, that’s just wrong, and this is to support that Python is a bad language to build complex or even intermediate projects.

Table of contents


  1. Performance
  2. Readability
  3. Popularity
  4. Professionalism
  5. Usage in final projects

1. Performance

4/10
We all know the jokes about Python taking up 15GB of ram for Hello World!, but is this actually true in concept?
In this, it will be comparing to interpreted languages (This is to not include bias, as it’s obvious that a compiled language will run faster than a interpreted language.) Just to see if Python is actually slow. I will be using the code provided below in both Python and NodeJS, with no launch args.
Here’s my full spec list at the time of recording their performance:

OS:			Windows 11 Home
CPU:		Intel(R) Core(TM) i3-4130 @ 3.40 gHz
RAM:		x2 8 GB DDR3 DIMM 1600 mHz + 2.3 GB SWAP
SSD:		PNY CS900 500 GB
GPU:		Integrated + NVIDIA EVGA GT 730 1GB
Python:		v3.11.3
NodeJS:		v18.16.0

Commands/code used to run this test:
(Powershell)

Measure-Command { ... }

(NodeJS, average 105.35ms)

/*
 This work is marked with CC0 1.0 Universal. To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0
*/

const iterations = 1000000; // Go through a million iterations with a constant, to see how they deal with them

var last = 10591529152; // Just a random starting number
const getNumber = () => last = ((~last) >> ((last % 3) + 1)) | ((~last) & ((last % 4) + 1)); // Some randomness with calculations, as to not have any bias towards small programs (Set in place by both Python and NodeJS)

var b = 0; // Average number
for (var i = 0; i < iterations; i++) { // Go through the iterations
	b += getNumber(); // Add the number
};
b /= iterations; // Get the average
console.log(b); // Log the result

(Python, average 473.31ms)

"""
 This work is marked with CC0 1.0 Universal. To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0
"""

ITERATIONS = 1000000; # Go through a million iterations with a constant, to see how they deal with them

last = 10591529152; # Just a random starting number
def getNumber():
	global last
	last = ((~last) >> ((last % 3) + 1)) | ((~last) & ((last % 4) + 1)) # Some randomness with calculations, as to not have any bias towards small programs (Set in place by both Python and NodeJS)
	return last

b = 0 # Average number
for i in range(ITERATIONS): # Go through the iterations
	b += getNumber(); # Add the number
b /= ITERATIONS; # Get the average
print(b); # Log the result

Performance chart:

Program NodeJS time (ms) Python time (ms)
getNumber 105.35ms 473.31ms
Hello World! 87.032ms 68.701ms

There is some obvious bias towards small programs in Python, but let’s taker a closer look at Python and NodeJS

NodeJS:

var last = 10591529152;
const getNumber = () => last = ((~last) >> ((last % 3) + 1)) | ((~last) & ((last % 4) + 1));

So, let’s go through this as what the program sees:
First off, let’s go to it, it will se that there is a function, but since there is no {}, it will be returning the value, () => 1 will return 1, so the program already knows that the function will return the variable
Secondly, the program sees that last = is the only thing in this, so it will return the value that last is set to, but it knows that last is a variable, due to it being set before, seeing that there is something that it’s being set to

last = 10591529152; # Just a random starting number
def getNumber():
	global last
	last = ((~last) >> ((last % 3) + 1)) | ((~last) & ((last % 4) + 1)) # Some randomness with calculations, as to not have any bias towards small programs (Set in place by both Python and NodeJS)
	return last

Python, will go through the same thing:
First off, we know that there’s a function, with a global variable, last (global last), so it knows to include the last variable within the function
Secondly, it will see that last is being set, with bitwise being included, so it will set last to the variable
Then, it sees that last is being returned (return last), so it will return the variable

We can see how NodeJS optimizes their code, whilst Python is going through something more readable, if there are any improvements in the Python code that is widely known, please let me know, so I can redo the test

We will be giving Python a 4/10 in this category, due to how detrimental this is to the performance, but it’s not too bad, so it won’t be getting that bad of a score.


2. Readability

8.75/10
Comparing the previous code blocks, we can see just how readable Python code is.
(NodeJS)

var last = 10591529152; // Just a random starting number
const getNumber = () => last = ((~last) >> ((last % 3) + 1)) | ((~last) & ((last % 4) + 1));

(Python)

last = 10591529152; # Just a random starting number
def getNumber():
	global last
	last = ((~last) >> ((last % 3) + 1)) | ((~last) & ((last % 4) + 1)) # Some randomness with calculations, as to not have any bias towards small programs (Set in place by both Python and NodeJS)
	return last

and

for i in range(ITERATIONS): # Go through the iterations
	b += getNumber(); # Add the number

We can obviously see that there is a variable, last, and that it equals 10591529152
Something less readable is the function decleration (Why this is getting a 8.75/10 instead of a 9/10), with there being def ...():, with : making more sense than {}, but still because of def, it makes it confusing to people with less knowlege
A bad thing, is globals global last, as we can see that there is a variable just outside of the function, last, but we still need to add global last, so that Python knows to access it, it’s good for complexity but not good for readability
Besides that, python makes alot of sense, with the math part being very easy to understand, function calls making sense, and the return statement returning the variable, along with Python not including ;, it makes more sense for new users
range() is a really easy way to understand for loops, as you know that i will goto ITERATIONS in this loop

Overall, Python will get a 8.75/10 in this category


3. Popularity

8.5/10
There is no doubt that Python is the largest programming language out there, with Python having the LARGEST market share in programming languages, along side it being used in alot of other programming languages. There is however data backing up that programmers prefer to use JavaScript

TIOBE Index (May 2023)

Placement Language Market share (%) Change (%)
1. Python 13.45% +0.71%
2. C 13.35% +1.76%
3. Java 12.22% +1.22%
4. C++ 11.96% +3.13%
5. C# 7.43% +1.04%
6. Visual Basic 3.84% -2.02%
7. Javascript 2.44% +0.32%
8. PHP 1.59% +0.07%
9. SQL 1.48% -0.39%
10. ASM 1.20% -0.72%

PPYL Index (May 2023)

Placement Language Market share (%) Change (%)
1. Python 27.27% -0.5%
2. Java 16.35% -1.6%
3. Javascript 9.52% +0.2%
4. C# 6.92% -0.3%
5. C/C++ 6.55% -0.4%
6. PHP 5.10% -0.5%
7. R 4.34% -0.2%
8. TypeScript 2.88% +0.3%
9. Swift 2.30% +0.1%
10. Objective-C 2.13% -0.1%

statista (July 2022)
Note, this for people who USE these languages

Placement Language Usage (%)
1. Javascript 65.36%
2. HTML/CSS 55.08%
3. SQL 65.36%
4. Python 48.07%
5. Typescript 34.83%
6. Java 33.27%
7. Bash/Shell 29.07%
8. C# 27.98%
9. C++ 22.55%
10. PHP 20.87%

Overall, 8.5/10, due to the overwhelming share of Javascript


4. Usage in final projects

6.5/10

Python is used in many workspaces, but this is mainly for pre-development, as they will likely move onto another programming language later on (Such as C++) for launch. This is why Python is used by so many data scientist, but when you see the production unit, it’ll be in another programming language

Source, spreadsheet

Language Creator Lines of code Median execute time (ms)
Python Matt Parker 110 lines 2,760,670,300ms
Python Benjamin Paassen 133 lines 1,338,000ms
Java Neil Coffey 207 lines 15,026ms
Python Phire 173 lines 2,136ms
C Kristin Paget 299 lines 1,045ms
Rust Orson Peters 112 lines 477ms
C++ Sylvester Hesp 178 lines 70ms
Rust Leonardo Taglialegne 133 lines 28ms
C++ Sylvester Hesp 278 lines 16ms
C Stew Forster 704 lines 5ms
C Stew Forster & Landon Kryger 1152 lines 1ms

Final overview

In my opinion, Python is a great programming langauge for people trying to start out, but as you go forward, I think you should move onto a better language (Such as C++)

4 Likes

Acktshually def is similar to define blocks from Scratch which can make it less confusing to people coming from Scratch :nerd_face::nerd_face::nerd_face:

4 Likes

Well, with def, you have:

def func(args):

vs

function func(args) {

vs

int funcint(int arg) {

So I would say that def func is weird, and doesn’t make much sense, are you defining a variable? Are you defining a function? (): makes sense, because:
you see, but {} also makes sense because it’s this does { hello world and whatever }

So in my opinion, it’s pretty equal

5 Likes

Those people would prefer how C and JavaScript use {} for functions (python doesn’t have much for visual separation between functions).

6 Likes

That was the point, you didnt even notice that I was demonstrating pythons way of doing it

3 Likes

This topic is now published at Python - An analysis - Active Member Chat

4 Likes

As a Pythonista I totally agree with this. Python is the first language I learned and it’s really what made me understand programming. And it’s great for lots of stuff, but it’s also not great at a lot of things. I don’t get programmers who stick to one programming language and try and shill that language as the best language for every single thing when there are languages that are clearly better than it.
An example being Django, who the heck thought using Python in the backend for full production sites was a good idea? Especially when there are so many other languages that are so much better.
Python has it’s place in programming, as do pretty much all languages except Java. And I will die on that hill.
And while I’m at it, another hill I’ll die on is that you shouldn’t statically type your python. If you are writing something that needs static typing, you shouldn’t be writing it in python.

5 Likes

Converted into a Wiki! You can add onto this, fix links, or just improve it, if you’d like.

me trying to use django to say hello world without having a 30 gb folder :skull:

2 Likes

Ok I am still a python lover but that was a rly nice in depth analysis

3 Likes

I was going to do more, but this portion took me 3 hours to do, and i was getting done with it, because i was trying to provide accurate data

2 Likes

lol nice