VBA, Python, PHP or C: is it the same?
01/08/2020
Let's take an almost ideal example for an informatics treatment: the sudoku.
The first concern of the computer scientist is to choose a representation of the data and to specify the interactions with the user. The sudoku being a grid of numbers, we jump on the facility by choosing upfront the context of a spreadsheet.
In VBA
To spot the initial constraints we put them simply in bold ; for example:


Not only it's unreadable but in addition it's slow but then slow from slow.fr !

But well, it does the job ; here the first solution found:

It must be admitted that the constraints of this sudoku were viciously chosen to require a large number of iterations.
In Python
Let's consider a more pedagogical version of this treatment, written this time in Python:

2 1 4 3 6 5 8 9 7 3 5 6 7 8 9 1 2 4 7 8 9 2 1 4 3 5 6 4 9 5 1 3 7 2 6 8 8 2 7 9 4 6 5 1 3 1 6 3 8 5 2 7 4 9 5 7 1 4 9 3 6 8 2 6 4 2 5 7 8 9 3 1 9 3 8 6 2 1 4 7 5Found in 1453557 iterations.
The Python has in addition the advantage of imposing the presentation of the code, which makes the (re)reading more accessible to all (even to its author when he has to come back to it several years after).
In PHP
For fun, the same treatment but in PHP:

It's moreover this proximity of treatment time that will have motivated the (empirical) search for constraints requiring a large number of steps (iterations) to obtain a first solution, no less than 1,453,557 treatment steps to find a first solution that satisfies the constraints chosen for the example.
In C
But then in C, what does it give ?
0.08 seconds.
Yes, it's well 8 hundredths of seconds... that is to say more than 5600 times faster than in VBA and 200 times faster than in Python !
In prime the code is much more beautiful:

These four examples have in common a procedural programming style (to oppose for example to an object oriented approach) and the treatment approach.
The sudoku grid is managed informatics in a table whose each cell, located by its line (l) and column (c) indices containsthe numerical value (v) of the figure it contains. A 0 codes for an empty cell.
The treatment is distributed in two functions:
- valid(v,l,c)
- search(v,l,c)
The first function checks the validity of a value v put in the cell (l,c). We check that the value v is not already present on the line l, nor on the column c nor in the 3x3 cells region to which the cell (l,c) belongs.
The second function is recursive (it calls itself). It first searches which value would be valid in the current cell and it then ensures that this value is compatible with a solution for the rest of the grid, starting with the next cell. If this second condition is not verified, we try another value. If we have exhausted all possible values, we question the value chosen at the previous cell.
And if we manage to find a valid value for the last cell of the grid, we have found a solution !
Differences of "details"
But writing this same treatment in VBA, Pyhton, PHP or C is not at all the same story.
The solution in VBA compared to those in Python, PHP or C is singularized by its dependence on the Excel context. The difference jumps to the eyes.
The solutions in Python, PHP or C resemble each other much more. They nevertheless have subtleties that could make lose a crazy time to the expert of one of these languages who would want to use another of which he is less familiar.
Some examples:
The structuring of the code
The instruction blocks in Python are defined by the indentation (the offset from the left margin) and by braces in PHP or C. This presentation constraint of the Python that we also had in Fortran is a hindrance for the experienced and isolated programmer but a help for the beginner or the teams of programmers.
The management of variables
In C, we must declare beforehand each variable and specify the type of data for which they are intended. We must even explicitly reserve (and then liberate) memory space in some cases (not illustrated in the example).
In PHP, the variables are identified by a $ and managed automatically. We can even use the same variable to store different types of data. Compared to C, it's cool but we end up with $ everywhere.
In Python, the variables are identified and managed automatically.
There are also differences on the visibility of variables. In C, global variables are visible everywhere ; a joyful source of error. In Python or PHP, we must introduce them in the functions with the keyword "global".
This evolution of the management of variables goes in the sense of simplicity for the programmer. One of the prices to pay is a concession on performances.
The more technical aspects
The difference between Python, PHP or C is even greater for more prosaic but nevertheless unavoidable aspects.
The examples given in illustration pudically mask them. It is notably the instructions that display the found solution or, even more, that initialize the sudoku grid and its constraints. The mastery of these more technical aspects makes all the difference between a beginner or experienced developer ; and that has nothing to do with a syntax question !
There is also another important nuance that distinguishes Python or PHP with C. The two first languages are interpreted, the C is compiled. This compilation step ensures a considerable performance gain at execution but entails a complexity and additional charge for the programmer.
The art of the computer scientist
It's not the mastery of a language that makes the computer scientist, no more than the use of a mouse or a keyboard nor the knowledge of a "framework" or an IDE.
In the end, the computer will systematically execute and at a super-human speed elementary instructions (each instruction performing a ridiculously simple action).
The art of the computer scientist is expressed in the conception of a treatment approach well adapted to solve a given problem.
And it's universal.
(Sources of the code examples on request)