by deanmoriarty · 6y ago · 0 comments
These days, every single commit I push has an entire paragraph or two clearly describing the changes, and the motivation behind them, even if it's a one-line diff.
My team praises me for this, and I think I've been able to influence the culture as I see more junior people taking their time to craft good commit messages and edit their commit history before pushing a PR.
I sort of agree but what I try to do is put more comments and documentation in the source code directly.
The problem is that commit messages are usually hidden only when there's a problem.
Comments are there for the life of the code.
The problem with comments though is that they could go stale and something could be refactored.
I try to put them directly on methods/functions more and not on specific lines of code.
If I have to document a line of code it probably is a sign that it should be a function/method itself as it's a bit too funky to just stand alone.
Commit messages are GREAT for tracking down when something is broken though.
Would be nice to have your IDE take your code comments and make commit messages for new methods and the documentation for that method/class.
Often times, even a copy-paste is better than nothing. Better to over-communicate
It is also built into Emacs as `vc-annotate` (default `C-x v g`), though `magit-blame-addition` is a better option for projects using git.
But for someone who is relatively new to the English language, this can be the source of much anguish and frustration. Doubly so for something like a commit message that is immutable by design. The idea of a typo, a bad idiom, or even worse, unintentionally offensive phrasing, being surfaced for all to see 10 years from now can be a frightening prospect.
I think this whole discussion goes to show the nature of institutionalized privilege, and how seemingly innocent requirements can have a disparate impact on marginalized groups.
We decided to structure our front-end application using Atomic Design which classifies UI Components in a hierarchy of Atoms, Molecules, Organisms, Ecosystems, and Pages. Pretty universally the definitions of these terms did not translate to many of our remote developers in other countries not only because of the language but likely they didn't have the same Biology education either.
This and other similar revelations have led me to always put myself in the shoes of anyone reading my code, comments, commit messages, and force myself to use simpler language whenever possible.
Communication in software development is a huge deal. While language barriers are a thing, I don't think you can or should compromise on documentation, and when it comes to commit messages I don't think this is the leading reason why folks don't write good ones.
I'm told by friends who were at RedHat when they decided to make the source repositories public (as opposed to just throwing release tarballs over the wall), and commit messages went way way up. This tells me: people knew better, they just didn't care if they weren't being held to account.
Similar here, but: looking back at a couple of years ago I obviously went through a phase where I was just writing complete paragraphs for the sake of making sure the commit looks meaty. So now I treat messages the same as code: code not written is good. If a one-iner is enough to explain why something was done, and the changes in the code speak for themselves, than that's it.
even if it's a one-line diff.
By now you probably figured the size of the diff doesn't seem to have much of a relationship with the amount of commit message needed :)
A good commit message is also really useful for code reviewers: it sets the stage and contextualises all the code they're about to read.
Some information is a pre-requisite for understanding a specific block of code. This information is a great fit for comments, because everyone who's looking at the code will need to know it, and having it in a comment ensures that it's discoverable.
Other information is a pre-requisite for understanding the engineering or business decisions that motivated a design decision, but isn't necessary for understanding how the code works or how to interact with it. That makes it less appropriate for comments, because the comment would just be clutter (light pleasure reading at best) under the most typical use case. People who are engaging in those use cases should know how to use git blame to find what they need.
For still others, the unit to which the information applies is not a block of code; it's a set of changes. In those cases, comments are a terrible choice for conveying that information. Maybe a commit message is better. If it's not, you probably need to be looking to a project wiki or some separate documentation files, so that the information can be written and maintained in one place. You can still use comments, but they should merely cross-reference the centralized documentation. Today's copy/paste is tomorrow's outdated and misleading misinformation.
I feel code comments tend to rot because they are not as immutably bound to the code they describe as a commit message is, and for the most part my commit messages are too verbose to end up in code comments, it would create too much clutter.
I have a good integration with my editor that shows inline blame annotations for the current line (and full message is a keystroke away).
Being able to seamlessly browse the history of a given function is one of the things a fully integrated development environment should support.
Any tips on how you're able to keep things clean for the entire team ? What's your usual workflow? I've read through Martin Flower and a few other blogs on this topic yet have never understood how to avoid "add x", "fix foo".
or time wasted writing unit tests, or pull requests, or code reviews?
(1) It's about effective communication. Why do developers appear to care so much about the way we write our code but not the artifacts that form it's ecosystem (and have a much wider audience)?
(2) If you're going to write a commit message, why not take the incrementally very tiny extra bit of time to do it right?
If you don't really care about the quality of your commit messages I'd suggest stop requiring them and allow blank commits. IMO this is preferable over the false impression that a garabage commit history provides any value.
A nice balance I've found is to not care while developing, but then squash all commits into a single one when merging a pull request and give that a good message.
It was a constant source of irritation at a previous job where the repository had been imported from a different version control system without history. So half the time "svn blame" would just tell you it was in commit #1 ten years ago, which wasn't nearly enough.
I don't think the reader should have to look at the code to get the summary of what the code does and how it does it.
I agree that the "why" should be the focus.
Thinking through describing the change in prose has an immediate positive impact on code quality.
It's a balance between rot and visibility, right? Unless you code with commit messages always visible, you have to go out of your way to look at them. If the interesting line changes even a little bit, you could hide the commit message explaining everything with one that explains a small change.
If I could only have one, I would rather have comments visible in the code, and control they rot through change review, but of course finding a balance between both is the best.
I do this when tracking down bugs or trying to figure out the design of a particular component.
It also serves as a good filter for commit content. If you can't write a good, comprehensive commit message for it, it probably shouldn't be its own commit.
I used to do this, but prefer the list form. I like to note what has been added or removed, if you're searching through the commit history it's all useful.
You can comment the commit all you want, but if it contains three separate and unrelated activities then the commit will still be 'muddy', whereas 3 commits with bad comments but one activity per is far more legible.
Remember, nobody is reading your commit messages, your tests, or (probably) your documentation unless something is already wrong. Then they're already stressed out and trying to grovel through your information. They're already biased toward being grumpy. Don't add onto that. I'm only reading your commits trying to figure out if a bug is a feature poorly realized or not, so I don't break something else.
Except some idiot migrated our bug database to a new server and re-numbered the tickets in the process, so only the last two years are intelligible.