6 ms·
Auto-expiring TODO notes in Ruby
- y14 12y agoThis is excellent. I always fail to keep track on my TODOS in files. Very useful.
- skrebbel 12y agoUse a decent editor.
- middus 12y agoAlternatively, you could continue using your editor of choice for editing and use grep to identify TODOs in your code.
- watwut 12y agoMy TODO comments show up in nice view in GUI I use (Eclipse). I'm sure other GUIs have similar views somewhere. I'm also sure that plugin to turn old ones into syntax errors could be done in a day or two. That sound like much safer approach then runtime exception.
- aaronem 12y agoA day or two, really? That seems like an awfully long time requirement for what should be a simple change.
- recursive 12y agoIf you're experienced making Eclipse plugins, it would probably be under an hour. If you're not, it could take you a day to learn how.
- watwut 12y agoI'm sure it is a simple change. The hard part is to find out where exactly should you do that simple change and how exactly should you do it. If you do not have experience with related APIs, you will need a day for googling and reading. Eclipse framework is huge and not all its parts are immediately understandable.
- froh42 12y agoDon't do that. Some years ago I had the same idea and realized something like that with the C-Preprocessor in a C++-Codebase. When did my Todo's expire? AFTER testing, just before a new release. With my idea of exipiring Todos I created a major pain in the butt for the team. It would be different if some other "sort of" alarm would be raised when TODOs proliferate, but a failure in the code is not a good solution. (i.e. hook a todo checker into your contious build system, let the nightly build raise hell when there are too many todos - but do not fail the production code.)
- dtech 12y agoWouldn't this be much more suitable to do in an IDE or compiler? Raising exceptions during runtime seems the wrong approach to me. I wouldn't be suprised if this is possible and used in e.g. Mylyn. Another idea would be to automatically create a task/bug/issue for every TODO created (which closes when the TODO is removed)
- theforgottenone 12y agoor an IDE that just scans the code files, picks out the lines of comments containing "TODO" and put them in a list in the gui, so you see it all the time. Or generate a compile warning instead of a comment. Then it will annoy you constantly, with no risk to production.
- sootzoo 12y agoI think he makes the case (and I agree) that if you create a substantial number of TODOs and they manifest as IDE/compile-time warnings, they eventually become noise which you learn to ignore instead of fix.
- deleted 12y ago[deleted]
- tekacs 12y agoMight it not make sense to invert the parity of the environment variable and require its being set for do_by to be used? I imagine most would rather set an environment variable in their dev environment than ensure it gets set in every possible production instance... :/ As much as 'turning off asserts' is the classical style, that's more to do with the design of older instrumentation than the sanity of it.
- peteretep 12y agoBetter to make it a NOOP and have an automated test that scans for it. Too much chance of exercising it in production otherwise.
- TazeTSchnitzel 12y agoWhy a function? I hoped it would just parse comments.
- michaelmior 12y agoLikewise. I think I'd rather have this as part of the build process. This would also make it easier to have a tool which works across languages.
- andywaite 12y agoI think that's a good idea. Perhaps based on a standard format such as '# TODO 2014-01-01 Fix me' ?
- Ruud-v-A 12y agoWhy put the date in the comment itself? Just ask source control when the line was introduced, and set a max age.
- andywaite 12y agoInteresting idea, but I'm not sure if that would be possible for all cases, for example what happens if the part of the line before the comment changed?
- dbuxton 12y agoFantastic idea and what I thought when I saw this post; I'm slightly surprised that nobody has produced a git one-liner to achieve this yet!
- skrebbel 12y agoLovely language / solution mismatch. Any compiled language would fit this much better - fail at compile time. Or in interpreted-o-world, at least do it at test time. I guess it's just lovely when deployed, working, test-passing software suddenly starts failing on a server (all servers at once, globally), because someone added a TODO a few weeks ago.
- jerf 12y agoFrom the README: "In your production environment, set DISABLE_DO_BY=1 to disable checks."
- theforgottenone 12y agoGiven that we are talking about lazy/overworked on top of lazy/overworked here, why any confidence that this will be done 100% of the time? Putting time bombs in your code, regardless of a global configuration switch, is just asking for trouble.
- andywaite 12y agoYou're correct, I'm going to change it to be disabled by default.
- jerf 12y agoI agree with you; my point was that while skrebbel spoke as if the point had never even been considered, it had in fact been considered. I have to admit to a certain amount of pet-peeve-like sensitivity to people commenting in ways that make it look like they only read the title.
- theforgottenone 12y agoI am guilty of this more often than I care to admit. Ooops.
- iirving 12y agoSo there may not be much awareness so this, but <strike>Ruby</strike> Rails (as noted below, the annotations or part of rails/rake) has this feature that you can add special annotations # TODO # FIXME # OPTIMIZE comments to you code, and "$ rake notes" to list them. it also allows you to have a custom annotations comments : For a full description, see : http://rubyquicktips.com/post/385665023/fixme-todo-and-optimize-code-comments http://rubyquicktips.com/post/385665023/fixme-todo-and-optim... Better to make a # DOBY annotation and modify the rake task to shame if the date passed. You could also add this metadata to the existing annotations. If you what to automate the shaming, write a guard gem to watch for these annotations.
- e28eta 12y agoI like it. It reminds me of a concept [1] I saw presented at Fluent Conf this year, called Sunset Tests. The idea is that when you write code which shouldn't be a permanent addition to the code base (for example, a poly fill for IE 7, or an A/B test), write a test that checks for the existence of that code and fails if it's still there past a certain date. I wonder if the TODO method could dynamically generate a test case that does the same. [1] Everything is a Polyfill: Automate Deleting Code for Front End Performance - Rachel Myers and Emily Nakashima http://www.slideshare.net/eanakashima/everything-is-a-polyfill-33857559 http://www.slideshare.net/eanakashima/everything-is-a-polyfi...
- kyberias 12y agoSilly. I fail to understand how the developer getting the surprising out-of-context (with regard to what the developer is currently doing) build failure due to time-bomb-TODO-comments suddenly is expected to experience an energy burst and fix the issue right then and there. After all, the developer didn't fix the issue when the comment was written! I think this just leads the developer to either a) delete the comment or b) increase the due date.
- sctb 12y agoAfter reading the title, I actually expected the code would do the opposite: remove the TODO because nobody found it to be the right time to address it over the specified period and they probably never will.
- andywaite 12y agoDevelopers often add TODOs for tasks that seem essential at the time, but later become redundant. There is also the use case of when you can't do something because you're dependent on something else, for example you might have a workaround due to a issue in one of your dependencies. Once that's resolves, you can update to the newer version of that library, and remove your workaround.
- grrowl 12y agoI'd see this with more value as a post-commit git hook. After a certain amount of time (or date specified) it would warn you that TODOs are about to expire, and either remove them or update the date. That way it can be project-wide and doesn't require execution.
- ansimionescu 12y agoI started doing something much simpler: When working on a project I just create .todo files anywhere it makes sense. This way I can view, edit, add, and remove them very easily with simple shell commands. I just enjoy the simplicity of `echo 'remember to test the milk' >> foo/.todo`.
- Argorak 12y agoI like your example. Especially because milk expires ;).
- mkal_tsr 12y agoHorrible implementation approach. Mixing runtime exceptions with project management that you're not guaranteed to hit while testing? lol. A pre-commit hook is the way to go, * Post-commit: You'll always catch the exception, but you'll be able to commit expired TODOs * Pre-commit: you'll have to explicitly change the expired TODOs either by removing them (irrelevant TODO, todo became todone through a refactor, etc.), or discussing a better end-date ... but either way, you're forced to address the expired TODO and not run the risk of committing expired TODOs nor not taking a test path that would miss the expired TODO exception