blog podcast

The Funny World of Python

Now that I’ve started digging deeper into AI, I’m finally also getting to hang around a bit more with Python. Historically I haven’t been a big fan of Python. As a developer I’ve often worked in corporate settings where we’ve used JVM-languages or Javascript. As such many of the problems I’ve been solving are these days written as mappings of lists, with map functions or reduce functions. Coming into Python I was expecting simple functions to handle these kind of features, but I found the way these things were handled unintuitive and clunky.

Now that I’m working with AI though, I feel like I’m seeing some of the merit of Python. Writing Python code reminds me of my old days working with Matlab. A lot of my work now has to do with matrices, and the way that Python handles broadcasting, where it intelligently can convert operations between scalar values and matrices into something that makes sense is such a joy. It feels really powerful to have element wise multiplication of two matrices available as A * B, and at the same time matrix multiplication available as np.dot(A, B). The way that operations are also sped up by parallelization is really impressive. All in all I’ve had a really smooth developer experience for doing math.

One interesting difference I’ve noticed is how many assert operations are used and how well the functions that are used are documented (at least in the course I’m taking). I suppose this makes sense when you have a none typed language where you are using matrices, it’s so easy to get the dimensions wrong. The assert takes the place of the unit tests I would normally be writing, with the up side that also other users that are using your module gets fast feedback on when something is not living up to expectations. The documentation on the functions is also really nice. Once again I suppose it makes more sense in this setting as mathematical coding is more complex than normal business logic.