Mixins or composition?

Mixins are great for "horizontal scaling" by adding functionality to a class over time. Reading mixed in code has an element of "gotcha" because the methods are scattered over multiple classes. Composition is great for handling complex functionality by insulating individual parts into their own classes and just exposing the bare interface to each other …

Advertisements

Another short story, where unit tests save my butt

I like to refactor. A lot. As I work on a problem I understand it better and I want to reflect this in the code. I was nearing the end of a pretty serious refactor. The tests had been failing for the last 60 commits or so. I wasn't worried, I was expecting this. But …

Embed Ace editor in a Python QT app

QT is an amazing framework, made all the more useful by having delightful Python bindings. QT supplies powerful tools to integrate host code with Javascript (web) frameworks, but they can be tricky to get started with. I wanted to integrate the Ace editor (written in Javascript) into my desktop Python program. Could I do it? …

Some macOS + Pyside2 tips

A live document, from the school of hard knocks ... Get macOS to use a fixed width font: setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont)) Get QTabWidget to have tabs on the left side and looking "professional" self.setDocumentMode(True) An epic can be written about the confusing behavior of menus on macOS, but the main reading material is https://doc.qt.io/qt-5/qmenubar.html#qmenubar-as-a-global-menu-bar menu.setNativeMenuBar(False) # We …

Python3: subclassing int

Lying awake at night, existential questions cross your mind. What is my purpose? Is there a god? Can you subclass a Python3 int? Only the last one has an answer. You can indeed subclass an int, but there are a few subtleties. In short, in Python3 depending on whether the built in type is immutable …

Mixins!

Mixins are classes which are not meant to be used by themselves but instead are meant to be combined with other mixins on top of a base class to extend the functionality of that class. They are a great way to modularize code and make class features compose-able. Mixins are best explained using a simple …

Tests and code coverage in Python

Not only is Python a nice language but it has always had a lot of tooling around it. I've always taken advantage of Python's tooling around testing (okay, not always ...) and recently I began to pay attention to code coverage again. Python makes it all so simple and delicious. I have used nose in …