Brilliant Programmers
I’m not a brilliant programmer, or even a clever one. But I can spot brilliant ideas.
I’d like to share a few cases of brilliant programming solutions vs clever ones.
Scenario 1.
A clever programmer had found a way to restructure a section of code to reduce the total number of calls to a microservice.
function getDashboard()
{
var metrics = getMetrics();
var userSettings = getUserSettings();
}
function getMetrics()
{
var userAuth = getAuthCreds();
// .. Do some cool stuff.
}
function getUserSettings()
{
var userAuth = getAuthCreds();
// .. Do some cool stuff.
}
As you can see, the two functions both call getAuthCreds, but we can move it up to the parent getDashboard function and pass it in as a parameter to save a request.
A brilliant programmer instead added a per request cache of the getAuthCreds call. Now it wasn’t as important to track and worry about optimal structuring to reduce the total number of getAuthCreds calls. This was a big win. I know someone is probably going to groan about caching and state, but it was well worth it here.
Scenario 2.
A clever programmer noticed a common mistake in C is accidentally assigning a variable in certain contexts.
while (foo = 0) {
... Whoops! That should be `foo == 0`.
}
And to mitigate this issue, they started writing these expression backwards.
while (0 = foo) {
...
}
Now the compiler will complain if they accidentally use the wrong operator! Clever.
A brilliant programmer writes a static analyzer and hooks it somewhere into the project pipeline, preferably so the developer gets feedback as soon as possible. Not only that, but the infrastructure they set up can likely be extended with new analyzer rules as need be. Brilliant.
The brilliant programmer always seems to be able to bend reality to his or hers whim, while the clever one expertly sidesteps the issue.