1

I really need some advice as I've recently come into a conflict over a difference of opinion on the SOLID principles and writing clean code. One of our, relatively new developers but senior, does not agree with me that it is not a good idea to inject the Database context directly in the controller and then have all the business logic there. I've tried to argue against this but to no avail. His opinion is that it will create too many classes and doesn't see the point. I asked him if he has read Bob Martin's clean code and he hasn't; I'm also pretty sure he doesn't know what the SOLID principles are. I also work with another dev who is utterly clueless about writing any sort of clean code; his idea of that is if the code is indented properly. Unfortunately, I was reading through some of his code that was in a controller and I came across something that just seemed anathema to writing good code:

if (DbContext.Queue.Any(x => (x.Name == selectedQueue.Name || 
   x.QueueAlias.Any(xa => xa.Alias == selectedQueue.Name)) && 
   x.Id != Id))

   return BadRequest("The queue name: " + selectedQueue.Name +
                              " is already in use as a name or 
   alias. Please select a unique queue name.");

I then asked if this could be moved into a method to which the more senior developer, who I mentioned earlier, said there was no need as the return statement explains it. None of them seemed to understand that from a readability perspective, it's not good. Am I wrong in thinking this? Still more worryingly was another senior dev, who I looked up to, stated that most places don't bother using SOLID. That seems a bit of a sweeping statement. Is this also correct?

I honestly feel like I need to leave as I’m not on the same page as the rest of the team. I’m trying to follow the SOLID principles as best I can but I’m also still learning and I understand there has to be a trade-off. My fellow devs don’t seem to follow any standards just the ones they’ve come up with over time, which means it hard to communicate on a similar level about writing code and structuring the application.

I apologise if this sounds like venting but I really need some advice because, to reiterate, I think I may need to leave as I fear I’m working in a cowboy coding environment and I’ll just come into further conflict and not really advance myself as a developer. I think what I’m mainly asking for advice on, “is how do I argue that this is bad design and we need to refactor and we need to start writing cleaner code”. Plus, I’ve talked to my manager about this, and he’s told me if I can convince him, he’ll ask the rest of the team to start implementing SOLID.

Al_M42KM
  • 11
  • 1
  • 1
    I've created a very successful software engineering career for myself over the last 20 or so years. I didn't know the SOLID principles for most of that time, so I'm living proof that you can make it work without knowing them. – Robert Harvey Jun 27 '19 at 03:30
  • 1
    As to the readability of your example, I completely understood it immediately, without having to read it twice. – Robert Harvey Jun 27 '19 at 03:30
  • I agree, you can make it work. But if you already know that you'll be working in a "hostile environment", you have 2 choices. You can try to convince (possibly very stubborn) senior developers to mend their ways, or seek employment elsewhere and on your way-out interview tell the management that the reason is poor development practices. Considering the need for competent developers, and the general quality of jobseekers, I suppose you'd have above average chances. Just don't become one of those people who parrot "but the SOLID principle", without any substance and experience behind it. – Kayaman Jun 27 '19 at 04:47
  • 1
    As for me, I didn't understand the code on the first read (although I'm a Java dev, not C#). I *might* extract it to its own method (depending on a multitude of things), because I don't know whether the next person to read the codebase is a Robert or a Kayaman. – Kayaman Jun 27 '19 at 04:50
  • @kayaman: The code illustrated is more or less idiomatic for something akin to an ASP.NET MVC controller. So if you've seen one before, this code is pretty straightforward. – Robert Harvey Jun 27 '19 at 05:18
  • 1
    How much experience do you have, @user3743251? – Robert Harvey Jun 27 '19 at 05:20
  • @RobertHarvey alright, if this is the worst example of bad code, maybe don't hand in your papers just yet. Might be a case of more theoretical knowledge vs. practical experience, and not knowing how to apply the former in the latter (i.e. "booksmarts"). – Kayaman Jun 27 '19 at 05:23
  • Without a doubt. More importantly, how to apply the booksmarts in a *practical* way, in a way that respects pragmatism. – Robert Harvey Jun 27 '19 at 05:24
  • 4
    @RobertHarvey you really understood the 4 deep parentheses **immediately?** And know that it's error free? – user949300 Jun 27 '19 at 05:30
  • Yes. The first line is Linq. It's error free if what it says it does is correct for the application. It's very readable if you know Linq. The second line is what a controller method typically returns; it generally includes an HTTP error code and a message, but it 's usually a class inheriting from Response, not Request. It doesn't look *entirely* error-free, no; it looks like you tried to cobble it together from memory. – Robert Harvey Jun 27 '19 at 05:33
  • 1
    In any case, none of the SOLID principles apply here; not really. Controller methods do what they do because of the way controllers are designed, and nobody's going to tear them apart just because Uncle Bob created some principles. – Robert Harvey Jun 27 '19 at 05:35
  • 2
    I'm [skeptical of SOLID myself](https://www.morganconrad.com/posts/ocp) but think that splitting this onto a function is good, not cause of SOLID, but could add clarity, and likely help with DRY. – user949300 Jun 27 '19 at 07:04
  • 2
    @user949300 I've seen horrible code written by people trying to over-adhere to DRY, resulting in absolutely insane and overcomplicated code. Some people understand principles and patterns as absolute rules, and don't know how to adapt them to specific use cases resulting in good code. If this is indeed idiomatic code in C#, then the developer is "at fault" if he isn't familiar with it. – Kayaman Jun 27 '19 at 08:45
  • @RobertHarvey I've got 4 years under my belt and in the last year have discovered design patterns, SOLID and clean code. I find what Uncle Bob has to say illuminating. He might be a bit dogmatic at times but I think his discourse has value, because at the moment, all I can see, in my experience, are software devs doing what the F they like and not following any kind of guidelines. And when trying to work in a team, it's a pain. – Al_M42KM Jun 27 '19 at 14:02
  • @user3743251: Alright, but the code sample you provided doesn't really illustrate the problems you're describing. And I've seen too many software developers who don't have a lot of experience who misuse SOLID principles thinking they're doing things "correctly." – Robert Harvey Jun 27 '19 at 14:24
  • 2
    Refactoring repetitive code isn't part of the SOLID principles. See, this is what I'm talking about. If I worked at a place for several years where we did things a certain way, and a new guy came in and told me I was doing it wrong because Uncle Bob sez so, I'd be very irritated. – Robert Harvey Jun 27 '19 at 14:50
  • I'm not a new guy with regards to the team but recently we have had a new guy join who has started to do what you've just stated; apart form it not being related to SOLID. @RobertHarvey: It doesn't sound like you're a fan of SOLID? But I agree with you, and I wonder if I'm doing things correctly by trying to follow the principles. – Al_M42KM Jun 27 '19 at 15:02
  • 1
    I think SOLID is just fine. But it has to be tempered with experience. Read [the post linked above](https://www.morganconrad.com/posts/ocp), and read the [duplicate post I linked at the top of your question](https://softwareengineering.stackexchange.com/questions/357745/are-bad-programming-practices-typical-within-the-software-industry). – Robert Harvey Jun 27 '19 at 15:07
  • @RobertHarvey : Will do. Thank you for your time. :-) – Al_M42KM Jun 27 '19 at 15:08

0 Answers0