Every domain of human activity has its own first principles. These are the foundational concepts, distinctions, ideas, and mental models upon which that domain is based.
And in my experience, the most useful first principles are not generic and hand-wavy. Instead, they are precise and specific.
One example: Python's "function object" abstraction.
In Python, functions are objects. That means you can store them in a variable. Like this:
>>> def praise(name):
... print(f"{name} is tall and handsome!")
>>> describe = praise
>>> describe("Aaron")
Aaron is tall and handsome!
This has some big implications. You can write a function that creates and returns a different function. You can pass functions around just like you might pass around an int or a list or an instance of a class; as far as Python is concerned, a function is just another value.
That lets you do some very powerful things.
One example: the Strategy design pattern.
Do you remember this one? It lets you select an algorithm at runtime. And in most languages, you need to write a special class with a special method to make it work. But in Python, you can just pass a function object instead. Like this:
>>> numbers = [7, -2, 3, 12, -5]
>>> # Sort the numbers.
>>> sorted(numbers)
[-5, -2, 3, 7, 12]
>>> # Sort them by absolute value.
>>> sorted(numbers, key=abs)
[-2, 3, -5, 7, 12]
See the last line, where it says "key=abs"? Notice there is no open parentheses after "abs". You are passing in the "abs" function, not calling it.
And this is without even opening the metaprogramming can of worms, filled with vibrantly wriggling features like decorators.
Again, this function-object thing is just ONE of the first principles of programming in Python. There are many more; other languages and technologies have their own, uniquely valuable first principles too. And it goes far above the language level, to the system design level and beyond.
When you learn to recognize, leverage and apply first principles in your own work, you find you can do things you just couldn't do before.
If that doesn't give you an unfair advantage in this frenetic age of AI, setting you apart from the drooling vibe coders, then nothing will.
If you liked this, you will enjoy the Powerful Python Newsletter.
Top comments (2)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.