- 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
It doesn't help that the indentation is reminiscent of FORTRAN.
Admin
for (DateTime procDate = settings.BeginDate; procDate <= settings.EndDate; procDate = procDate.AddDays(1))
Add line breaks to taste. I've had to read code before written by people who seem to be allergic to using a
for
loop with any increment but++
. Or maybe don't like having keeping all of the loop control in one place or want to pre-emptively break anycontinue
statements.Edit Admin
The sarcasm dripping off of (i.e. gushing from) this dripped off my screen and ate a hole through my desk. What am I going to tell the facilities people here in the office?
Edit Admin
Clearly paid by the line of code every day.
Edit Admin
This code is sponsored by "big LINQ", who want to turn profit by turning everyday developers away from the healthier alternatives.
Admin
I would prefer
procDate += TimeSpan.FromDays(1)
But I guess it's a matter of taste
Edit Admin
Whoa there, that "1" looks like a magic number. Maybe it should be a declared constant?
Edit Admin
#define DAYSPERDAY 1
Admin
Or, if you're Time Cube guy:
#define DAYSPERDAY 4
Admin
Wait. Did you really use "indentation" and "FORTRAN" in the same sentence?
Edit Admin
Given some of the LINQ statements I have to wade through on a daily basis, I thought the original code was perfectly cromulent.
Edit Admin
"Maybe it should be a declared constant?" Of course not, it should be a value in an XML config file somewhere.
Edit Admin
The first example could be cleaned up pretty well with a new function:
Admin
Range takes start and end. It would have been perfectly fine if they'd just used that rather than all the add and subtract nonsense. And just used the iterator... the toList() is entirely superfluous. Likely just couldn't be bothered figuring out the return type and didn't want to drop the unnecessarily long phrase in the loop control line.
Admin
Time is functional, not imperative as idiot educators claim. I, the wisest programmer, have found a single LINQ query for an unlimited range of dates.
Admin
XML isn't modern anymore. All config data should be stored in JSON binary blobs and be retrieved from GitHub in the CLOUD. So should be the value of "number of days in a day". Make it negative if you need more time.
Admin
The functional version mostly just needs a wrapper to hide the implementation details. I have some Java code that does something equivalent with a method along the lines of:
Stream<Date> datesBetween(Date startDateInclusive, Date endDateInclusive);
...which is very useful in my line of work.
Edit Admin
The world is not ready for FP, because it requires deeply thinking about things instead of brute force tries.