Wikipedia puts the following program code as an example of a computer program that shows why the halting problem is unsolvable:
I can follow the argument that if such a program $g$ exists /is well defined then we get a contradiction and so the totally computable function $halts$ can't exist. However I don't understand what the program $g$ does. I dont understand the defintion of $g$ to the point where I can't even execute the first two or three steps of it by hand. I have almost zero knowledge about programming languages and probably that's what I am lacking. I already know the proof of impossibility of solving the halting problem by enumerating all Turing machines and using a diagonalization argument, however I still want to understand the computer programming language version of the proof as it looks very concise. I d be grateful of someone can explain to me what $g$ really does


Let us consider a slightly adjusted version of g.
Now, let us go through each line step by step.
Let us provide a few examples in the Python programming language (since the code in the proof is basically python code). I suggest that you execute the code yourself by using a jupyter notebook or any other environment of your choice.
If we execute the above code, then it prints 'Hello world'. Notice that we are calling a function called 'print' which takes a single argument as an input. In our case we have provided a string 'Hello World'. Let us write a function that calls another function that calls the printing function for us.
The above does yield in the same result as the first implementation. We call the function 'g'. Within that function we call another function called 'loop_forever'. The function 'loop_forever' prints 'Hello World' by calling the function 'print'. Notice that we have not defined the function 'print' but it is defined somewhere in Python itself. We ignore the implementation at this point in time and just assume that it prints the provided string to the console (which it does; try it).
Now, let as adjust the function 'loop_forever' as follows.
The statement in the second line is called a 'while loop'. It executes everything after the ':' which is indented as long as the statement in between the 'while' and the ':' is true. In our case the statement $1 == 1$ is always true (the $==$ is a python operator which tests if the right hand side is equal to the left hand side and returns 'true' if they are equal and 'false' otherwise). What will happen if we call the function 'loop_forever'? It will print 'Hello World' forever. The function does not hold.
If we take a look at the compiled code, then the compiler usually compiles the above to the following.
The statement '$1 == 1$' is assigned to a variable called 'a'. The while statements runs as long as the variable 'a' is true which is always the case in our implementation.
Most compilers are quite clever and usually would compile the above to the following.
Since the statement 'True' is trivially always true, we could implement our initial implementation as follows.
Now, let us consider the second line of the function 'g'.
Let us consider the next six lines. This is called an 'if-else-statement'. It reads as follows: If the variable 'doesHalt' is 'true', then execute 'loop_forever'. If the variable 'doesHalt' is 'false', then just return the value 'True'.
We have two cases.
If the first case occurs, then the function 'halts' must have returned true with 'g' as an input argument. If the second case occurs, then the function 'halts' must have returned 'false'.
How do we implement the function 'halts(g)'? It appears that this is not possible in the 'real world' for general input functions. The only way to determine whether a general function does or does not halt is to actually execute it. The problem is, if the function does not halt then it would run forever. In theoretial computer science the function 'halts' is an oracle function that is defined as a black-box function. We just assume that it returns 'true' if the function we want to test does hold, and 'false' otherwise.
Now, by definition the function 'halts(g)' only returns 'true' if the function 'g' does halt, BUT then the function 'loop_forever' will be executed since 'doesHalt' is 'true' and 'loop_forever' executes a while loop that never stops, thus the function 'g' does never stops running. It never holds. A contradiction.
The argument for the second case is similar. If 'doesHalt' is 'false', then the function 'halts(g)' must have returned 'false'. By definition this means that 'g' does never hold, but since 'doesHalt' is 'false', the 'else'-case is executed which just returns 'True'. The function 'g' halts. A contradiction.