Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Good Ole Refactoring

I was talking with some co-workers about a pull request recently and we all decided we didn’t really like the look of some Code.

Here's the code:

Our main issue with the code was that it was difficult to read and immediately understand what was going on.

Here are the things you should know:

  • The SystemClock is a Headspring nuget package
  • IsDayOnWeekend just checks if the current day is a Saturday or Sunday
  • IsHoliday checks whether or not the day falls on a holiday

So we did a small Refactoring to make the code more readable.

  • So we renamed the method to include GetPreviousBusinessDay
  • We get the last 365 days, we could've just as easily gotten the last 30, but decided to just get the full year.
  • After we get the last 365 days, we get only the valid business days
  • Then we order those dates descendingly, skip the number of days back we want to go, and then grab the first date

Our refactoring is more readable, has some "clever" code that we like, but aren't married to either. I'm curious to know other opinions, and other solutions that we could've used.



This post first appeared on Deran Schilling, Learner, please read the originial post: here

Share the post

Good Ole Refactoring

×

Subscribe to Deran Schilling, Learner

Get updates delivered right to your inbox!

Thank you for your subscription

×