Has the code devolved into a big ball of mud?... What can you do about it?

Has bad architecture forced your team to write smelly code? There are plenty of symptoms:

  • global state everywhere…
  • flow of data completely non-obvious…
  • parameters to methods constantly mutated…
  • super, super fragile code…
  • methods being overloaded several times…
  • huge, 8000-line classes…
  • etc.

more...

Does your workplace use best practices?...

Are you somewhere that doesn’t promote good coding practices like code reviews, unit testing, pair programming, etc…? Do you know someone who is? The result is situations like the ones I’ve posted about recently - shitty legacy code, 500 line methods with 20 parameters, and no way to wrap your head around it.

more...

I was thrown into the codebase from day 1...

…I don’t really know how the system works… what do I do?!

Yup, I’ve been there too. My last couple posts talked about how much it sucks to be working with code that sucks. But what if you don’t really mind working with code that sucks, you just feel like you suck at working with it? Worse yet, you actually suck at working with it?

more...

I've inherited 200k lines of spaghetti code... what now?

We know spaghetti code is bad. We teach ourselves how to avoid writing it. But of course, there’s that gravitational force that pulls it from orbit and sends it falling into our laps…

more...

Are you working on the greenfield code that you always dreamed of?...

I didn’t think so… me neither.

”…nope, I’ve got a legacy codebase with nothing but 700-line methods, inconsistent formatting, raw code duplication, no comments, no documentation, hundreds of stored procedures, and no tests…”

more...

What's better: bad tests or no tests at all?...

I don’t have to tell you that every project is different. Should you test setters and getters? What about a method that writes to a file? Do you test methods that call other methods if those methods are already tested? What do you do about exceptions? There’s no point in testing if you’re testing incorrectly… right?

more...

Cracking open a legacy code 'black box'...

Legacy code and integrations can seem black box when you see them for the first time. You’re expected to get familiar quickly. No matter how much time you’re given to get familiar with your new project, you could always use more time.

more...

Nobody plans to write smelly tests...

Just getting started with automated unit testing? Study all you want, but you’ll eventually walk into a code situation that you weren’t well-prepared for.

For example, you inherit some nasty code and your boss wants you to cover 50% of it with tests. You know code smells create test smells and you’re worried…

more...

Debugging all the time isn't fun...

Do you like spending time in the debugger? Personally, I don’t. A lot has to happen to see debugger information, therefore it loads slowly. There are ways to make the debugger faster, but there’s another reason why I don’t like it. Its information is ephemeral.

more...

Just starting out with Domain Driven Design?

You’re just getting into Domain Driven Design (DDD), Command Query Responsibility Separation (CQRS), and Event Sourcing (ES) and most of the overall principles are clear… but as soon as you start using them in your own domain - everything becomes a decision-making nightmare…

more...

Flipping a Boolean When All Values Meet a Condition with LINQ

Every once in a while, a seemingly simple coding problem can throw a chicken-or-egg situation at you. You’ve built complex software in mere hours, how can a for loop throw you off like this…!?!?

more...

3 Ways to Loop Without do/do-while/for/foreach/etc...

There are some crazy questions out there to test your knowledge of CS theory that can leave you stumped. It could come from an interviewer who is trying to weed out hobbyists or a student that you’re mentoring who has a tough professor.

more...

Why Delegates? Why not Call Methods Directly?

Delegates… being a developer/engineer/tinkerer, you naturally want to “get” them. You may kind of get them, but not feel like you can explain them to someone else.

One reason is the practicality of delegates isn’t always clear. Why couldn’t you just directly call a method on an object instead of using a delegate?

more...

New to Testing Time-Dependent Code?... Use NodaTime.Testing!

When you’re just getting into testing and your app has a lot of time-dependent logic - you might feel like you’ve picked the wrong app to start testing with.

more...

How to Map Nested JSON Objects to a .NET Dictionary

Sometimes a public JSON API responds in a format that you can’t control. For example, nested objects instead of an array:

{
   "companies": {
      "abc" : "Abc Company",
      "def" : "Def Company"
   }
}

more...

Weekly Keyboard Shortcut #5: ReSharper's Generate Type Constructor

Welcome back to Weekly Keyboard Shortcuts with your host, Slowness McMousington.

Ever feel like there’s a productivity boost right at your fingertips and you’re not using it? Ever watch someone puke code onto the page like some kind of Hollywood-hacker? If you’re slow and jealous like me, you want to start building your repertoire of Visual Studio/ReSharper keyboard shortcuts now.

more...

Weekly Keyboard Shortcut #4: ReSharper's Go to File Member

Welcome to the latest in my Weekly Keyboard Shortcut series! Last time, we looked at ReSharper’s Expand/Shrink Selection. This week, we’re going to look at another navigation shortcut.

more...

Changing a Type within a Class when you Instantiate: An Intro to Generics

Have you ever run into a problem that you couldn’t describe well enough to even ask about it?

“I want to change a specific type to another type when I instantiate a class to make it more general and reusable…”

“Is this even possible?”

more...

Weekly Keyboard Shortcut #3: ReSharper's Expand/Shrink Selection

If you’re new to my Weekly Keyboard Shortcut series - it’s hard to find the time to stop and be aware of what you’re doing in your Visual Studio/ReSharper workflow.

more...

Weekly Keyboard Shortcut #2: ReSharper's Rearrange Code

Last week kicked off a regular series I’m doing on keyboard shortcuts.

It’s hard to find the time to uproot your workflow and tweak some piece of it that could be optimized. When you do decide to take some time to focus on how you use tools like Visual Studio and ReSharper, it’s hard to find where to start.

My goal is to try to pick out a single shortcut that you can focus on at a time.

more...

Weekly Keyboard Shortcut #1: ReSharper's Go To Everything

I know there are some really good Visual Studio and ReSharper shortcuts right in front of my face, but I don’t have time to stop and practice them.

Of course, there are huge collections out there like Mad’s Kristensen’s Visual Studio Shortcuts and Jetbrains’ ReSharper Documentation, but again - I don’t have time to pour over these collections to learn a few basic shortcuts.

more...

Getting Started with Entity Framework Code-First with an Existing Database

When you’re just getting started with C#, you can get overwhelmed by the benefits and drawbacks of the different ORMs and approaches people take.

Say you have a lot of SQL under your belt. Entity Framework Code-First sounds great, but you’re not sure how to get comfortable with it.

You want to start small by reading and writing to an existing database. All you want to do is map a simple model to an existing table.

more...

Erlang-style Supervisors in C# with Akka.NET and the Actor Model

One reason Erlang is considered a fault-tolerant language is its support for the Actor Model in its standard library…

more...

Converting DateTimes by Offsets with NodaTime

There must be a simple way to convert one DateTime to another DateTime using only a GMT/UTC Offset integer… right?

more...

Singleton Indexer - A Workaround for not having Static Indexers in C#

Indexers are used to simplify access to a collection that is encapsulated in a class you’re designing…

more...

Bad Data, Try/Catch, and Slow Performance

It can be tempting to use try/catch to check data integrity. This can degrade performance, especially if you’re throwing a lot of exceptions.

more...

Throwing an Invalid Cast Exception?... Look Out for Unboxing

Implicit and explicit numeric casts are usually pretty straightforward

more...

Calculating Values using Calculated Values in LINQ

Need to perform a LINQ query with a calculated value that relies on the result of another calculated value?

more...

Exposing IQueryable in a CQRS Query Stack

Sending IQueryable<T> to higher layers can be a touchy subject…

  • “there is nothing more frustrating (or more expensive to maintain) than a data layer leaking up the stack”
  • ”…literally no case where EF + Repository that exposes IQueryable makes sense”
  • “EF-generated anything should never leave the data layer”
  • “it’s bad for unit testing”

more...

A Pattern to Decouple your Aggregates from their Clients

Last time, we talked about DTO Assembly as a separate concern from Aggregate persistence. This means we don’t want to return DTOs from Repositories.

Instead, we put dedicated Application Services in our Application Layer to handle requests from the Presentation Layer. We used DTO Assemblers to map our Aggregates to DTOs inside these Application Services.

more...

A Better Way to Project Domain Entities into DTOs

Imagine you have a nicely designed Domain Layer that uses Repositories to handle getting Domain Entities from your database with an ORM, e.g. Entity Framework, into an MVC view or a Web API controller.

Problem is, the Presentation Layer needs objects of a different shape than your Domain Layer Aggregates.

By different shape, I mean that this layer might need data combined from multiple Aggregates, or only portions of an Aggregate.

more...

Do I Really Have to Unit Test This Method?

You might write a simple void method that takes some arguments, validates those arguments, then makes a call to insert that data into a database.

To unit test the validation step, you might go ahead and mock the database, injecting it into your class with constructor DI of some sort.

more...

What Needs to Be Disposed?

If you’re like me, you just do as the .NET FCL (Framework Class Library) documentation tells you and use a using statement to properly dispose SqlConnection or FileStream.

Even though the CLR (Common Language Runtime) has a sophisticated garbage collector, memory leaks can and do happen.

more...

What's the Point of the 'dynamic' Primitive Type?...

All the features of the .NET CLR (Common Language Runtime) must have some practical use… right? Then what’s the point in the dynamic primitive type?

more...

Keep an Eye On Your Azure Service Bus with the Particular Platform

You might have a good idea about how you’d implement an architecture that utilizes a service bus with asynchronous messaging, but how do you manage the application once it’s live?

more...

Building with Azure Service Bus?... Take a Test Drive with the NServiceBus Sample Project

There’s been a lot of mention lately about architecting solutions using Azure Service Bus and other equivalent technologies like RabbitMQ and MSMQ.

It’s easy to see clear benefits and use cases for asynchronous messaging using both queues and topics/subscriptions. But… where do you start? It’d be nice to have a good sample application to see how this type of project is structured that isn’t just two consoles talking to each other.

more...

How to Compare Object Instances in your Unit Tests Quickly and Easily

When unit testing, you may need to compare attribute equality instead of the default reference equality of two object instances. It might not be feasible to manually compare EVERY field with expected values in another object.

more...

Entity Framework: Modeling an Email Domain with CC and BCC Addresses

Working with Entity Framework Code First takes a lot of the guesswork out of entity relationship modeling in your SQL database. But, if you’re like me, you need to have some awareness of how Entity Framework has designed your database schema.

more...

Should You Jump into Unit Testing before OOP?

Sometimes it’s hard to choose which programming fundamental you should start focusing on next. You might feel pressure to gain a firm grasp on OOP principles before moving on to design patterns or unit testing.

Say, however, you have a loose understanding of OOP principles and you want to work on your biggest deficit, which is unit testing. Is it OK to go against the logical progression of learning more advanced OOP topics before unit testing?

more...

ASP.NET MVC: Should I Use Bundles or a Build Tool for my JavaScript?

As an ASP.NET MVC developer, it can be hard to choose the best JavaScript concatenation/minification approach, especially if you’re working with a SPA (Single Page Application).

more...

How Working the 'Vertical Slice' Can Fix your Coding Mental Block

Making something “just work” and “good enough” was ok when you were a junior developer. But now that you’re in a more senior role, it’s easy for your mind to freeze when it’s time to sit down and code.

more...

Using TDD to Break Through 'Paralysis by Analysis'

As a high-performing software professional, there may be times in your career where your mind freezes as you try to anticipate every disaster that might happen. It may start to take you longer to deliver your high-quality code.

Younger “rock stars” spit out code while you think/worry about design, maintainability, dependency management, modularity etc. Management seems to only see one thing: speed and your lack of it.

more...

Management Doesn't Care about Code Quality?... 3 Ways to Cope

You’ve been given a tight deadline. You just read Domain Driven Design by Eric Evans. *“The business NEEDS to put effort into code quality!”* you say.

more...

A Strategy for an Unmovable Legacy Architecture

“How do I follow best practices when re-architecting my legacy project?”

It’s not uncommon to have a project built with ASP Classic or VB6 lurking around in your enterprise.

more...

Struggling to Keep Up?... We All Are

Even before I started web development, more experienced devs told me they struggled with not being able to stay current in their field.

more...

How to Deal with Pre-Commit Nervousness

You build your project one more time, run your unit tests, run your integration tests, look over your commit log, hold your breath, hover your finger over the mouse button while you do that last mental check, take a deep breath… and click

more...

My AE/ED Line-Based Text Editor Cheat Sheet

I’ve been working with a database called Unidata for almost 3 years now. I refer to it as the “O.G. NoSQL” database because it is the oldest NoSQL database that I know of. It’s referred to as a Multi-Valued Database and it became popular when it was released as part of the Pick Operating System

more...

The Simple Programmer Email Course

A lot of the impetus for me posting more regularly, moving off of Medium, and trying to focus my content comes from an email course I recently subscribed to by John Sonmez at SimpleProgrammer. I first found out about John through his Pluralsight course The Go Programming Language and, since then, have made sure to listen to his guest interviews on .NET Rocks and JavaScript Jabber. He also has a really good book out called Soft Skills. Also a couple podcasts including Entreprogrammers.

more...

Logging with Ninject Interception and Serilog - Part 3

Recap

Part 2 of this series demonstrated the usage of SerilogMetrics with Ninject.Extensions.Interception to make a simple drop-in, AOP-style metric logging interceptor over any (virtual) method in my application. It’s with this interceptor that I want to demonstrate interception via an [Attribute] rather than traditional Ninject binding syntax.

more...

Logging with Ninject Interception and Serilog - Part 2

Recap

Part 1 of this series was me attempting to use Ninject.Extensions.Interception in combination with Serilog to do AOP logging for times when fine-grained logging isn’t necessary across larger vertical slices of my application.

more...

Logging with Ninject Interception and Serilog - Part 1

The Problem

I have a project with a lot of places where I want to “cross-cut” the concern of logging into. This is also called “AOP” - Aspect Oriented Programming. AOP claims to “increase modularity by allowing the separation of cross-cutting concerns… by adding additional behavior to existing code (an advice) without modifying the code itself”.

more...

How to Do Dependency Injection in a CRM Plugin

I first approached this because I thought it was ridiculous how our current mega-Plugins that handle all of our integrations were impossible to debug. I needed a way to separate the logic from the instantiation of the plugins inside of CRM. CRM introduces a ton of constraints as far as being able to code cleanly and take advantage of patterns that make the code maintainable and debuggable.

more...