I'm leading a team of web developers, and a number of the developers are writing unmaintainable code.<p>Example: Mega objects that should be broken down; mega functions that should be broken down; objects in the wrong areas (business logic in presenters)<p>I'm dealing with this on a case-by-case basis through forensic pull request reviews, and loading common themes into a ways of working document.<p>My concern is that the devs just don't seem think like architects - thinking about the jobs to be done and the classes and methods needed to do the job, and where they should live.<p>Is this a common issue and are there solutions? In particular, solutions for non-CS background developers.
I think code review is the way to do it, making sure you communicate the general principle rather than just the specific change.<p>I don’t think having a CS background makes any difference here, but I have found that some people pick this stuff up quickly and others don’t. Going forwards you should make sure you’re filtering for this as part of your hiring process.
I've had success with two techniques, though they require patience.<p>First is setting a few short, firm rules about the specific implementations in a project's code. For example, one of my commandments is, "Do not log from library classes that query the database." Its main purpose is to maintain separation of concerns, but its secondary purpose is to get developers to ask why.<p>The other is similar, just more general, and that is (in the absence of formal coding conventions) picking two or three minor, common coding mistakes and being a dictator about them: declaring a local variable that's only read once, returning true or false in an if-then-else block instead of returning the evaluated expression directly, that kind of thing. Look for them first in code reviews and require changes on the spot. It gets folks to slow down a little and consider what they're doing, which makes a lot of difference in the long term.
I'm going to add a code design course to: <a href="https://platform.intervee.io/courses" rel="nofollow">https://platform.intervee.io/courses</a><p>with challenges that very similar to the problems you described. But it will take a few weeks to be ready.<p>For your question:
Maybe they undervalue a well design code because it's hard to be measured. At the end of the day, you judge them based on their tasks and not quality. Try to give them a motivation to think like architects.
What would happen if you ask them to be reviewed by a team member, before pushing it to your review?
1) Devs doesn´t even need to think like architects. You (or the project manager, project owner, whatever) must provide a (good) specification.<p>2) You can also bring general standards into practice. But do not try to solve everything at once.<p>3) Leave code review comments on a helpful way. There are some good articles, how to mastering that.<p>4) Force they to refactor, and leave time for that. You can sit together with the developer, and refactor one part of his/her code. Next time sit together again, and let him/her to refactor. Next time just let him/her to do that, and review code.