Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

My team has about 18 members and the code is generally good, using TDD and good specifications makes for working code. But I think they abuse comments in favor of writing cleaner, more readable code.

I would like to introduce them to the concept and I'm wondering how can I do that on a larger scale without sitting with each and every one of them on their code and explaining how it could be improved.

This is different from the suggested duplicate because I believe I already know how to write clean code. What I'm looking for is how do I introduce my team to writing clean code?

share|improve this question
    
Do you mean to say they rely on comments instead of writing clean code? "in favor of writing clean code" sounds like they already are writing clean code. –  Heatsink Jul 13 '13 at 17:15
    
What does "clean" mean for you? Are you looking for better names of variables/methods/classes? Are you refering to Clean Code Development initiative ? –  k3b Jul 14 '13 at 8:36

4 Answers 4

I'm wondering how can I do that on a larger scale without sitting with each and every one of them on their code and explaining how it could be improved

Short answer:

  • nothing else than regular code reviews can fix this
  • you don't have to do all the code reviews by yourself, especially when your team has 18 people

How you organize your code reviews is up to you, of course, for example, you could insist that before some new code is checked in (into your VCS), every dev picks an available peer and asks him kindly to proof-read the code. You could also do code reviews on a more formal basis, or after check-ins - choose whatever works best in your team.

share|improve this answer

Your first problem is to decide what you mean by clean code. You may know what you mean, but I expect you will find a range of opinion amongst 18 team members. Without first agreeing (or dictating, if you are so minded) what is good and what is bad, you have no chance of achieving it.

As a suggestion, why not get each team member to submit a piece of what they consider good code to the Code Review StackExchange site (http://codereview.stackexchange.com/) and see what reviewers make of it (if it is C, I will review it :-). It doesn't need to be a large amount - just a few functions or a class, or maybe even just a header file. If the team is good, they should expect to get only minor remarks. The reviews will give you some independent basis for progressing towards cleaner code.

share|improve this answer

There are a few ways you could do that.

First way, use your languages features. In java you could things features such as Abstract, Final, Public, Private, inheritance, interfaces, delegates, events. That would prevent them from messing the code at the object oriented level. You could go a step further and implement design patterns. Designed patterns were adapted in the 90s by programmers, but first developed by an architect whose name was Alexander Christopher. Design patterns have the strong advantage of templating the code design, and imposing a design structure.Read the article the gang of four. There is also a site where different design patterns are implemented.

At the class level, you could use things like getters and setters, that would clean up the code and make it more manageable. Tell your team in general to use prefixes for function names, such as get, set, is (for returning booleans).

I read from some book that is called "clean code" that you should use up to 20 functions in a class, and each class should be classified by functionality. Number of lines in the function should also be limited. So why not to tell your team to follow such policy?

Teach your team to write shorter code if you can, use trinary expressions instead of if or else, use switch instead of many if and else, use recursion instead of some loops, do do while loops instead of while loop . Avoid the use of labels when in loop, avoid many condition statements in ifs or for loops, avoid long loops (comment at the end of loop closing braces if loop is long),avoid many nested loops.

To sum up, enforce a template on all the code design through abstract classes, inheritance interfaces and design patterns overall. Use short well named functions, group them by class, allows use the right accessors (try to use uncommon accessors like 'final', 'sealed'), use getters and setters, as they are also a means of code control. Try to address and comment how to write clean, short and effective control flow. Use the api more as it offers prebuilt functionality, dont try to come up with your own functionality as it will result in more code, which is also less tested.

*I was in a messy code situation too many times to know what clean code is!

share|improve this answer

have them watch the videos. http://cleancoders.com he does a bunch of wacky stuff in the videos so its never boring.

Suggest to start with Ep 15. Get your group together and spend a few minutes discussing how to design an app for a simple coffee maker? and then watch http://cleancoders.com/codecast/clean-code-episode-15/show

this video clearly shows the common mistakes in application design and then the big payoff using clean code. and its fun to watch so it should engage your team.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.