- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
"Or gasp you could use a comment! Then you can remove the assumption that the moron who will be reading/maintaining your code will see the "obvious".
final long ms = 300000; /* 5 minutes worth of milliseconds */"
Now try adding 1 minute to that and to
"final long ms = 5 * 60 * 1000;"
This isn't about some idiots not able to calculate one minute in milliseconds, this is about clearness and simpleness. After changing this value a few times I'd probably write "final long ms = (5 * 60 * 1000)+(0*1000);" so you can easily add seconds ^^
Second point is if you have to comment that line you'd simply write /(minutes)+(seconds)/ and never change that again. If someone ever fiddles with the value and changes 300000 to something else forgetting to change the comment as well you could end up with a hard to spot bug....
Admin
But, it takes longer to write a comment than to simply make the code make sense.
Admin
It must have something to do with ASCII: patno -= 'Y'//(ASCII CODE 89) //Y? WHY? WHY!?!?!
Admin
or even better
final long ms = 5 * 60 * 1000; /* 5 minutes worth of milliseconds */
Admin
Because magic numbers and comments never become out of sync over time.