TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why Not Comments

261 点作者 ghewgill8 个月前

54 条评论

renhanxue8 个月前
I saw someone quip (on twitter, I think) many years ago something like:<p>&quot;A junior engineer writes comments that explain what the code does. A mid-level engineer writes comments that explain why the code does what it does. A senior engineer writes comments that explain why the code isn&#x27;t written in another way.&quot;<p>(except punchier, of course. I&#x27;m not doing the quip justice here)
评论 #41509602 未加载
评论 #41506237 未加载
评论 #41509666 未加载
评论 #41506777 未加载
评论 #41506400 未加载
评论 #41509024 未加载
评论 #41506999 未加载
评论 #41507349 未加载
评论 #41537577 未加载
评论 #41510419 未加载
评论 #41511020 未加载
评论 #41509078 未加载
评论 #41517189 未加载
narag8 个月前
I comment everything that I think would be useful for me when revisiting the code a year later. Usually &quot;why&quot; and &quot;why not&quot;. Sometimes a short &quot;what&quot; when the code is complex and it&#x27;s nice to see the sequence more clearly.<p>What&#x27;s not so useful: mandatory comments. A public API should be thoroughly documented, but some shops insist on writing comments for every function in the code, even private ones and even if its purpose is so obvious that the comment just rephrases its name. This practice is not only a waste of time, but also insensitizes you about comments and teach you to ignore them.<p>Other wasteful comments are added by some tools. I hate the one that marks every loop wiht a &#x2F;&#x2F;for or &#x2F;&#x2F;try comment.
评论 #41510449 未加载
评论 #41514065 未加载
评论 #41509758 未加载
评论 #41510272 未加载
评论 #41512118 未加载
评论 #41512357 未加载
anotherevan8 个月前
I think the favourite type of comment I&#x27;ve ever left in my code follows this template:<p><pre><code> DEAR MAINTAINER: This code is the way it is because of &lt;reasons go here&gt;. Once you are done trying to &#x27;fix&#x27; this, and have realised what a terrible mistake that was, please increment the counter as a warning to the next person: total_hours_wasted_here = n </code></pre> I&#x27;m not the original author, but have gratefully used it once or twice, and been amused when there was a single line commit incrementing the counter.
评论 #41512420 未加载
ghewgill8 个月前
I agree that the title is ambiguous - it&#x27;s what piqued my interest to read the article in the first place. Personally I lean toward fewer comments overall - perhaps to a fault - but explanatory comments as shown in the article are absolutely valuable. It&#x27;s a good reminder to explain the whys and the why nots.<p>This especially applies to your own code that you write and still have to maintain 5, 10, 15 years later. Just the other day I was reviewing a coworker&#x27;s new code and thought &quot;why choose to do it this way?&quot; when the reason was 10 lines up where I did it the same way, 8 years ago. She was following the cardinal rule of maintenance - make the code look like the existing code.
评论 #41506122 未加载
Timwi8 个月前
This is just a special case of a broader, more general advice that I follow:<p>Comment on whatever would be surprising when you read the code.<p>When I write code, a voice in the back of my head constantly asks “will I understand this code later?”. (People who just instinctively answer ‘yes’ every time are arrogant and often wrong.) Whenever the answer is ‘not sure’, the next obvious question is “why not?”. Answering <i>that</i> question leads you directly to what you need to write in your comment.<p>Sometimes the answer is “because the reader of the code might wonder why I didn&#x27;t write it another way”, and that&#x27;s the special case this article covers. But sometimes the answer is “because it&#x27;s not obvious how it works or why it&#x27;s correct” and that clearly requires a different type of comment.
评论 #41510492 未加载
评论 #41513956 未加载
gregmac8 个月前
&gt; I see more people arguing that whys do not belong in comments either, that they can be embedded into LongFunctionNames or the names of test cases. Virtually all &quot;self-documenting&quot; codebases add documentation through the addition of identifiers.<p>Identifiers can go a _long_ way, but not _all_ the way. I personally am a fan of requiring documentation on any public methods or variables&#x2F;fields&#x2F;parameters (using jsdocs&#x2F;xmldoc&#x2F;etc). Having a good name for the method is important, but having to write a quick blurb about what it does helps to make it even clearer, and more importantly, points out obvious flaws:<p>* Often even the first sentence will cause you to realize there&#x27;s a better name for the method<p>* If you start using &quot;and&quot; in the description, it is a good indication that the method does too much and can be broken down in a more logical way<p>People often think properties are so clear they don&#x27;t need docs, then write things like:<p><pre><code> &#x2F;** The API key *&#x2F; string ApiKey; </code></pre> But there&#x27;s so much missing: where does this key come from? Is this only internal or is it passed from&#x2F;to external systems? Is this required, and can it be null or empty? Is there a maximum? What happens if a bad value (whatever that is) is used? Is there a spot in code or other docs where I could read more (or all these questions are already answered)?<p>This is stuff that as the original author of the code you know and can write in a minute or two, but as a newcomer -- whether modifying it, using it, or just parachuted in to fix a bug years later -- could take _hours_ to figure out.
JohnMakin8 个月前
I often write comments like this when I can predict what an overly nitpicky reviewer will say in a code review - &quot;I didn&#x27;t do X because Y&quot; hoping to save some annoying back and forth about it.
评论 #41505904 未加载
评论 #41505968 未加载
Terr_8 个月前
&gt; Does 16 passes over each string BUT there are only 25 math strings in the book so far and most are &lt;5 characters. So it&#x27;s still fast enough.<p>Another twist on this is to put in a debug logging statement which triggers when the inputs are much larger than the original design constraints.<p>It&#x27;s roughly the same message to a future-developer, but they might find it much sooner, short-circuiting even more diagnostic and debugging time.
评论 #41506164 未加载
评论 #41506199 未加载
ok_dad8 个月前
I personally don&#x27;t care what anyone says, I use comments and doc comments ALL OVER the place; I do it in reverse, though. I write a list of steps for the application as comments, a rough draft at first, then as I develop the code I take the big steps and split them into little steps, sometimes removing the original comment and sometimes not, and I continue to split comments into smaller steps until I have nearly a complete algorithm. Then I just code the logic in there. I normally will code from the outside in, so I&#x27;ll also be writing code as I do the comment-splitting stuff. Sometimes I get off on a tear and I code a bunch of stuff at once, but then later I go back and comment it down to a level that I think most of you would find annoying. Every function and variable has a comment about what it does, even the `deg_to_rad` function has a comment `&quot;&quot;&quot;Converts degrees to radians.&quot;&quot;&quot;`. Why not, storage is cheap!<p>I know most people don&#x27;t like it, and that is fine, they can deal with it! I they don&#x27;t want to see my comments, they can remove them from their version of my code with a script, and if my co-workers and boss don&#x27;t like them they can remove them in a code review! However, I can say that I enjoy reading my old code way more than I enjoy reading other&#x27;s code which have zero comments. I work in Python, so a lot of the simple non-algorithm code (boilerplate stuff for apps, like flask APIs for example) is mostly &quot;self-documenting&quot; since the old saying goes, &quot;write some pseudo-code and 95% of the time it runs in Python.&quot; The most important comments are sometimes on the boilerplate stuff because that&#x27;s where a lot of changes happen versus the algorithms where I find there is a lot more wholesale rewriting in my industry.<p>I will always love comments and doc comments!
评论 #41508070 未加载
评论 #41506247 未加载
评论 #41506176 未加载
评论 #41506455 未加载
评论 #41506502 未加载
评论 #41509093 未加载
评论 #41508673 未加载
评论 #41506659 未加载
jesse__8 个月前
I ascribe to the notion that &#x27;comments are apologies&#x27; (to my future self).<p>If a piece of code is weird, or slow, or you&#x27;d say &quot;yeah, it&#x27;s kinda janky&quot; when describing to somebody, I usually write a comment about it. Especially if I&#x27;ve changed it before; to document some case that didn&#x27;t work, or I fixed, or whatever.<p>When you operate on this basis, superfluous comments just melt away, and you typically end up documenting &#x27;why&#x27; only when it&#x27;s really necessary.<p>Try it out in your own codebase for a month and see how it feels :)
GuB-428 个月前
I&#x27;d say that it is one of the few cases where comments are the best solution.<p>You can&#x27;t have functional code for what isn&#x27;t done, so that&#x27;s some information you can&#x27;t express in code.<p>Furthermore, a major problem with comments is that you can&#x27;t debug or test them. There are many tools that can analyze code, static or runtime, but because comments are just free text, you can&#x27;t do much besides spellchecking. Also it is common to forget to update comments, and with the lack of testing, in the end, you get lies.<p>But here, the only maintenance these comment need is to remove them if they stop being relevant. For example because you finally did the thing you said you wouldn&#x27;t do, or just scrapped the part. Very low effort, also rather easy to spot, since if you see a thing being done with an explanation on why it is not done, it means someone forgot.<p>It is also worthwhile because as programs grow, they tend to do more, and &quot;not&quot; assumption may no longer hold (there used to be 4 parameters, now there are 10000...), meaning it is something you should check.<p>A lot of slow code comes from an assumption that N will be small, and N ends up being big. By the way, that&#x27;s why I favor using the lowest O(n) algorithm that is reasonable even if it is overkill and slower on small sets. Because one day, it may not be. If for some reason, using a low O(n) algorithm is problematic, for example because the code is too complex or the slowdown on smaller sets too great, then comes the &quot;why not&quot; comment.
评论 #41514067 未加载
评论 #41507043 未加载
breck8 个月前
I resisted putting comments in my languages for years. My reasoning was it was always a flaw of my code (or the language) if I couldn&#x27;t express myself in typed code.<p>Then I realized that my languages will never be perfect, and having comments is an essential escape hatch. I was wrong and I changed my mind.<p>Also, 99.9% of languages have comments:<p><a href="https:&#x2F;&#x2F;pldb.io&#x2F;blog&#x2F;a-language-without-comments.html" rel="nofollow">https:&#x2F;&#x2F;pldb.io&#x2F;blog&#x2F;a-language-without-comments.html</a>
golergka8 个月前
&gt; This is incredibly inefficient and I could instead do all 16 replacements in a single pass. But that would be a more complicated solution. So I did the simple way with a comment: &gt; Does 16 passes over each string &gt; BUT there are only 25 math strings in the book so far and most are &lt;5 characters. &gt; So it&#x27;s still fast enough.<p>I&#x27;ve been in this exact situation quite a few times — use a bad algorithm because your n is low. However, instead of commenting, I did something like this instead:<p><pre><code> function doStuff(items: Item[]) { if (items.length &gt; 50) { logger.warn(&quot;there&#x27;s too much stuff, this processing is O(n^2)!&quot;); } &#x2F;&#x2F; ... do stuff }</code></pre>
Wowfunhappy8 个月前
&gt; When I was first playing with this idea, someone told me that my negative comment isn&#x27;t necessary, just name the function RunFewerTimesSlowerAndSimplerAlgorithmAfterConsideringTradeOffs.<p>Wow, someone actually suggested that?! Do people write whole programs like this?
评论 #41509505 未加载
评论 #41506513 未加载
评论 #41508348 未加载
评论 #41506361 未加载
tombert8 个月前
My rule of thumb has been &quot;comment stuff that isn&#x27;t the naive solution&quot;, basically anything that would make someone think &quot;wtf is this&quot; the first time they read it.<p>My biggest headache right now has been getting high-throughput with SQL and as such I&#x27;ve had to do a lot of non-obvious things with batching and non-blocking IO in Java to get the performance I really need, and as such a of the &quot;obvious&quot; solutions don&#x27;t work (at least with a reasonable amount of memory). Consequently I&#x27;ve been pretty liberally commenting large segments of my code so that someone doesn&#x27;t come in and start bitching about how &quot;bad&quot; my code is [1], &quot;fix&quot; it, and then make everything worse by rewriting it in a more naive way that ends up not fulfilling the requirements.<p>[1] I have since stopped doing this, but I&#x27;m certainly guilty of doing this in the past.
pdpi8 个月前
I find myself following only two or three different patterns in comments:<p>There&#x27;s often a fairly small kernel of very dense code that abstracts away a bunch of complexity. That code tends to have well north of a 1:1 comment to code ratio, discussing invariants, expectations, which corner cases need special handling and which ones are solved through the overall structure, etc.<p>Then there&#x27;s a bunch of code that build on that kernel, that is as close to purely declarative as possible, and aims for that &quot;self-documenting code that requires no comments&quot; ideal.<p>Finally, there&#x27;s the business logic-y code that just can&#x27;t be meaningfully abstracted and is sometimes non-obvious. Comments here are much more erratic and often point at JIRA tickets, or other such things.
jakub_g8 个月前
Apart from what&#x2F;why&#x2F;why not: Something I started doing recently is to put URLs in the comments:<p>- URL of documentation for a complex feature<p>- URL with a dashboard with telemetry<p>- URL of a monitor which checks if the given feature, CI job, GitHub action etc. works correctly.<p>In a big project, figuring this stuff out is not trivial, requires a lot of searching with proper search terms and&#x2F;or asking the proper knowledgeable person.<p>I find it weird that code is often so detached from everything non-code.
评论 #41506570 未加载
analog318 个月前
One issue with comments is that an engineer who struggles to write clearly will also struggle to write clear comments. And clear code. But at least the code can be deciphered by reverse engineering it, stepping through it, or in some cases rewriting it. For me, at least the comments are worth reading before trying to figure out what someone&#x27;s code does, to get me into the ballpark.<p>I often add comments to code as I decipher it, then remove them again when I figure things out.
评论 #41509587 未加载
at_a_remove8 个月前
Although I had started programming when I was nine, in high school I was fortunate enough to have a computer science teacher with a PhD in the field. Among one of the habits drilled into me was extensive commenting.<p>Every function (or procedure) starts with a comment block. It first talks about the what and why. Then, a line for the inputs and another for the outputs. Next -- and this is done closer to the end of the writing -- I describe what it calls and what it is called by. The comment block optionally finishes with room for improvement.<p>The function itself probably has other comments. Usually for anything which is not <i>blindingly obvious</i>. Because I write code like a caveman, wherein only one thing happens on one line, most everything is quite clear. If there&#x27;s anything weird or magical that has to happen, it gets a comment.<p>Elegance and cleverness is reserved for data structures, algorithms, and so on, rather than doing a lot of stuff in as few lines as possible. I do this for Future Me, who might be having a bad day, or for anyone who wants to adapt my code to something else.<p>One of the last steps in a finished program is going through and making sure that my comments match my code. I am a very boring kind of programmer.
gary_08 个月前
The title might be clearer with a hyphen: &quot;Why-Not Comments&quot;.
kqr8 个月前
Another big one I wish I saw more often is &quot;these are the circumstances under which this assumption was made and here are the steps you can take to check if those circumstances have meaningfully changed.&quot;<p>In other words, the comment allows the author to reach into the future and co-debug with the reader, even if the author is no longer there.
AcerbicZero8 个月前
I have learned to enjoy narrating my struggles in the comments, probably to excess; but it certainly makes it much easier to pick up a task again after I leave it alone for a week or two.<p>People rarely touch what I write, but if they do, and they want to strip the comments out, thats totally fine with me, just don&#x27;t ask me how it works after you do :P
worik8 个月前
I have had the experience this year of working on a system with 150k lines of C ant 150k of Typescript. The gentleman who wrote it in 36 months quit and here I am.<p>He did not believe in comments, much. I think he thought he was commenting the hard stuff, mēh, I am unsure.<p>It has led me into strong opinions.<p>* Document every function. The function should make clear what the preconditions, preconditions, and the purpose are<p>* Docunebnt every file&#x2F;code unit. Why it exists<p>* Document important loops like functions<p>* Document the easy stuff. It is not easy if unfamiliar<p>* Review the comments when working on code<p>This would have saved my company about thirty percent of my time.<p>The compiler does not verify comments, like it does code, so it is a burden. Bad programmers get another opportunity to sow chaos, I know. But one of the main purposes of code is communication with following humans, as well as controlling machines<p>Careful and thoughtful comments are a professional obligation IMO
ufo8 个月前
When I see a sequence of string replacements, instead of performance the main thing I worry about is if the output of one replaces matches a pattern for another replacement. I see variations of this often during code review.<p>Doesn&#x27;t seem to be a problem here though because they&#x27;re replacing macros by symbols that are known ahead of time.
评论 #41506067 未加载
8organicbits8 个月前
Another approach is ADRs, which document alternatives considered, but these are documentation, not comments. I&#x27;ve found them useful for building consensus around architecture decisions.<p><a href="https:&#x2F;&#x2F;adr.github.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;adr.github.io&#x2F;</a>
kstrauser8 个月前
The title&#x27;s a little odd, unless it was to grab attention. It&#x27;s saying &quot;Why [I use] &#x27;not comments&#x27;&quot;, not asking &quot;why not comments?&quot; A &quot;not comment&quot; here is an explanation of why the programmer didn&#x27;t choose the obvious approach. I agree: that&#x27;s a very valuable thing to document for the next person.<p>For instance, you might write something like:<p><pre><code> # I used a bubble sort instead of a quick sort here because # the constraint above this guarantees there will never be # more than 5 items, so it&#x27;s faster to use the naive # algorithm than to implement a more complex algorithm that # involves more branching. </code></pre> or<p><pre><code> # Normally we&#x27;d do X, but that broke customer Y&#x27;s use case # based on their interpretation of our API docs which we # had kind of messed up. So now we do Y because it works # under both interpretations, at least until we can get # them to upgrade. </code></pre> Basically, tell your audience why you&#x27;re not using the expected method. It&#x27;s not because you didn&#x27;t know about it, but because you do know and you&#x27;ve determined that it&#x27;s not a good fit for this use case.
评论 #41506008 未加载
评论 #41506101 未加载
keybored8 个月前
You can still document the why in commit messages![1]<p>I feel like I’m getting off the self-documenting code ride. In our own codebase we rely way too much on “descriptive names”. Like full-on sentence-names. And is the code self-documenting? Often not. You indeed cannot describe three or more axes of concerns in one name.<p>Do comments go stale? Well why does it? Too loose code reviews? Pull requests that have fifty lines of diff noise that you glaze over? We have the tools to do better on that front than some years ago at least.<p>It’s a joy to find a corner of the code base where things are documented with regular sentences. Compared to having to puzzle through five function call layers.<p>[1] But yeah, really. But also: sometimes also in comments. Sometimes both.
评论 #41506290 未加载
评论 #41506107 未加载
spencerchubb8 个月前
My team comments way too much. I constantly see stuff like this<p>def fetch_data(comment_id):<p><pre><code> Args: - comment_id: The id of the comment to fetch. Returns: The comment data </code></pre> # Fetch comment data<p>data = fetchCommentData()
评论 #41512208 未加载
philipwhiuk8 个月前
Personally I think you&#x27;re better off putting &#x27;not comments&#x27; in git commit information. Git commit comments are like normal comments except they don&#x27;t get detached from the code.
评论 #41506591 未加载
obelos8 个月前
Do you really need to comment to yourself or anyone else that you did a thing the less efficient way because it was simpler? I guess I&quot;m not seeing the use. When later you&#x27;ve perturbed the criteria that caused that function&#x27;s inefficiency to be immaterial to overall performance needs and it suddenly becomes material, profiling is going to reveal the low-hanging fruit faster than digging through the code for a “this could be faster a different way” comments.
ktosobcy8 个月前
I somewhat dislike the notion of &quot;self-explanatory code&quot; (especially if someone has tendency to be &quot;smart&quot;)... optimise for reading and add comments!
mark-r8 个月前
I once wrote a bubble sort into production code, because the total number of elements to sort rarely exceeded 4 and it was what I could do off the top of my head. I don&#x27;t remember if I left a comment explaining the reasoning, but I think I did. A year later a new feature invalidated my assumption about the number of elements and the sort was way too slow. I&#x27;m sure the person who inherited that code cursed me a few times.
wwarner8 个月前
I would call this “defensive coding”, analogous to defensive driving. And comments that talk about something that isn’t there is way too defensive, kind of like the excessive braking and overly polite waving that can make 4 way stops so confusing. Write your code clearly, keep your functions wholly visible without scrolling, keep the comments to a minimum, and put the ideas that can’t be expressed as code in a README.
agentultra8 个月前
May also sometimes, when designing algorithms, be useful for documenting pre- and post-conditions and invariants in procedural languages that lack embedding such specifications. You can&#x27;t really reason about these things in the language itself and end up having to use something else (predicate calculus usually) but it&#x27;s nice to at least have an indicator, as tfa suggests! What code <i>doesn&#x27;t</i> do is important!
icambron8 个月前
The “why not” form just seems to be a special case of “explain why this code is weird”, which is my commenting metric in its entirety
slaymaker19078 个月前
&gt; In recent years I see more people arguing that whys do not belong in comments either, that they can be embedded into LongFunctionNames or the names of test cases.<p>Who is arguing this? Usually, if I&#x27;m adding a comment on why something is done a particular way, it&#x27;s something that is going to take at least a full sentence to explain if not a whole paragraph.
fennecbutt8 个月前
A lot of anti comment crowd are because &quot;good code should be understandable without comments&quot; which I think is just elitist snobbery.<p>Sure people can tell what the code is doing over a file but comments could definitely add a little more context of what the code is _for_.
dekervin8 个月前
I am working on the abandonned idea of a rapgenius for code. I think it still is a useful idea for the open source world. You can join the HN learn discord [1] if you want, so I can keep you posted.<p>[1] <a href="https:&#x2F;&#x2F;discord.gg&#x2F;ks4yfPgbyn" rel="nofollow">https:&#x2F;&#x2F;discord.gg&#x2F;ks4yfPgbyn</a>
flerchin8 个月前
Comments and docs are lies that I dearly love. I want and need them, but I never forget that they&#x27;re, at best, helpful lies. The code does exactly what&#x27;s written, the comments adhere more or less, sometimes.
remot_human8 个月前
Maybe what we need is a single vocabulary word that means “I’m doing something that won’t scale well to large inputs but is still worth writing for now” then you could name the function replaceEscapeCharsNewWord()
评论 #41505990 未加载
评论 #41506461 未加载
deodar8 个月前
There is no hope for the software industry to mature if we cannot agree on some basic coding practices. Like the judicious use of comments to improve maintainability.
k__8 个月前
Would be cool if literate programming caught on.<p>It seems only to be a thing with Jupyter notebooks, and even there it mostly describes the results and not the code.
yawnxyz8 个月前
in the age of AI and Cursor, I make my function name as expressive as I can, and I make sure to add a couple of lines of comments, either generated or manual.<p>It makes it way easier to send these into Claude (it seems, at least). I hope they introduce a semantic&#x2F;vibes search too as I can never remember what I name my classes and functions...
yodsanklai8 个月前
This seems a bit like a strawman argument. I don&#x27;t think anybody say that we should never use comments.<p>The problem with comments is that they can become stale, and it&#x27;s often possible to self-document or write simpler code that causes less surprise. But of course, it&#x27;s totally fine to put comments.<p>And I think comments should be mandatory for interfaces functions&#x2F;types unless their behavior is obvious. I don&#x27;t want to read the code to understand what a function does, or what invariant a class maintains. And if it&#x27;s too complex to document in a few lines, probably this isn&#x27;t the right interface. But apparently, this isn&#x27;t obvious for everybody. In my company, most of the code isn&#x27;t documented.
matt_lee8 个月前
&gt; Why not &quot;why not&quot; comments? Not why &quot;not comments&quot;<p>I nearly exploded trying to grok this
评论 #41506745 未加载
W0lf8 个月前
My rule of thumb for code comments is to comment what&#x27;s not in the code.
mentalgear8 个月前
An article not not to overlook.
评论 #41509714 未加载
pwdisswordfishz8 个月前
&gt; Why not &quot;why not&quot; comments? Not why &quot;not comments&quot;<p>Or you know, you could have just used a hyphen instead of clickbaiting.
boerseth8 个月前
&gt;The negative comment tells me that I knew this was slow code, looked into the alternatives, and decided against optimizing.<p>I admire the honesty, but will continue to phrase these <i>&quot;why not&quot;</i> comments as insincere TODOs.
veltas8 个月前
Why not question-mark?
zwnow8 个月前
Comments tend to get outdated quickly as your app grows. If you are not careful with your phrasing you might even introduce misinformation into your app. I&#x27;d rather read the code instead of comments.
评论 #41508660 未加载
aurelien8 个月前
BBBbbbbeeeeccccaaausssseeeeEEEE!!!!
jerhewet8 个月前
Comments should never be &quot;what&quot;. They should always be &quot;why&quot;.
评论 #41506239 未加载
评论 #41506219 未加载
kazinator8 个月前
Most comments belong in the git log message. That&#x27;s where you want to discuss the &quot;why not&quot;. You have all the space you need in order to do that, without cluttering the code. The log message will accurately pertain to the change made at that time.<p>When commits are rebased, the log message must be revisited and revised. Changes can disappear on rebasing; e.g. when a change goes into a baseline in which someone else made some of the exact same changes in an earlier commit, so that the delta to the new parent is a smaller patch. In my experience, commit messages stay relevant under most rebasing.<p>Comments are (largely) an obsolete version of version control log messages.<p>In the 1980s, there was a transitional practice: write log messages, but interpolate them into the checked out code with the RCS $Log$ thing. This was horrible; it practically begs for merge conflicts. It was understandable why; version control systems were not ubiquitous, let alone decentralized. You were not getting anyone&#x27;s RCS &quot;,v&quot; file or whatever.<p>Today, we would be a few decades past all that now. No $Log$ and few comments.<p>Mainly, the comments that make sense today are ones which drive automatic API documentation. It would not be reasonable to reconstruct that out of the git history. These API comments must be carefully structured so the documentation system can parse them, and must be rigorously maintained up-to-date when the API changes.
评论 #41514173 未加载