Hacker News new | ask | show | jobs
by Aaargh20318 1265 days ago
The other day I had to make sense of some Python code that used numpy heavily. It was an absolute disaster to figure out what the code was actually doing because of Python's lack of proper typing.

Take for example, the numpy.dot function. This is from the documentation:

> numpy.dot(a, b, out=None)#

> If both a and b are 1-D arrays, it is inner product of vectors (without complex conjugation).

> If both a and b are 2-D arrays, it is matrix multiplication, but using matmul or a @ b is preferred.

> If either a or b is 0-D (scalar), it is equivalent to multiply and using numpy.multiply(a, b) or a * b is preferred.

> If a is an N-D array and b is a 1-D array, it is a sum product over the last axis of a and b.

> If a is an N-D array and b is an M-D array (where M>=2), it is a sum product over the last axis of a and the second-to-last axis of b:

So to figure out what this call to dot actually does and what it's output type is I need to know the actual types of 2 inputs. Of course, those inputs are the results of other function calls, that are also dependent on the types of multiple inputs. When reading code you have to manually keep track of each type as you read through it, you have to look up every function to see what it does and what it can return under what conditions.

Programming languages are not for computers, they are there for humans to understand what is going on. Python absolutely fails at this because python code is almost totally unreadable. It is at best a write-only programming language.

1 comments

You're complaining about a library, not Python.