Tech writer with 560K+ views. Sharing my opinion and what I learn. Danish C# backend engineer in FinTech. Ex Big4 senior tech consultant.



How to easily replace if-else statements. And no, a switch is not a suitable substitute.

Image for post
Image for post

If you want to learn how I use commands and handlers to keep my code neat and tidy, read on. It’s not about avoiding if-elseif-else. It’s about finding a more suitable approach.

Bear in mind that no single approach will ever get rid of traditional branch-based programming. You need to build a repository of techniques to draw from.

The method we’ll walk thru now is just one of many.

if-else is, at its very core, not bad. It’s merely just a hammer and nail situation we got going. …


The art of turning 6 lines into 92 lines by replacing if-then-else and switch with objects — for the better.

Image for post
Image for post
Credit: the author

Sure, if-else and switch makes for condense, simple code. But your software should not be comprised of the fewest lines possible, sacrificing readability, maintainability, or flexibility.

I see a lot of branching happening over enums, or, other discrete values. Some developers even get aggravated when told not to use if-then-else.

But, what do you think the consequences of using enums in your if-then-else statement are?

Branching on discrete values makes your software difficult to change. Every new feature requires you to track down where the branching is happening, and modify your existing code accordingly.

This is definitely not how we want to develop great software. It’s perhaps a perfect first step towards making your code work. But, as you progress to making your code better, switch and if-then-else must be long gone. …

Crafting great software is about focusing your attention on what matters at the right time

Image for post
Image for post
Photo by the author.

Rubbish software is produced when we try to do everything at once.

Principles, guidelines, best practices, and rules of thumb — they all make your life easier. Without them, ten-minute tasks can turn into ten-hour tasks.

One of the absolute best pieces of advice I received from my mentor very early on in my career was this simple one-liner:

“Make it work, make it better, make it faster.”

It’s a slight alteration of Kent Beck’s famous quote, and its simplicity is enabling and puzzling.

“Make it work” is quite easy to wrap your head around. You have a set of requirements, and you’re coding to fulfill them — kid stuff. …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store