I must admit something… I must admit that I get more and more frustrated with the lack of code quality in all projects I work on as a contractor. Some are okay, but most are very far from it. What frustrates me more is that most of this poor-quality code I analyze is written or supervised by senior software engineers. Since I don't work permanently at a company anymore, I can't make sure that code quality is a feature, not an afterthought. By the time a company gets in trouble and hires me to work on their codebase, it's almost too late to implement code quality since it usually means major changes to the code and architecture.
As an example, this year I was hired for a contract about 1 ½ months before user accepting testing started on the first version of three projects. These projects aren't even in production yet and they already have 4,200 code violations (one every 4 lines of code), including violations from StyleCop. These three projects also needed major architectural changes so that the code can be reusable and unit testable, something I discuss a lot in my conference sessions. This is an example on when it's almost too late to hire me, since I fear most of the work I did in the first 1 ½ months will never make it into the master branch.
On a contract a few years ago, their codebase had over 50,000 issues (not including StyleCop). I worked on it for about a year… just fixing their code issues. I didn't even add one feature in that year! As with many contract jobs, they ran out of funding at the end of their fiscal year, so I moved on to another contract. About six months later they hired me back and in that six months, they introduced over 10,000 new code issues!
Now do you understand why I get frustrated? I've been writing about and speaking about code quality for a very long time. I drill code quality into my students heads in all classes I teach. All my code sessions at conferences are wrapped around code quality. I write about code quality in all my books. Heck, I have the only pure .NET coding standards book out there!
Management Doesn't Care, So You Have To
Let's face it, management at most companies only care about two things. The first is features, features and more features. Adding features is the only way to sell product. The second thing they care about is adding those features at the lowest cost possible. Due to these two things, management does not care about code quality which always includes proper architecture, since to them, it isn't a feature. They can only see what features cost now with no worry about how much it will cost the company in the future if code quality isn't a feature from the very beginning. Especially when it comes to fixing bugs, which isn't a feature either.
At one company I worked at, towards the end of my time there, I was in a major meeting with managers and vice presidents. They were talking about all the features that needed to be added to the product to sell more product. Towards the end of the meeting I was getting frustrated and I finally raised my hand and said, “The features you want will either be impossible or take so long that our competitor will release it before us and we will lose customers if you don't break down and re-architect the database.” They all looked at me with expressions like they have never heard this before until my boss said, “Dave has been telling you this for four years, why don't you listen to him?” Not long after that they laid off all the high-level software engineers in my department, including myself. Guess what happened? They lost customers.
So, it's up to you, the coder, to care about code quality or it won’t happen. Why should you care? You will be the one that will have to maintain the code, add features and fix bugs. If your projects are a pile of spaghetti code, then you will be just putting band aid over band aid on top of it until it finally falls down and you have to start all over again, hopefully right this time. It will be worse if the database is poorly architected too as I discussed in the example above. So why not do it right in the first place?
For me, it's also a matter of pride. I want to check into source control the best code possible. It's even more important to me as a contractor since I will be at the company for a limited time, so I can't put it off until later.
Learning Code Quality
Again, to learn code quality, it must be important to you. You must care about it and once you have been doing it as long as I have, it just becomes second nature. So much so that these days, it's painful for me to work on projects that code quality isn't a feature and I'm forced to use bad practices. Now that I think of it, maybe I should charge companies a higher hourly rate depending on the state of their code!

Mahesh ChandPosted Jun 11, 2019, 12:03 PM
Code quality and code security should be the very first discussion in project kickoff meetings. Project Owners, Managers, and Architects needs to understand the value of quality and security. I see so many applications with security holes. It is funny.. in one of my interviews I asked a "web developer" what happens in memory when you declare a variables in your code. He was like . ahh . I don't know. I'm a web developer :). Developers on the other hand are rushing to get their work done and show their "bosses" that they have finished. If developers take too much time on quality and security, their manager will probably going to yell at them for taking too much time. It's the project owners and architects need to put aside extra time for code quality and code security.
Thiago VivasPosted Jun 11, 2019, 11:49 AM
Nice article. I can feel your pain, it is very difficult to see someone that cares for code quality :\
Former memberPosted Jun 11, 2019, 5:46 AM
Nice article sir ...thanks for sharing
Subbarao APosted Jun 11, 2019, 3:09 AM
Wonderful article on the code Quality David. Code quality plays a critial role in the performance of the application.