3

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?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794

7 Answers7

11

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
  • 5,587
  • 1
  • 31
  • 39
  • 1
    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) – SingleNegationElimination Jul 18 '09 at 19:34
9

Perhaps you begin by recognizing explicitly that part of your job is to help develop the junior devs. If you're not the boss, management should sign off on this. Management needs to recognize that your choices are to develop them now or clean up after them later, and you need management's backing for the time this will take.

Code reviews and pair programming are fine ideas. They are especially good because they are not "just for junior people"–I do both with one of my close colleagues; together we are nearly 100 years old and have more than 70 years of programming experience :-)

But there's a larger problem here: the programming methodology that enables you to be most effective (YAGNI + refactor) is not effective for your junior partners. My experience is that it takes people years to learn the benefits of YAGNI, so if you expect them just to learn your way of doing things, you are setting yourself up for disappointment.

I would encourage you to identify some methodology that you think is going to be useful with your junior partners. The particular methodology probably doesn't matter (heresy!); I've had success with composite/structured design, object-based design, algebraic specification (!), and extreme programming. But

  • Do pick something that has a name and some literature devoted to it, that your juniors can take pride in learning, and that is a skill they can carry to future projects.

  • In order to show that it is tasty, you may need to eat the dog food yourself. Pick something you can live with and be productive in.

  • Observe your juniors carefully and teach them a decision procedure they can use to identify when they should ask you for guidance.

Good luck!

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
  • 1
    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 Jul 28 '09 at 16:15
2

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
  • 32,260
  • 12
  • 84
  • 119
  • 2
    +1, but caution -- junior devs don't always recognize when things are getting difficult. To some, difficulty is normal. – Norman Ramsey Jul 18 '09 at 19:43
1

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
  • 24,318
  • 4
  • 40
  • 46
1

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
  • 313
  • 2
  • 4
0

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
  • 18,086
  • 12
  • 58
  • 77
0

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
  • 11,860
  • 4
  • 38
  • 49