• Hanzito (unregistered)

    It doesn't help that the indentation is reminiscent of FORTRAN.

  • Smithers (unregistered)

    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 any continue statements.

  • (nodebb)

    Kevin sends us this example of elegant, beautiful functional code in C#:

    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?

  • (nodebb)

    Clearly paid by the line of code every day.

  • (nodebb)

    This code is sponsored by "big LINQ", who want to turn profit by turning everyday developers away from the healthier alternatives.

  • JP (unregistered) in reply to Smithers

    I would prefer

    procDate += TimeSpan.FromDays(1)

    But I guess it's a matter of taste

  • (nodebb) in reply to JP

    Whoa there, that "1" looks like a magic number. Maybe it should be a declared constant?

  • (nodebb) in reply to Ross_Presser

    #define DAYSPERDAY 1

  • Conradus (unregistered) in reply to sibtrag

    Or, if you're Time Cube guy:

    #define DAYSPERDAY 4

  • Steve (not that one) (unregistered) in reply to Hanzito

    Wait. Did you really use "indentation" and "FORTRAN" in the same sentence?

  • (nodebb)

    Given some of the LINQ statements I have to wade through on a daily basis, I thought the original code was perfectly cromulent.

  • (nodebb)

    "Maybe it should be a declared constant?" Of course not, it should be a value in an XML config file somewhere.

  • Shamus Taylor (github)

    The first example could be cleaned up pretty well with a new function:

    	foreach (var date in DateRange(settings.BeginDate, settings.EndDate))
    	{
    		Console.WriteLine(date);
    	}
    	
    	public static IEnumerable<DateTime> DateRange(DateTime start, DateTime stop)
    	{
    		for(var date = start; date <= stop; date = date.AddDays(1))
    		{
    			yield return date;
    		}
    	}
    
  • Erin (unregistered)

    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.

  • Duke of New York (unregistered) in reply to Conradus

    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.

  • Officer Johnny Holzkopf (unregistered) in reply to n9ds

    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.

  • SG (unregistered)

    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.

  • (nodebb)

    The world is not ready for FP, because it requires deeply thinking about things instead of brute force tries.

Leave a comment on “Every Day”

Log In or post as a guest

Replying to comment #:

« Return to Article