After publishing my previous article, on Python metaclasses, I got a fair amount of feedback, and there was one point in particular I feel I should elaborate on. It may seem simple at first glance, but it is nonetheless worth discussing in a little more detail: “Why do I use the __init__ method in my metaclass? Would __new__ be more pythonic?” It’s a fair question, but as I show here, I think the __init__ method is better for most cases.
Every article about Python metaclasses contains a quotation (yep, including this one) by Tim Peters: “Metaclasses are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don’t (the people who actually need them know with certainty that they need them, and don’t need an explanation about why).”
With all due respect to Mr. Peters, I completely disagree. Why? Because, as an engineer, I hate magic. Moreover, I hate using calling something magic in lieu of giving a proper explanation. Metaclasses are regular tools, and they are very useful in some cases, and as such it is worth having a working understanding of them. Read more
I was fiddling with D during my vacation, while I was taking a break from building my house, and I wanted to share the most exciting (in my opinion) feature of this programming language – the uniform function call syntax. Read more
When it comes to design, whenever I hear that something “should” be done a specific way, I feel compelled to ask a simple question: “Why?” Indeed, if everyone believed and practiced design patterns without understanding them, engineering would be yet another religion. Therefore it is sometimes worthwhile to revisit, and challenge, certain design conventions.
To that end, what about the “Fat model, skinny controller” (and vice versa) approach in the MVC pattern? Where should the controller’s charges end and the model’s begin? Read more