views:

267

answers:

7

When writing code for a new system I don't want to introduce unnecessary complexity in the design that I might never have any need for. So I'm following YAGNI here, and rather refactoring as I see the need for more flexibility or as responsibilities becomes more clear. This allows me to move faster.

But there is a problem here with junior devs, in that they will not recognize when to refactor or where build out the design. They just stuff more code into the existing design.

So, what are the best ways to tackle this? Should I more often build a more future-proof design so when adding to it they have a good example to follow, even if we might never have to add anything? Or should I just go ahead with more code reviews, education, etc? Or both?

Have any of you had any experience with this type of problem? How did you solve it?

+2  A: 

There is a reason they are junior and you are senior.

The ability to realise when a change in design is needed is one of them.

I would carry on as you are but encourage them to come to you when things are getting difficult. You can then work with them to alter the design if needed, this will be easier for you than refactoring it and will help you pass on knowledge to your junior developers.

Garry Shutler
+1, but caution -- junior devs don't always recognize when things are getting difficult. To some, difficulty is normal.
Norman Ramsey
+9  A: 

I would recommend code reviews or pair programming. It gives you the chance to educate your fellow developers and increase the overall quality.

Sebastian Dietz
Indeed, I expect more code review and generally mentoring the junior devs to be a better use of your time than writing a lot of excess code you don't know you'll need, just in case the junior devs want to add to it (which they will often do in conflict with your design, anyway)
TokenMacGuy
+1  A: 

A very good way to show how far to build out a design is to be specify about what the design will do when built out, then write tests to cover the new functionality. When the tests pass, development is done.

You might realize along the way that you forgot to test for something. That's fine, and is useful feedback to help you specify better next time. Write the missing test(s), and only enough code to make them pass.

Then refactor. Knowing what to look for when refactoring takes a bit of practice. Start with

  • Is there duplication in the code we've just written that we can eliminate?
  • Is there duplication between what we've just written and pre-existing code?
  • Does the code we've just written concern itself with too many things? (I.e., should we break out collaborators?)

Repeat this a few dozen times, and it'll get easier.

Dave W. Smith
+8  A: 
Norman Ramsey
Junior Developers often learn best by having clear-cut interfaces or even unit tests to code to. It's much easier to learn good coding practice via seeing it done than it is to come to it by yourself.
Markus Koivisto
A: 

I'm all for code reviews and teaching, but I think futureproof design is also important. Maybe you could think of it in terms of you designing an API and the junior developers using the API. In this way you are the one who does the hard work that they would screw up (identifying duplicated code and eliminating it) while they do all the grunt work that isn't a productive use of your time.

Of course this has to be balanced with a need to develop your junior developers skills. Neither side of the equation can be neglected.

Imagist
+1  A: 

Another way of looking at YAGNI is that any changes to code need to be justified.

Might it be helpful to require any commit needs an associated unit test (or BDD user story, choose your poison)? It helps to communicate your intent (you want people to think about why they are adding this feature) and you get regression tests for free.

Also gets the noobs to start thinking about modularity (usually needed to make your code testable) and will help a lot if you do need to refactor later on.

Rasputnik
A: 

It may help to map out what work they will do and then verify it to help build their sense of judgement which is really what you are asking, to my mind. Pairing is one option but if you can't spare that much time then having a sort of "check point" to see how they are doing and preventing them from going down the wrong path.

JB King