Making my code read like a book?
Something like:
if (User.hasBirthdayToday()) { var banner = createBanner() { position = BannerPosition.Top, message = User.isOlderThan(18) ? getBeerBanner : getSodaBanner, backgroundColor = Color.NavyBlue, displayForSeconds = 15 }; banner.Show() }
Instead of spaghetti code:
DateTime today = DateTime.Now; bool userHasBirthdayToday = User.DateOfBirth.Day == today.Day && User.DateOfBirth.Month == today.Month; if (userHasBirthdayToday) { string messageType = "BIRTHDAY_SODA"; if (today.Year - User.DateOfBirth.Year >= 18) { messageType = "BIRTHDAY_BEER"; } string bannerMessage = Banners[messageType]?.getMessage(); Banner b = new SiteBanner(BannerPosition.Top, bannerMessage, Color.NavyBlue, TimeSpan.Seconds(15)); b.Show(); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Making my code read like a book?
Something like:
Instead of spaghetti code: