News for hackers. Stuff that matters.
Re:The Linux codebase has over 3k TODO comments, many from o... by jbaudanza on Sunday December 29, 2019 @10:01PM (#21910445)
I use TODO in my code all the time as shorthand for: "This code is functional, but if you are going to do another iteration you may want to consider the following improvement or optimization."

It's not at all meant to be to be like an item in a TODO list. Code would be a terrible place to keep that.

Re:The Linux codebase has over 3k TODO comments, many from o... by mewse on Monday December 30, 2019 @01:00AM (#21911155)
The lead programmer at my very first coding job taught me to put a string of at least three hash marks in a comment, to denote “this is a thing which is okay during development but absolutely must be changed/fixed before shipping this product”.

The more essential the change/fix, the more hashes. Made it really easy to do a global search for them, and you could easily filter the results to only show the most important ones by searching for longer strings of hashes.

Twenty years later and I’m still doing that in my personal projects.

Re:The Linux codebase has over 3k TODO comments, many from o... by Jach on Monday December 30, 2019 @01:25AM (#21911244)
At my work we just file a bug and make sure it gets prioritized as a must-fix... The code might contain a bug number and remark too for redundancy, but the bug itself generally spells out the bits of code that need to be changed/removed/whatever.

Using code comments really seems like the wrong place to prioritize changes. Even on personal projects.

Re:The Linux codebase has over 3k TODO comments, many from o... by shhsshs on Monday December 30, 2019 @01:44AM (#21911319)
I agree in principal, though if the intent is to have the minimal amount of side-tracking while marking something as TODO for the future, I don’t think you can get better than a comment.

A nice cli interface for creating tickets in GitHub/Jira/etc. would help with that. I wonder, would it be nice to have a pre-commit hook that scans for TODO comments, removes them, and drafts tickets? Then both flows would work well.

Re:The Linux codebase has over 3k TODO comments, many from o... by Jach on Monday December 30, 2019 @03:23AM (#21911687)
I suppose it depends on how far you trust your ability to keep everything in your head, and reload everything coming back, and follow through on notes to self. I make todos too, but I try to honor a self-agreement that they be short lived and ideally not make it very far beyond my machine.

I linked https://github.com/dspinellis/git-issue in another comment but it gives a sense of the command line experience. I've also at times hacked up various scripts to create or modify items in github/jira/our internal POS, it can make things more likely to hit the tracker than to be met with a shrug. (It's so odd how sensitive programmers can be to even minor blocks in flow like a few seconds waiting for a webpage, or avoiding refactoring a method / class because in Java a new method might best belong to a new class which to do things 'proper' often entails a new file and then another new file for unit tests, adding them to version control, and all that takes like 30 seconds even with IDE support and is annoying.) I've at times thought about a small vim command that would call one of those scripts to create a new issue pre-templated with the file and location I was on, create, then insert the work item id, but never got around to it. As a pre-commit hook something to look for TODOs explicitly might be interesting, though I generally dislike hooks.

Re:The Linux codebase has over 3k TODO comments, many from o... by gumulka on Monday December 30, 2019 @08:23AM (#21913162)
I have somethink like this in the pre-commit script: https://pastebin.com/XmMHTvZR

It works only for gitlab and assumes that the remote is named origin.

This will create an issue with the title text being everything after TODO. It does not support multiline and only looks at the newly added lines, but does not remove from the commit or alters them.

Re:The Linux codebase has over 3k TODO comments, many from o... by girvo on Monday December 30, 2019 @01:33AM (#21911277)
I don't really want to use a bug tracking system on my personal projects, though, so I can see why someone would choose to do the TODO or hash idea
Re:The Linux codebase has over 3k TODO comments, many from o... by imtringued on Monday December 30, 2019 @12:16PM (#21914919)
If I don't write down everything I will forget what I am working on. Personal projects often get delayed by random things because they don't have a fixed schedule. After a while I forget what I am supposed to work on. What I do instead is I just write an issue with nothing more than a single sentence (often just a title with no body). If a new contributor wants to work on the project then they can use that issue as a starting point to join the project and ask for clarification how I want to it to be implemented.

I personally wanted to contribute to a few projects but it was difficult to track what is currently being worked on or what needs to be done. When an opensource developer only works 8 hours a week on a project you don't want to waste their limited time by having a dozen people ask them what needs to be done and then not doing anything (because a feature might not be relevant to you but you couldn't have known that because it wasn't written down).

Re:The Linux codebase has over 3k TODO comments, many from o... by dragonwriter on Monday December 30, 2019 @08:34PM (#21918282)
> Using code comments really seems like the wrong place to prioritize changes.

It's a poor place for long-term tracking, but it's a great place for recording notes while minimizing context-switching cost while coding.

Re:The Linux codebase has over 3k TODO comments, many from o... by mytailorisrich on Monday December 30, 2019 @02:22AM (#21911455)
> “this is a thing which is okay during development but absolutely must be changed/fixed before shipping this product”.

These should not reach the master codebase and should thus be fixed before you merge your code into it.

Re:The Linux codebase has over 3k TODO comments, many from o... by alkonaut on Monday December 30, 2019 @03:00AM (#21911605)
I think if multiple people are working on a code base which will not ship for years, then having those can be acceptable.

Obviously if “next release” is a deploy from master in 2 weeks then it isn’t.

Re:The Linux codebase has over 3k TODO comments, many from o... by mytailorisrich on Monday December 30, 2019 @03:12AM (#21911646)
It does not make it acceptable, quite the opposite as there would actually be less time pressure to ship code. What you describe would lead to an accumulation of issues over time that will degrade the codebase until it ships and then makes maintenance a nightmare.
Re:The Linux codebase has over 3k TODO comments, many from o... by alkonaut on Monday December 30, 2019 @04:15AM (#21911996)
A code base that will ship in 2 years will be shipping for various non-production reasons until then. There will be stakeholder demonstrations and alpha releases and things where the code must be functional (runnable), but it may not be production ready in terms of completeness, security etc.

The "accumulation of issues" is there regardless. Leaving TODO's isn't cutting corners or accumulating technical debt. It's simply something that is still to do. Any project will have an issue management system with outstanding issues, but a note in the code is worth more than a thousand words in an issue. "TODO: here is where the validation of parameters must be done, see issue #123". or "TODO: enable right-to-left in these two textboxes when right-to-left text input is added, see issue #234".

There is no value in keeping a main branch "clean" from TODO comments because it's somehow more hygienic. The code needs to be runnable at all times, even with incomplete features. Reaching zero TODO's before a product ships is a matter of grepping for the strings.

Re:The Linux codebase has over 3k TODO comments, many from o... by mannykannot on Monday December 30, 2019 @09:49AM (#21913630)
The situation you have described, with there being versions of the code that must not go live, is precisely what branches are for, and branching is cheap. Whether you should consider the particular branch named 'master' to be special in any way, is largely a matter of preference, though if you end up with a mature product, it is quite possible that you will want to be able to cut a release from more than one branch.
Re:The Linux codebase has over 3k TODO comments, many from o... by alkonaut on Monday December 30, 2019 @10:17AM (#21913816)
Absolutely you can either designate an unstable “develop” branch and do stakeholder demos from there while keeping master clean, or you can develop on master and ship from stabilization branches. You can have any number of branches and assign any level of quality and polices to each. But you can’t avoid TODOs entirely by keeping them only on feature branches as what you’ll need is a branch with all features integrated but not necessarily shippable.

If you do stakeholder demonstration from an integrated “develop” branch and ship from master, you can have a policy of “no TODOs in master” meaning you won’t ship the TODOs. I’m not saying one must have TODOs ever in the branch-that-will-be-released but that they can be very useful and almost unavoidable to have in some integrated branch, because you may need to show a product without it necessarily being ready. Exactly what quality gates you ship with is a preference, for example specific comment tags (PERF, FIXME, TODO, ...). These are just words. In my codebase TODO means "this works but isn't optimal, so should be revisited IF the code ever has a reason for change". In other codebases it might mean "This is utterly broken and can't be shipped". Whether shipping is acceptable of course depends on which of those interpretations one uses (And using both would be a process error).

Re:The Linux codebase has over 3k TODO comments, many from o... by mytailorisrich on Monday December 30, 2019 @04:25AM (#21912059)
You seem to have somewhat diverged from my point, which was a reply to this statement:

> “this is a thing which is okay during development but absolutely must be changed/fixed before shipping this product”.

There is no valid reason to submit effectively defective code to the main branch. There is a major difference between incomplete functionality, which obviously is what the codebase contains during development, and defective or sub-standard implementation.

As an example (and from one of your examples), leaving validation of inputs "for later" is a sure way of shipping code that does not validate inputs and, again, there is no reason not to properly implement this from the get-go.

This sort of issues only accumulate if you let them by cutting corners.

Real-life example: I saw things like "TODO: Check for null pointers" in code. This should be rejected outright during code review. If you should check for null pointers, then do check for null pointers.

Re:The Linux codebase has over 3k TODO comments, many from o... by alkonaut on Monday December 30, 2019 @04:47AM (#21912186)
Validation may not be possible (Because it requires an external service for example, or validation rules may not even be decided. For example. I suspect that many MVP demos have a login/signup, which might validate the email. I also suspect that e.g. minimum password rules are enforced, it's usually done much later).

But yes I agree it's a poor example if it's possible to do right away it must be done right away. But I think you get my point. RTL-input may be the better example: it's a nice-to-have for some people, probably not part of an MVP but still a likely part of what some stakeholder calls critical functionality if you support RTL input locales.

My point is that while you may be able to categorize some things as "critical" or "important" (i.e. things one can argue should not reach the mainline even during development) there will always be a gray areas where you can't complete the development, but should still have a functioning app in some sense.

Re:The Linux codebase has over 3k TODO comments, many from o... by rurban on Monday December 30, 2019 @02:06AM (#21911403)
This should be marked as FIXME, not some management savy ###
Re:The Linux codebase has over 3k TODO comments, many from o... by coldtea on Monday December 30, 2019 @04:11AM (#21911969)
Neither FIXME nor ### are "standards" so the distinction is moot. Can use either...
Re:The Linux codebase has over 3k TODO comments, many from o... by hutzlibu on Monday December 30, 2019 @03:10AM (#21911640)
Why?

I also use ###. It is just a different style.

Re:The Linux codebase has over 3k TODO comments, many from o... by kanox on Sunday December 29, 2019 @11:23PM (#21910792)
> This code is functional, but if you are going to do another iteration you may want to consider the following improvement or optimization.

I assign the same meaning to TODO or FIXME markers but a lot of people see this is as a measure of poor quality so instead I write regular comments of the form "this could be made better by doing X and Y".

Re:The Linux codebase has over 3k TODO comments, many from o... by somehnguy on Monday December 30, 2019 @12:06AM (#21910947)
That may work but I find those comments tend to get lost over time. TODO/XXX/FIXME support are built into IntelliJ which makes stuff like that super easy to find. If some random dev looks and decides its low quality because of those words...well I don't care because its a silly metric to judge on.
Re:The Linux codebase has over 3k TODO comments, many from o... by TeMPOraL on Monday December 30, 2019 @02:15AM (#21911432)
And even if they aren't supported by default in your IDE/editor, they're perfect hooks for recursive grep. A simple

  grep -rn TODO *
and you see a nice list of all of them, with files and lines.
Re:The Linux codebase has over 3k TODO comments, many from o... by kanox on Monday December 30, 2019 @04:01AM (#21911908)
> those comments tend to get lost over time

That's fine, they don't need to be tracked. There are other systems for issues that need tracking.

Re:The Linux codebase has over 3k TODO comments, many from o... by delusional on Monday December 30, 2019 @02:38AM (#21911522)
Intellj also supports custom "patterns".

"Intellj supports it" is a pretty meaningless argument anyway.

Re:The Linux codebase has over 3k TODO comments, many from o... by Fiaxhs on Sunday December 29, 2019 @10:06PM (#21910468)
Correct me if I'm wrong but I use "FIXME" for this intent. I keep TODO for stuff actually left to implement.
Re:The Linux codebase has over 3k TODO comments, many from o... by BurningFrog on Sunday December 29, 2019 @10:15PM (#21910520)
To me, FIX implies that something is wrong, not that it works but could use improvement.

I would like to have a tag for "here's something that works, but could be improved" though!

Re:The Linux codebase has over 3k TODO comments, many from o... by sombremesa on Sunday December 29, 2019 @10:25PM (#21910578)
Pray tell, what line would you NOT put that tag on? That's like, all code...
Re:The Linux codebase has over 3k TODO comments, many from o... by kadoban on Sunday December 29, 2019 @10:35PM (#21910617)
TODO is for when you know something specific that can be improved and want to document it, not just generally that nothing is perfect.
Re:The Linux codebase has over 3k TODO comments, many from o... by saagarjha on Sunday December 29, 2019 @11:11PM (#21910748)
I occasionally get to write code that is as good as I think it can be. That doesn’t mean it’s perfect, but I don’t know how to improve it.
Re:The Linux codebase has over 3k TODO comments, many from o... by cgag on Monday December 30, 2019 @02:16AM (#21911437)
Something I've seen Jonathan Blow do that I like is tag things // @Speed when doing a quick to type but slow to run kind of first pass.

It seems nice to have tags for places to jump where the improvements are obvious, rather than hoping to just remember/spot them later.

Re:The Linux codebase has over 3k TODO comments, many from o... by hawkice on Sunday December 29, 2019 @10:35PM (#21910616)
I think we all occasionally write code we like, but I also write code I don't like, but only the most vague idea on how to improve.
Re:The Linux codebase has over 3k TODO comments, many from o... by BurningFrog on Sunday December 29, 2019 @10:44PM (#21910655)
I don't want to brag about my skills, so I won't answer that.
Re:The Linux codebase has over 3k TODO comments, many from o... by davidlinc1 on Sunday December 29, 2019 @11:23PM (#21910793)
I similarly don't want to brag about my skills in pointing out areas of improvement in code that others might think is optimal, so I won't answer that.
Re:The Linux codebase has over 3k TODO comments, many from o... by Hurtak on Monday December 30, 2019 @04:53AM (#21912213)
Isn't that what NOTE is for? The code is fine for now, but here are some constrains/limitations/implementation details that you should know when you want to touch that par of the code.
Re:The Linux codebase has over 3k TODO comments, many from o... by kjs3 on Sunday December 29, 2019 @10:11PM (#21910497)
That seems like a good compromise. I've used LOOKAT to note places where I got things going but felt like there was a better way of doing things if I had more time.
Re:The Linux codebase has over 3k TODO comments, many from o... by yoloClin on Sunday December 29, 2019 @11:23PM (#21910787)
Is there a standard for valid flags? I recently recommended a client use `TODOSECURITY` for todos which had security implications until fixed - I discovered functionality which was implemented before authorisation had been developed, resulting in a codepath which was unintentionally reachable by standard users.

Seemed weird to make up a codeword but I wasn't aware of any standard convention, and visually highlighting high impact issues (w/ the bonus of greppability) seemed like a sane approach in rapid development environments.

Re:The Linux codebase has over 3k TODO comments, many from o... by james_s_tayler on Monday December 30, 2019 @12:00AM (#21910926)
Open a ticket for that straight away and start working on it immediately. Or 3 years later. Whichever actually happens.
Re:The Linux codebase has over 3k TODO comments, many from o... by yoloClin on Friday January 03, 2020 @10:43PM (#21952733)
Yeah, that's probably true. I don't have any visibility over that particular projects ticketing system but I imagine it was never raised given it wasn't fixed until I noticed it.
Re:The Linux codebase has over 3k TODO comments, many from o... by sophiebits on Monday December 30, 2019 @12:37AM (#21911061)
I’d strongly recommend not landing code that has known security problems.
Re:The Linux codebase has over 3k TODO comments, many from o... by yoloClin on Friday January 03, 2020 @10:45PM (#21952741)
It was my job to look for security problems.
Re:The Linux codebase has over 3k TODO comments, many from o... by rkagerer on Monday December 30, 2019 @12:08AM (#21910953)
For small projects without issue tracking, I use TODO for this iteration (or soonafter), and WISHLIST for "would be nice" future optimizations.
Re:The Linux codebase has over 3k TODO comments, many from o... by Jach on Monday December 30, 2019 @01:33AM (#21911278)
Might I suggest you give a chance to having separate TODO and WISHLIST and TASKS text files in the root folder that use whatever id scheme you like and point to the code, with the code referring back to those ids only rarely? Or even a single file with sections for those things and more, perhaps called PLAN? Keeping things separate keeps the code tidier, gives you license to put more details than you're likely to put in a one or two line comment, lets you refer to multiple code points instead of the local comment area, can be given to a high school student temp worker, and so forth.

For personal projects I've used https://github.com/dspinellis/git-issue a few times for a local command line issue tracker, it's not bad. I've got a longstanding mental TODO to try out Fossil one of these days though with all that and more integrated...

Re:The Linux codebase has over 3k TODO comments, many from o... by ddyevf635372 on Sunday December 29, 2019 @11:55PM (#21910908)
Use IMPROVEME instead of FIXME ;)
Re:The Linux codebase has over 3k TODO comments, many from o... by dudus on Monday December 30, 2019 @12:25AM (#21911013)
TODO, FIXME and XXX are built into tools already. Sure you can make new stuff up but it makes it harder to find later.
Re:The Linux codebase has over 3k TODO comments, many from o... by ygra on Monday December 30, 2019 @02:08AM (#21911415)
Those things are configurable, though, so new markers are rarely problematic from a tooling perspective. Getting your teammates to agree on using the same markers is perhaps the bigger problem.
Re:The Linux codebase has over 3k TODO comments, many from o... by dudus on Monday December 30, 2019 @09:38AM (#21913576)
Making them agree is not necessarily the hardest. But remembering to tell new team members in a year or two. Or revisiting the codebase in 5 years from now. I doubt you'll remember
Re:The Linux codebase has over 3k TODO comments, many from o... by gwbas1c on Monday December 30, 2019 @09:49AM (#21913634)
I think TODOs are fine for small projects, or early code.

HOWEVER: For a mature project, TODOs should be found and reviewed during the pull request. Either they should be fixed prior to merge, or a ticket should be filed. (With a link placed in the TODO comment.)

In the rare case that a TODO remains without a ticket, it really should be something obscure that really doesn't need to be fixed. For example, TODOs are great for micro-optimizations or suggestions for long-term refactoring.

Re:The Linux codebase has over 3k TODO comments, many from o... by sedatk on Sunday December 29, 2019 @10:50PM (#21910684)
Then write a regular comment, why use TODO at all?
Re:The Linux codebase has over 3k TODO comments, many from o... by berkut on Sunday December 29, 2019 @11:02PM (#21910719)
So that it's grep-able?
Re:The Linux codebase has over 3k TODO comments, many from o... by catalogia on Sunday December 29, 2019 @11:06PM (#21910728)
It's also nice to highlight TODO and FIXME in your text editor for added emphasis. I believe Vim even does this by default.
Re:The Linux codebase has over 3k TODO comments, many from o... by nkozyra on Sunday December 29, 2019 @11:12PM (#21910751)
I think this is the primary benefit.

Only so many times can you scroll past a nagging ide hint before you say "FINE, I guess I'll do it now!"

Re:The Linux codebase has over 3k TODO comments, many from o... by sedatk on Monday December 30, 2019 @02:03AM (#21911387)
Why would you grep in a scenario where a note is written because "[the]... code is functional, but if you are going to do another iteration you may want to consider the following improvement or optimization.". It's exactly meant for when you encounter it, it's not meant to be found externally.
Re:The Linux codebase has over 3k TODO comments, many from o... by TeMPOraL on Monday December 30, 2019 @02:18AM (#21911445)
Because it's trivial to add special highlighting to such notes in most editors and IDEs. Hell, a lot of them come with a configurable list of these comment keywords already built in.
Re:The Linux codebase has over 3k TODO comments, many from o... by alpaca128 on Monday December 30, 2019 @07:22AM (#21912834)
Why would you intentionally leave out a TODO tag to make it harder to find?

Lowering the barrier to see such comments increases the chances of people actually handling them. Having a highlighted TODO in the code makes it much more visible even if you don't use grep.

Re:The Linux codebase has over 3k TODO comments, many from o... by Fakira on Sunday December 29, 2019 @11:15PM (#21910761)
TODO, as the name implies, should be things that must be done. Anything aspirational could be left as a mere ordinary comment.

Personally I hate TODOs and only see them as temporary things to act as placeholders for the correct code. At some point, I will go through all todos and clear them.

Re:The Linux codebase has over 3k TODO comments, many from o... by kanox on Sunday December 29, 2019 @11:25PM (#21910803)
> TODO, as the name implies, should be things that must be done.

A lot of people use them for things that "could" be done.

Re:The Linux codebase has over 3k TODO comments, many from o... by nosianu on Monday December 30, 2019 @05:42AM (#21912440)
Also, there are things that "must be done" only if the code is extended but it may be perfectly fine as it is at the current state. So I add a TODO when I see that there will probably be the need for refactoring in the intermediate future, but there is no need in the current code base. That is a TODO that is triggered (to become a "true TODO") when that code is touched again, but it remains (justifiably) inactive for now.

The reason I use not just a comment is what others here already said, it gets highlighted by the IDE, and I have too many other "gray" comments that would not get read unless someone is looking at those sections specifically, so another regular comment would be easily overlooked. The suggestion for external tools or files is even worse: Pretty much nobody will check them when it's time for refactoring. It has to be inline. Sure, it can't become too much, but one such "triggerable TODO" comment for just a few modules is fine.

When I write the code I can often already see options to make it more scalable or generalizable, but as it is currently being use the additional cost is not worth it, and if there never is future expansion the code actually is fine as it is. When I already know what needs to be done because my brain is fully 'inside' this code it would be a waste to throw that knowledge away, and regain all the contextual knowledge and ideas with a lot of work a year later. Those are the cases when I add such comments. They are not necessarily "TODO" level at that point, I use that tag only when additional conditions are met and I'm sure I want to avoid missing the comment.

Occasionally, when I have some time over, I scan through my TODOs, there are about 2/1000 LoC. Most of them I leave alone because the condition for their realization has not been met yet, but sometimes I find one of them is worth doing at that point. If it was a general comment I would have no chance to find them that easily. If they were in an external tool or file they would deviate from the actual code more and more, since we do quite a bit of refactoring due to growth and changing needs. But if there's a highlighted TODO in a module you are refactoring it's impossible to miss, so it is easy to update or remove those if they become invalid, even more so than regular "gray" comments.

Re:The Linux codebase has over 3k TODO comments, many from o... by cmyr on Monday December 30, 2019 @12:13AM (#21910967)
yep, TODO is for things like possible optimizations or improvements that are known, and FIXME is for things that are... functioning, but incorrect by some reasonable definition. (YMMV)