by junon · 7mo ago · 0 comments
Document why. I can read code. I want to know _why_ this nebulous function called "invert_parameters" that is 200 lines long even exists. Which problem did you have that this function solved? Why was this problem there in the first place? Write some opinions on maybe its intended lifetime of the codebase. Hell, I write comments that apologize, just so that a future reader knows that the code I wrote wasn't meant to be great but that I was in a time crunch or a manager was breathing down my neck, or that some insane downstream/upstream thing did something... well, insane.
Paint some picture of your mindset when writing something, especially if it's non-obvious, as that'll give all the additional context not captured in code, when reading the code.
Obviously this isn't the only good documentation rule, but I wish people - juniors and seniors alike - would do this more often, especially at the workplace.
Documentation can take many forms: ADRs, system diagrams, specs, JIRA tickets, commit messages and descriptions, PR descriptions, code comments, idiomatic/intuitive code, etc. etc. and much of that requires maintenance or review to ensure it's still up to date.
Outdated tests quickly become broken tests, and they serve a purpose as documentation as well, but aside from throwing around buzzwords like TDD and BDD and all that, it's rarely a skill that is explicitly developed. Or maybe it's handed over to an SDET or something.
Build a decent set of tests that can survive the implementation being refactored, rather than coupling them to the runtime code or filling them with mocks and stubs, and you can get a good way to documenting complicated routines simply because you are explaining how it works through numerous well-described assertions.
That means you never need to bother with the 'how' or 'what' when commenting code, and you have multiple levels of 'why' as you go up from the code to commits to the issue tracker and beyond.
Sometimes the intent is obvious and doesn’t need explanation, you’re implementing the feature.
But if the intent is not obvious - like compensating for some out of band failure, or responding to some not obvious business need, or putting in something temporary that will be fixed later, then the reader needs to know.
It’s frustrating that so few think about the perspective and needs of the reader or reviewer, not just the machine.
Code is a specification for execution. It should include everything needed to fully execute and understand it.
This is why even microchip makers put much of the SPI signal specification into each datasheet despite SPI being a super common protocol. The more your code's comments act as a datasheet, the better longevity it'll have.
Some of that's inevitable, but I'm continuously surprised about how unconcerned people are about it day to day.
I document why stuff in comments, commit messages, and other documents all the time. It's super easy since 1) I've been there when that shadow knowledge goes away, 2) I can think about future-me when I write that stuff, because I know I'll forget a lot of it. I don't know why so many people have a problem with doing the same, and need to be constantly reminded to do it.
Probably a big part is letting the perfect be the enemy of the good. I don't consider anything to be definitive, it's all clues to be pieced together later, and I just like to leave as many clues as possible.
That's why I always believe the following two points:
1. Engineers are trained on-job. This means, if you want to be a good engineer, a really good one. You need to be very picky about what you do. Most of the "engineer" positions out there, like 95% of them, do NOT promote, or even go against the best principles of true engineering, so you are basically fighting against the objective that is to be the best engineer you can be.
2. Engineers should NOT deal with complicated business rules -- that is, it can exist in code, but the stakeholders are the one to provide and explain it. We should want NOTHING of it.
Serving business interest, and keeping our jobs ≠ doing whatever the business stakeholders want, that means we have to be very picky about the kind of job we do, the kind of team and company we want to be part of it.
I can kind of see that, if you're so disengaged you don't care if your job is hard or easy. Then you just see it all as slogging for a certain number of hours a day.
But I don't get that. I don't like things being unnecessarily hard, and writing stuff down makes it easier to actually get things done in the future. And at some point you're going to get judged on your performance, so wasting a bunch of effort uselessly slogging doesn't make you look good if someone paying attention to if you're actually getting things done or not.
The biggest reward is me making my own life easier, and when I do that I can always later pretend to slog a big to grab some time for myself.
Frankly I don't blame workers either, it's not their fault they have to play a stupid game that helps no one so they can continue to have health insurance and not become homeless.
The last business I started, I was coding at full steam building features that I could make work now although not optimal, so I would add comments reflecting that.
Over the > 15 years the product’s been on the market, there have been several times I’ve come back across those comments when we outgrew the quick solution several years later.
It wouldn't be able to reverse engineer why something was done when the "why" is some arbitrary decision that was made based on the engineer not having had his morning coffee yet, but those "whys" aren't an important property of the system, so who cares? Even in the unlikely event that someone documented that they zigged instead of zagged because it was just the vibes they were feeling in that moment, nobody is going to ever bother to read it anyway.
I have seen countless engineers just while away the years modestly building and documenting incredible systems. Systems that "just work" for years on end. They never get fired because they're recognized for their value, but they also never get to the top.
Bullshitters, on the other hand, have no ceiling. They are never out of their depth because they transcend skill or accountability. They'll tell you they know everything, they'll tell you nothing is impossible, they'll gossip and disparage everyone else. The best bullshitters are full-on psychopaths and these are the guys that run the world.