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
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,
if-then-else must be long gone. …
Let me just say this right off the bat: If-Else is often a poor choice.
It leads to complicated designs, less readable code, and may be pain inducing to refactor.
Nevertheless, If-Else has become the de facto solution for code branching — which does make sense. It’s one of the first things any aspiring developer is taught. Unfortunately, lots of developers never advance to more suitable branching strategies.
Some live by the mantra: If-Else is a hammer and everything’s a nail.
The inability to determine when to use a more suitable approach is among those that distinguishes juniors from seniors.
I’ll show you some techniques and patterns that’ll put an end to this horrific practice. …
Who’s the judge anyway, right?
I’m a design patterns advocate. I like to write neat, clean code, thoughtfully applying design patterns where I see fit. It’s an incredibly rewarding feeling when you correctly and effortlessly implement a design pattern. The opposite is true when forcefully attempting to apply an ill-suited pattern.
Nevertheless, there are times when I simply need to move a user story from In-Progress to Testing. Fast.
Depending on the problem you’re solving, writing garbage code might be completely okay. By garbage code, I mean overly bloated and simple code that does, however, function correctly.
Don’t mistake garbage code for code that doesn’t meet the requirements or fails. That’s insufficient, buggy code, which is entirely different by nature. …
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. …
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. …
I’ll start by providing you exactly what you came for: the rules of thumb.
Are you curious about why these heuristics are useful? Then read the additional information included after the list.
Let’s dive headfirst into the matter. This list is a mix of heuristics I always have in the back of my mind when I venture into a refactoring session.
It’s honestly not very difficult to write great, configurable classes. But, it might be if you’ve grown used to doing things in certain ways.
From my experience, the best way to turn an existing class into a configurable one is first to move logic into separate classes and then the moving hardcoded part into constructor or method arguments.
It’s that easy. Let me show you how.
Before you spend any time refactoring your existing classes into configurable ones, I’ll let you know why it’s so great.
A configurable class is damn easy to use. It’s extensible. It doesn’t do too much. …
Truth be told, we’re all confused.
One thing is obvious after years of professional development, wading through tons of code. Developers are terrible at naming things.
As a rookie developer, I know you feel overwhelmed, puzzled or straight-up confused whenever you meet
WhateverManager class in the wild — or better,
Business Developer? Yeah, you’re a salesperson. Social Media Ninja? You probably got a 3-week course in how to post cat pics on Instagram and develops a “sick” SoMe strategy. Software Developer? You might as well be a code monkey. Who knows which responsibilities you’re assigned.
There’s a distinction to make. Job title and job role. We sometimes (often) like to make our titles fancier than the role we’re having. …
I’m not going to preach theory. Since you decided to click this cryptic title, I assume you’re already familiar with the SOLID principles abbreviations.
Chances are you’ve already looked at a bunch of other articles, tutorials, and videos about SOLID. No shame in having to get more perspectives on the same topic.
I’ll show you how easy it is to refactor garbage code, and hopefully, you’ll have a foundation to improve your code quality.
Luckily, it’s incredibly easy to write SOLID code.
So, I have no chance of demonstrating every aspect of each principle. I’ll merely be demonstrating the principles using a few practical examples. You have to do your own thinking from thereon. Incorporate what you think works. …
I’m sure even non-.NET developers will find the ideas useful.
For the uninitiated or anyone starting to pick up C#, collection initialization is one of those need-to-know language features C# has to offer.
The greatest thing about C# is how flexible the language is — making it likely the most enjoyable language to work with. Microsoft keeps adding new, awesome features to the language and .NET ecosystem. Even so many features that we often miss a few of the really handy, convenient ones.
Writing a custom class leveraging the collection initializer is one of the most overlooked features. This is even despite the collection initializer’s heavy use when initializing e.g. …