Some of you who follow me may have noticed a tendency of mine to “hack” programming languages more than really use them (other than reflection via annotations in languages such as Java; I hate that stuff), and today is no different. Today, we look as using what would be normal higher-order functions as Python decorators to create new functions that encapsulate the idea of both the higher-order function as well as the passed-in function under one name. Continue Reading

A while back, I did a post on making instance-level properties in Python where the implementation of it required inheritance as well as messing with __getattribute__() and __setattr__(), which are a little dangerous to mess with. Then I had another idea last night (as of the time of writing this): Use normal descriptors to delegate to “Delegated Properties” (name taken from Kotlin, the original inspiration). These Delegated Properties can be designed very simply in a way that they only have to worry about the value on one instance, instead of figuring out how to store the value per instance. Continue Reading

I need to preface all of this with a disclaimer:
I love Python, but I am able to see plenty of faults with it. In this article, I attempt to provide a very roundabout way of working around one of those faults: the lack of multi-line lambdas. This is not to say that this is a good solution, but it may be one of the best that we have for certain cases. Try and see if one of the typical workarounds is the best option before settling on this. Continue Reading

Making Descriptors that act as specialized properties can be tricky, especially when it comes to storing the data the property controls. I should know, I literally wrote the book. Looking at how other languages do it – especially Kotlin’s Delegated Properties – I felt that Python could use a system that works more like that. Continue Reading

This may come as a shock to my regular readers, but even as a Pythonista and Kotlinite, I’m a little jealous of JavaScript. That’s right; I – a JS hater – am jealous of JavaScript. More specifically, I’m jealous of JavaScript’s object literals (also full-featured function literals, but I don’t think I can do anything about that). Yes, in many respects, JS object literals are almost exactly the same thing as Python’s dicts, but there is one important difference: dot notation access.