Class interfaces are an area of expression. When writing a Class, we shoot for many criteria: clarity, extensibility, compactness, testability, and joy. Salomon and Ainsley like to group these into one vague attribute: ergonomics. All engineers have some innate sense of what is ergonomic. Dearest reader, would you reach for a class with 60 arguments for initialization?
Wording is one easy crutch for instigating ergonomics: “What do I name this method?”. “Get” gets the gold as a verb for extraction. It is a deserved victory. “Get” functionality lives alongside “set” functionality; “Set” is one letter away from “get” delicious! No surprise then, so many interfaces in the wild adopt “get” and “set”; they are the de-facto champs. Alas! However! Still! Yet! Nevertheless! Irregardless!
There exist more appropriate terms which carry more context:
- Fetch: resource is not local
- Yank: vim
- Find: filtering happened
GET
:HTTP
- Access: auth
- Retrieve: onerous
- Pluck: discriminate
- Yoink: cheeky steal
“Get” is excellent, but not considering context would place engineers at an ergonomic local maximum. The terms above provide more appropriate solutions sometimes, but they too can be unideal. Our new constraining factor: only concerning ourselves with finding the best piece of language.
Reaching for ergonomics via vocabulary is organic! Higher abstraction programming languages are not machine speak.
An ergonomic complement
How about other approaches? Widen the net of context until you reach our programming language, and you will arrive at “convention”.
Someone in some room right now is in a screaming match over what is Pythonic 🐍.
Look to Collections! You know collections; “List"s and “dict"s are particularly prolific, but you might be familiar with an expanded set: tuple, deque, string. Collections subscribe to similar interfaces amongst themselves and beg you to join them. For a moment, let’s depart the Python Bakery and visit the Java Kitchen.
String str = "Sharpen your knives.";
str.charAt(5);
Java has arrived at a nice ergonomic name for this indexing functionality. Python eschews words altogether and opts for ergonomic ✨magic✨.
str_ = "Kiss your croissants."
str_[5] # 🥐
This detail is one of my (Salo!) fave design decisions in python. Not just the broader theme, specifically that string is part of that theme.
There is much to be gained by following this convention. While many people understand what get and set mean with enough context, every python developer knows []
. That then is the pitch:
When writing class interfaces that require get and set functionality, implement it with
[]
.
The above is not a brilliant insight but rather the under-leveraged design of the language. The Remix web framework has a philosophy section in their docs, feast upon this gem:
Work with, not against, the foundations of the web: Browsers, HTTP, and HTML. It’s always been good and it’s gotten really good in the last few years.
Replace all the web words with python words in your head, please.
We can’t wait to show you examples of this in the wild. Maybe also to broaden your horizons regarding what functionality you can interpret as a collection. If you feel happy with what you have read thus far, consider reading part two.
Love,
Salo & Ainsley