2021-09-19: Consenting adults, CLIs

We are all consenting adults here

It’s a well known concept in Python which most people are aware of but not with this phrase (atleast it was a TIL moment for me).

Python allows you to override properties and methods of an object and you can’t avoid it by restricting it with a “private” like language construct. People usually mark private functions by prefixing it with an underscore (eg: _function_internal()). Although, it doesn’t prevent some code to not override this method, you can still encapsulate your internals and public functionality cleanly.

Considering the flexibility, it’s the job of the developers to understand the trust which Python puts on them.

Below is an excerpt from an e-mail thread which talks about being consenting adults:

Nothing is really private in python. No class or class instance can keep you away from all what’s inside (this makes introspection possible and powerful). Python trusts you. It says “hey, if you want to go poking around in dark places, I’m gonna trust that you’ve got a good reason and you’re not making trouble.”

After all, we’re all consenting adults here.

I came across this phrase this while I was working with ABCs for a project at work and encountered abc.ABCMeta.register() for virtual subclasses.

Consider that we have an interface as an abstract base class like below

import abc


class Demo(abc.ABC):
    @abc.abstractmethod
    def process(self):
        pass

Now we create our own implementation of the Demo interface like below

class CustomDemo(Demo):
    def process(self):
        print("Implement process method defined in Demo ABC")

We have our implementation CustomDemo which implements the interface defined in Demo. Pretty standard practice.

Let’s assume there’s an implementation in an external package which works like our Demo but doesn’t inherit the ABC. We can register such unrelated concrete classes with the ABC as virtual subclasses using the register() method. For example, consider the ExternalDemo implementation like below:

class ExternalDemo:
    def process(self):
        print("Demo implemented by external package not aware of Demo ABC")

You can register this implementation with the ABC like below:

Demo.register(ExternalDemo)

And now we can use ExternalDemo as our own implementation of Demo. As you can notice the flexibility here, Python is trusting you with the “We are all consenting adults” philosophy.

CLIs

I recently worked on a small CLI application at work called trail built in Golang. For this I used Cobra, a library to create CLI applications.

Pretty easy to start with and nicely structured. I also added this to my midi-macro project which had basic command line arguments as inputs before.

While working on this, I also came across the Go Release Binaries GitHub action which automatically publishes binaries to GitHub release assets whenever a new release is created. I don’t have to now go through all the combinations of GOOS and GOARCH to generate binaries on release.

slack-standup → slate

In this season of rebranding, I have also renamed my project slack-standup to slate. For its logo, I used Adobe Spark’s logo maker which suggests to logos based on name, style etc. I don’t have much designing skills and this worked out fine for a small hobby project.

I have been making some beta pre-releases for last few weeks and now I am wrapping up the documentation before publishing the major release and sharing with people. This project seems to be working well at work and multiple teams are using it for their daily standups.

Right now I am using GitHub wiki as documentation but I might consider moving to GitHub pages once I have the project nicely documented.

Some podcasts I listened to last week

Updated: