TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How do I get my team to write better code?

63 pointsby kamakazizuruover 10 years ago
I&#x27;m leading a team of programmers - not all of whom I had a say in choosing. They&#x27;re generally a smart lot when it comes to understanding the algorithmic &amp; functional logic - but make beginner level mistakes like hardcoding thigns, naming functions like &quot;findeventsfromthelast6hours&quot; (when the 6 hours could be changed at some point - rendering the name of the function pointless). And so on...<p>I review commits now and then and find some of these issues - but due to the nature and timeline fo the project cannot do it for each and ever commit of course. So I&#x27;m wondering what I can do about this? Is there a short guide or book that I can recommend my team to read? I of course tell them these things myself too - but it gets frustrating because I keep feeling like a lot of this should really just be common sense.

49 comments

rmcastilover 10 years ago
You need to stop thinking of them as &#x27;coders&#x27;. When you think of them that way, you&#x27;re putting them in a box and limiting them.<p>Instead consider them to be a team of people. As you said, each of them are at different stages in their career in programming. You need to understand this and sympathize with them and their code. This takes time and effort on your part to help lead the way.<p>You say that you review the commits now and then and find some of these issues, but do you bring them up? Do you show them how the code can look and read better?<p>If you do, make this a process and act as the person approving pull requests for the first several weeks. Then formalize this process and delegate this job to the next person who you feel writes high quality code.<p>Again a SHORT guide or book will not turn around the quality of your codebase and the team working on it. If you&#x27;re interested in better code, invest in your team. Send them to conferences, give them a budget to spend on books, have book clubs and lunch and learns. Invest in the process of improving the skills of your team.
评论 #8567361 未加载
评论 #8567854 未加载
评论 #8567640 未加载
评论 #8567540 未加载
评论 #8567419 未加载
评论 #8567542 未加载
评论 #8567536 未加载
npsimonsover 10 years ago
There are many different things you can do, but it all comes down to: do your programmers care? If they don&#x27;t at all, it will be impossible to make them improve. If they care a lot, they will improve themselves. If they care a little, that&#x27;s where you can try some of the strategies others have given here.<p>As for my specific suggestions, I would recommend &quot;The Pragmatic Programmer: From Journeyman to Master&quot;, and actually apply the principles in the book yourself. Use unit tests, setup CI (such as Jenkins), a code review system (such as Gerrit), a bug tracker, code analysis (such as Sonar), and use tools (linters, etc). Also, cranking up warnings on your compilers&#x2F;interpreters and not allowing in anything that doesn&#x27;t pass muster is a good start. This might all seem like a lot, but you can do little parts of it at a time. It is worrisome that you say you can&#x27;t review every commit. Perhaps you could assign members of your team to review each other&#x27;s commits? This would also have the bonus of giving them a feel for what it&#x27;s like to be on the receiving end of bad code, and to teach each other.
edw519over 10 years ago
<i>I review commits now and then and find some of these issues - but due to the nature and timeline fo the project cannot do it for each and ever commit of course.</i><p>Why not? I do.<p>I have 8 direct reports and I review every single line of code that they write. Some days this is all I do.<p>Others think I&#x27;m crazy but our group outperforms every other group by any measure. I&#x27;m convinced it&#x27;s because of peer review.<p>A few thoughts:<p>1. Regarding resources and timelines: It&#x27;s not when you start, it&#x27;s when you finish. Every hour of peer review saves me at least 10 hours on the back end (systems testing, regression testing, user acceptance testing) and 100 hours on the back&#x2F;back end (maintenance).<p>2. I never have to tell anyone anything more than once. I make sure I explain why. (When you do &lt;x&gt;, you cause &lt;y&gt;.) Then they learn and remember. This is not a religious debate; it&#x27;s a way of conducting business. This won&#x27;t work nearly as well if people are more interested in showing what they know than learning how to do it properly.<p>3. As I get to know different people, I know where I can skim and where I have to focus. I rarely return much to senior people. I often return a lot to junior people.<p>4. Everyone makes mistakes, even senior people, and even me. Peer review, like regression testing, is a pain in the ass, but it more than pays for itself on the back end.<p>5. As soon as you feel you&#x27;re ready, you&#x27;re senior people can take some of the peer review workload. I have done this before, but it hasn&#x27;t lasted because of turnover.<p>6. Once people know everything will be peer reviewed, they become more careful about what they&#x27;re doing.<p>7. Technical debt is a huge timebomb. I know of no better way of slowing it down than 100% peer review.<p>8. Everything is documented in the ticket. This provides some feedback on how it&#x27;s working and what should be changed (programming standards, peer review methods, etc.)<p>9. Once you put your phone away, get off the internet, and stop going to useless meetings, it&#x27;s amazing how much more time you have to do things that really make a difference, like peer review.<p>10. I hate doing this. I&#x27;d rather just code. But the only thing I hate more than peer review is fixing bugs. That&#x27;s why I do this.
评论 #8567743 未加载
评论 #8567866 未加载
评论 #8571821 未加载
jgrahamcover 10 years ago
I wrote a short blog post for work about this <a href="http://blog.cloudflare.com/making-code-better-with-reviews/" rel="nofollow">http:&#x2F;&#x2F;blog.cloudflare.com&#x2F;making-code-better-with-reviews&#x2F;</a><p>Simply put: we use git and developers can&#x27;t commit to the master branch. They commit to their own branch, the build system builds&#x2F;tests that branch and the developer makes a pull request and gets the code reviewed.
评论 #8567199 未加载
andreasklingerover 10 years ago
We do team based pull request reviews. (in github)<p>You need two other seniors to give you +1 to move on. The number &quot;two&quot; comes from the fact that we are still a small team.<p>People can will still review stuff that has already two +1&#x27;s but the commiter could already move on if needed.<p>The advantage of pull requests is less &quot;teaching how to do it properly&quot; but more &quot;learning from each other&quot; and &quot;continous exposure to all parts of the codebase&quot;.<p>Thus it&#x27;s not the job of the Team Lead to do this reviews but everyone&#x27;s.<p>Pull requests reviews are done (asynchronously) done each morning (whatever this means for each person&#x2F;timezone). This leads to the fact that you usually can expect PRs to be done within 12-36hours.<p>I could not imagine working in a team with different experience levels (not speaking of countries&#x2F;timezones&#x2F;specialisation) without pull request reviews.
评论 #8567267 未加载
blueatlasover 10 years ago
We do 1-1 peer reviews and make changes in real-time so that the developer can see the preferences for code style, naming, indenting, etc.<p>You should also lead by example. Your post includes numerous spelling and grammatical errors. If you want them to be precise with such things, you yourself must do the same. Sorry, not picking on you, but your developers will follow your lead with any form of writing.
评论 #8567884 未加载
mamcxover 10 years ago
Apart of the suggestion here, you have a problem in &quot; but due to the nature and timeline for the project cannot do it for each and ever commit of course&quot;.<p>If the time is so tight that you can dedicate time to fix stuff (including the code quality) then any of the suggestion here are DOA.<p>Remember: If you want to chop wood for 10 hours, use 8 to sharp the axe.<p>Code, code, code, code non-stop is as efficient as chop wood without sharp it after a while.<p>Dedicate time to improve the code quality <i>ALWAYS</i> pay off. Think: &quot;I&#x27;m time constrained, so continue the death march until we finish&quot; ALWAYS make the project <i>take longer</i>.<p>---- A good idea is STOP each week, review the tasks, ask where are the pain, where is the code that is becoming a mess, what is complicated, then FIX that. Decreasing code&#x2F;clearing it in the short AND long run will be a time saver.<p>Encourage change when the purpose is quality. Not stick to code&#x2F;design that is a pain. Stop each week to breathe and see if move forward as now make sense, or is better to kill a portion of the code and rework it.<p>This is specially important when the TIME is critical. When time is not critical, you can do bad code because, hell, you can take the time! But when you have not time, any bad code is slowing you.<p>Then make this clear to the team.<p>Not be yourself the only that code review. Everyone can do it.<p>Take control when deploy. Not when your customer say so. Be predictable (ie: Always deploy in the start of the week, never at the end).
carlioover 10 years ago
I think you can get a long way with &quot;automated code reviews&quot; - basically, linting and static analysis. There are various ones out there for your language - disclaimer: I wrote one for Python called <a href="https://landscape.io" rel="nofollow">https:&#x2F;&#x2F;landscape.io</a><p>They can take a little while to get set up exactly how you like them, but once you do, run them on your CI server after every commit and it&#x27;ll output the warnings about style violations and so on. That&#x27;s basically what you&#x27;re after. It&#x27;s not a replacement for a manual code review but it&#x27;s certainly closer to what you want than nothing!<p>As other have said though, this only works if you and your team treat code quality as important and actually take the time to understand the output of the analysis tools. That&#x27;s why I like the CI approach, so that you can see if the number of warnings is going up or down over time and react accordingly. That metric is a useful one to keep an eye on to get a view on the quality of your code, and if it gets too high you can schedule some time.<p>(PS if you are interested in learning more about &quot;Automatic Code Reviews&quot; for Python, here&#x27;s a talk I did at EuroPython14: <a href="http://carlcrowder.com/pages/europython-2014-automatic-code-reviews.html" rel="nofollow">http:&#x2F;&#x2F;carlcrowder.com&#x2F;pages&#x2F;europython-2014-automatic-code-...</a> )
评论 #8575683 未加载
评论 #8567871 未加载
jasallenover 10 years ago
Honestly, the things you describe are not that bad. If they are writing code that passes the test cases, move on and be happy. If you&#x27;d described things like circular dependencies and passing brittle &quot;magic strings&quot; through multiple layers -- things that will GENUINELY cause maintainability issues I&#x27;d sympathize more.<p>I doubt anyone named it the &quot;...last6hours&quot; but then parameterized the number of hours -- so you&#x27;re changing that code anyway if the number of hours changes. If you have a requirement to parameterize that, do so, otherwise YAGNI, move on.<p>Hardcoded strings is another one. Frankly, unless you are using the string in more than two places or it&#x27;s part of a &quot;set&quot; of values, where referencing the full set is useful, you may just be making more work to do it &#x27;correctly&#x27;.<p>You reference timeline pressure. &quot;Good, Fast, Cheap, pick two&quot;. If you don&#x27;t have enough programmers for the timeline alotted, the powers-that-be have already selected Cheap and Fast. Deliver a product that does the job asked, a few maintenance iterations (if the product is one of the 30% that make it that far) will teach you want areas of code are touched a lot and need to be &quot;made maintainable&quot;
评论 #8567899 未加载
shreeshgaover 10 years ago
Give them a free copy of Clean Code[1], I started to care about my code more after I read that book.<p>You cannot sit and review each commit, the best you can do is to make them care about code.<p>[1] <a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882" rel="nofollow">http:&#x2F;&#x2F;www.amazon.com&#x2F;Clean-Code-Handbook-Software-Craftsman...</a>
评论 #8567462 未加载
DanielBMarkhamover 10 years ago
Saw something interesting at a conference a while back. If you have a few days, it might be worth trying. It&#x27;s called &quot;mob programming&quot;<p>Basically you get everyone in a room. The basic premise here is that everybody brings their &quot;A game&quot; and shares it with everybody else. One person types, everybody else decides what to type. Sounds chaotic, but as long as folks stay focused, what happens is that very quickly the entire group gets on the same page about IDE, coding standards, patterns, and whatnot.<p>I&#x27;d plan for a few days, but you might see results just in a solid morning of doing it. Don&#x27;t know.<p>Of course, you probably don&#x27;t have a few days. But -- how much time are you losing to this other stuff? Couldn&#x27;t hurt. Beats giving people a book to read.
评论 #8567349 未加载
jonkaye68over 10 years ago
My advice is that before you propose solutions, you ought to really figure out what the problem is. Is it ignorance, laziness, or something else? I&#x27;ve looked over the various responses and haven&#x27;t seen one angle -- have you asked your team about why they are not doing what you&#x27;d like? There&#x27;s a lot of advice about read this, do that, etc. but you don&#x27;t yet know why they are not following what you think is common sense. You might find something surprising by putting it on the table, or at least you&#x27;ll find the reasons they give. Then you can address those. My advice is to put this out as a question to your team and see how they react. You might even find out that some of the patterns you think are best are not, i.e., your team has a reason you didn&#x27;t think of. For example, I created a 10-element array to speed the search of a big table in which all keys began with a digit from 0-9. The more experienced guy told me that in the .NET world, the convention was to use key-value pairs instead of an array. To satisfy him, I changed it to a hash table, where I hashed the first digit. It seemed pretty silly to me, making a hash table for what to me was clearly a better approach using a simple indexed array. He had in his mind the &quot;right&quot; way to do it, eventhough I still think the hashtable in this case was silly.
Bahamutover 10 years ago
If your timelines are such that you cannot institute a process for code reviewing pull requests and you have a team of developers, then I have to question the planning by the managers.
vladimirralevover 10 years ago
I honestly think this complaint is poorly argumented. It depends on the nature of the project. When you say &quot;findeventsfromthelast6hours&quot; that&#x27;s perfectly reasonable name for disposable code or private implementation. You should only be concerned about such name if it made it to the API somewhere. Hardcoding things is also not a bad thing by itself. If I had to guess, your team is under the impression the code they write is prototype and will be rewritten anyway, not API to be consumed by other parties or doesn&#x27;t have a direction that allows them to make the proper abstractions. Sure you can demand nothing to be hardcoded, but you must remember eventually those params will have to come from somewhere. I see so many people move hardcoded values Java -&gt; IOC&#x2F;DB config or Erlang -&gt; DB not realizing it&#x27;s more difficult to reinitialize the component than to do a hot reload and speed up your development process at the very least. Whatever you do it must be for a well-defined reason. It&#x27;s also possible your team developed their own process where it&#x27;s easier or faster to fix these issues on the go rather than planning in advance.
评论 #8568596 未加载
llamatabootover 10 years ago
Clean Code and The Pragmatic Programmer are both great books, but really your team needs to be doing code review on every line of code that is going to make it to production. It doesn&#x27;t have to be &#x2F;you&#x2F; reviewing all of it. As a bonus, having your team review each other&#x27;s code builds more familiarity with the app(s) you are working on and allows all your team to learn from each other.
joezydecoover 10 years ago
Steve McConnell&#x27;s <i>Code Complete</i> might be a good resource. Could you buy a copy for each team member and take an hour each week to read and discuss a chapter? That might get you on the road to better coding practices.<p><a href="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670" rel="nofollow">http:&#x2F;&#x2F;www.amazon.com&#x2F;Code-Complete-Practical-Handbook-Const...</a>
rglullisover 10 years ago
Each week, you take one of them to be your pair. Do pair programming for 2-3 hours each day of the week. Make a wiki page with code style guide and recommendations. Each common mistake you find your pair doing, add to the wiki page. At the end of the week, you and your pair review the commits you have done <i>and</i> from a couple of others from the team.
tamersalamaover 10 years ago
They are not coders. They are partners in success. Make sure first you treat them as such. Each person might have much to give above turning specs to code (ideas, processes, improvements, automations, design, architecture, etc...). If they feel they have a stake and their efforts are accommodated (and praised), there will naturally be an improvement.
评论 #8567393 未加载
j45over 10 years ago
Sometimes it&#x27;s more about learning clever architecture than clever, or better code. Clever architecture can often help keep your code an order of magnitude simpler.<p>The issue you may run into is seasoned developers are the ones who learn this over time.<p>Conversations based around &quot;why&quot; help a team understand the importance of:<p>- creating a codebase that they will still want to &#x2F; be able to work on without dealing with poor decisions of the past, o<p>- being kind to your future self<p>- realizing not everyone has had a relationship with a codebase for 3, 5, or even 10 years and what that might look like. In the real world, existing code bases are a reality. Optimizing for that reality, instead of the clean slate that university assignments, or startups provide can also be an important light bulb.<p>- peer reviews, and teaching the why you do things a certain way are far more likely to get the lasting result you are seeking.
smanatstpeteover 10 years ago
Try having your team read these books:<p><a href="http://www.amazon.com/Writing-Solid-Code-Microsoft-Programming/dp/1556155514" rel="nofollow">http:&#x2F;&#x2F;www.amazon.com&#x2F;Writing-Solid-Code-Microsoft-Programmi...</a><p><a href="http://www.amazon.com/Practice-Programming-Addison-Wesley-Professional-Computing/dp/020161586X" rel="nofollow">http:&#x2F;&#x2F;www.amazon.com&#x2F;Practice-Programming-Addison-Wesley-Pr...</a><p><a href="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670" rel="nofollow">http:&#x2F;&#x2F;www.amazon.com&#x2F;Code-Complete-Practical-Handbook-Const...</a><p>I know these are old books and are C and C++ oriented, but it helped me a lot during my formative years and helped me transition from being a decent programmer to being a decent engineer. They are short books which are well written and not very dense.
评论 #8568354 未加载
canterburryover 10 years ago
To me, this is the difference between being a programmer and a software engineer. Software engineers think of the bigger picture and understand the overall impact of choices made in the code on other things. Programmers focus too much on just coding and don&#x27;t see the bigger picture.<p>I am sure much of this has to do with experience and having had the opportunity to learn from good software engineering teams.<p>In my teams, I have handled this with mentorship. Recognize who in the team needs mentoring and assign them a code review buddy. If mentorship somehow doesn&#x27;t work, you just have to manage those programmers and put them under tighter supervision. However, you can&#x27;t expect much change until you set and communicate expectations. Be clear on what you expect and review against those benchmarks.
StevePerkinsover 10 years ago
What I&#x27;ve seen work is a combination of code reviews and ongoing continuing education.<p>----- CODE REVIEW SIDE -----<p>This can include automated tools, human interaction, and computer-assisted human interaction. To start with, pick a set of command code standards and style guidelines. Google has nice ones for many languages that you can use as a starting point (<a href="https://google-styleguide.googlecode.com/svn/trunk/" rel="nofollow">https:&#x2F;&#x2F;google-styleguide.googlecode.com&#x2F;svn&#x2F;trunk&#x2F;</a>).<p>Secondly, enforce them through automated tools (e.g. in a Java shop, these might include PMD, FindBugs, Checkstyle, etc). Have everyone install the IDE plugins for those tools (along with your common config). Incorporate them into your continuous integration build process. Perhaps put in place a static analysis tool like Sonar to send regular reports on code issues.<p>The human element would start by having someone review committed code before it&#x27;s allowed to be merged downstream. Git&#x27;s pull requests, along with diff view systems like GitHub&#x27;s, make this easy... but you can use workable practices with Subversion or whatever also.<p>There are limits to &quot;pull request&quot;-based code reviews, though. When change sets grow too large, it&#x27;s difficult for the reviewer to understand the high-level vision for the changes. You start reviewing the trees, rather than the forest. So I think you still need periodic in-person code reviews, to walk through the state of a codebase at certain milestones and discuss higher-level issues.<p>----- CONTINUING EDUCATION SIDE -----<p>The thing that I&#x27;ve seen work best here is a regular, ongoing lunch-and-learn type series. Take any of the standard code quality treatises (e.g. &quot;Pragmatic Programmer&quot;, &quot;Code Complete&quot;, &quot;Clean Code&quot;, etc), and tackle a chapter per week. Better yet, split up the chapters and have the team members themselves present a chapter. It&#x27;s great experience for them (if they&#x27;re not TOO freaked out by public speaking), and you&#x27;ll never learn something as deeply as you do through the process of teaching it to others.<p>The problem with lunch-n-learns is that you MUST have buy-in from management to make them a serious and ongoing part of your team culture. When deadlines are tight and there are fires to put out (and when are there not?), a lot of companies are quick to cancel that week&#x27;s lunch-n-learn. When that happens, they lose traction and fall apart.
euphemizeover 10 years ago
Most tips here are very good, suggesting books (&quot;Clean Code&quot;, etc.), team huddles and showing them the way. But you seem to be implying that they could be great coders - if they wanted to.<p>I can&#x27;t help but feel like these programmers aren&#x27;t very passionate about their code, and that&#x27;s what you need to help them with. If they&#x27;re naming variables wrong and hardcoding strings, but understand the asymptotic running times of what they&#x27;re doing, I&#x27;d go on a hunch and say they&#x27;re bored or unmotivated.<p>I say this because I recognize myself in some of these behaviors - when I want to get rid of something and don&#x27;t care much about the project. &quot;What&#x27;s the fastest shortcut I could take to get me out of here?&quot;.
thothamonover 10 years ago
Lots of good advice, but I suggest having the whole team review each others&#x27; code 100% of the time. In other words, each commit gets a random or rotating selection of two people who review the code.<p>Reviewing other people&#x27;s code is almost as valuable as being reviewed. Even if it&#x27;s not perfect all the time, it builds a good culture of coding and gives your developers valuable experience.<p>The culture of the code review should be a careful examination with Q&amp;A. You need to take as long as you need to get it right. This is a great investment in your product and your team that will pay off starting right away and extending into the long term.
codingdaveover 10 years ago
It is your team, with your own culture, so I would not presume to tell you exactly how to do it, but I can give one general bit of advice:<p>Communicate.<p>Tell them what you are seeing, and just as importantly, why it can be a problem. Many times, beginner mistakes arise simply because they never have been exposed to the reasons for them being &quot;mistakes&quot; in the first place. So teach them. Nicely.<p>Think of them as students, and you are their teacher&#x2F;mentor. Help them grow, support them and act as a resource so they can do their own jobs better. Treat the whole experience as an opportunity for growth, not a judgment on their skills.
jtwebmanover 10 years ago
Below are a few things that could help but you said it yourself. If you don&#x27;t have time to review then my guess is you are also pressuring the devs for time. Sometimes to make your deadlines they might have to cut corners. Maybe you can switch to a more agile process and instead of crazy deadlines you ask them what they can get done the next 2 weeks (correctly).<p>- Setup process for them to review each others commits (Code Reviews)<p>- Add a tool like FxCop, JsLint or JsHint to the build and commit process<p>- Hire more senior programmers that they will look up too.<p>- Paired programming<p>- Be a team and do stuff as the team (We are not factory workers)
eccpover 10 years ago
Point them to some coding guidelines for the language&#x2F;platform which you&#x27;re developing.<p>For Clojure development: <a href="https://github.com/bbatsov/clojure-style-guide" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bbatsov&#x2F;clojure-style-guide</a><p>For Scala: <a href="https://github.com/alexandru/scala-best-practices/" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;alexandru&#x2F;scala-best-practices&#x2F;</a> or <a href="http://docs.scala-lang.org/style/" rel="nofollow">http:&#x2F;&#x2F;docs.scala-lang.org&#x2F;style&#x2F;</a>
arvanhalleorgover 10 years ago
Technical books. Code videos from stuff like Google I&#x2F;O and friends. Coding conventions. Peer programming. Use pull requests and assign them to another member of the team. It won&#x27;t fix it overnight, but you&#x27;ll notice the changes as they come in. Also, you might want to let them learn to write better code. People adapt best when you lead them, instead of getting them to do it. Everyone was a beginner and not everyone was exposed to the same amount of code or scenarios.
projectileboyover 10 years ago
I spent 10 years &quot;coaching&quot; (that word... blech...) teams, and from my experience there&#x27;s no easy answers. What works for one team at one point in time might be horrible for other groups. Having said that, here are some things that have worked for me:<p>* If some of the people on the team have more skills than others, you could try asking people to pair program for part of the day. You could try setting up a lab space for this if people are interested.<p>* Weekly brown bag sessions where you talk about a technical topic of interest. Let people on the team nominate ideas. Do it over lunch and have the company have food delivered. The better the food, the more people will want to attend.<p>* You should get an automated build in place, and encourage people to do some level of automated testing if they aren&#x27;t already. Some people take this a step further and use the automated tests to help drive out the design (Test-Driven Development by Kent Beck is a good book on this topic).<p>* You could try starting a technical book club where people read a chapter a week, and then get together and discuss it over lunch. Given your situation, I&#x27;d strongly recommend starting with &quot;The Practice of Programming&quot; by Kernighan and Pike. Again, it helps a lot to have the company get good food delivered.<p>Don&#x27;t make a million changes at once. I might start with the book club if I were in your position. None of this stuff will magically transform your team, but these kinds of things can start creating a culture where people start to care more about the quality of their work. You&#x27;ll encounter people who have very strong religious feelings for or against any one of the things I listed above, usually based on some past experience. I&#x27;ve seen each of the above succeed big and fail hard with different groups. Just try what seems to make the most sense for your team.<p>One last note: when you try things, don&#x27;t do stuff in fits and starts - talk with the team about what you&#x27;re going to do, see if there&#x27;s buy in, and if there is, commit to trying it for, say, four weeks. After the four week period is done, talk with the team about whether or not it&#x27;s working for them, and if they&#x27;d like to stop or continue. Over time, you can add&#x2F;remove&#x2F;change more things in the same manner.<p>Good luck!
nXqdover 10 years ago
Short term solution : Lead by example, a good chance that they can learn from those and maybe copy them afterward. But the code quality will improve. This can take your time but as long as you have several good examples, you can reuse those. Long term solution: Encourage them to watch conference and good books like Clean Code, or TDD books. Those are incredibly good. Maybe they are not interested in at first, and never, but those who want to be better will become ones.
lazyjonesover 10 years ago
You absolutely need coding standards (the stricter, the better, as long as they make sense), especially with languages like C or Perl where you can shoot yourself in the foot with what looks like particularly &quot;smart&quot; coding.<p>I&#x27;d also recommend choosing a strict language with useful conventions like Go (www.golang.org) if you have the possibility to switch. If will prevent many (not all) headaches in the long run, even if it&#x27;s not immediately obvious.
ainiriandover 10 years ago
If you can spend some money I recommend hiring someone good to give some lessons, some hours per week. Then there is also the option to give those lessons yourself.
评论 #8567369 未加载
jwitchelover 10 years ago
1. Smaller commits. Break the project down into smaller tickets and have them check-in more frequently.<p>2. Rotate who reviews so everyone gets a chance to review everyone and put yourself in the rotation.<p>3. Lead by example. Write some code into production and submit yourself to review. Everyone writes code, everyone reviews, everyone gets reviewed.<p>4. Each review find just one thing to refactor and let them know they should be looking for the same thing in other people&#x27;s code.
rovolutionaryover 10 years ago
You can set up a weekly code review where you take turns letting each developer present a piece of code they wrote to the team, and then discuss and give feedback about that code.<p>Also direct them towards resources where they can learn clean code practices. Perhaps institute a monthly &quot;book club&quot; where you select books about good coding practices. I would suggest starting with Clean Code by Robert Martin
arisarnadoover 10 years ago
I think you need to come up with a coding guideline. After that, you review&#x2F;discuss it with your team.<p>Also, you may need to create a &quot;checklist&quot; and encourage your team to follow it as a way of self-check on their work.<p>In this way, you will be able to concentrate your reviews on important things (such as logic, etc) since the trivial errors were already eliminated.
feynover 10 years ago
I’ve been in a technical lead position across 5 companies over the last 10 years, and after trying just about everything written or spoken about influencing team code quality, I finally found a formula that works:<p>1) Take on the most brutal coding tasks&#x2F;features yourself. You will have to cherry-pick the upcoming work to look for things that just about any other engineer would freak out about if they got it assigned to them.<p>2) Knock it out of the park in terms of time-to-market <i></i>and<i></i> code quality. You need to do both, to eliminate the concern of, “We don’t have time to write quality code.” The code should be so clean, so well factored, so well unit tested, that you would be comfortable getting a code review from Martin Fowler, Kent Beck, and Bob Martin all at the same time. This also implies that you’re read their books, and would know how to pass their code review.<p>3) Call a code review with the entire team, and aggressively code review your own code. There is always room for improvement in any code, depending on hour you interpreted current requirements and future needs. This has to include phrases like, “I didn’t know what to do here so I…”, “I really which I had more time to change this to…”, “I went back-and-forth on how best to abstract this, but ultimately I chose this abstraction because.” Basically, you’re looking to show them the worst possible code review on the best possible code.<p>4) Depending on the personalities involved (including your own), decide how you are going to coach each engineer 1-on-1. No two people are alike, so you will need to dial your approach to each person. Some people will thing you are a show-off, some will think you intimidating, as well any another other human emotion and concern that causes someone to not seek out or not take advice. This is where your emotional IQ and communication skills will be tested.<p>5) When you start coaching them, don’t go after every single flaw. Try to find the underlying root cause of the problem in the code, and address that. A common problem I run into is the people just don’t understand OOP but think they do. I usually have to coach them on basics like encapsulation and cohesion, working them up to design patterns, and further up to domain modeling, all the while instructing on proper implementation technique (such as unit testing.) Once they have the fundamentals in place, you can begin fine-tuning certain implementation patterns.<p>6) Over time, at least one member of your team will get good. With their permission, publicly review their code. In this, you want to be very positive: “I like what they did here…”, “That’s a good way to encapsulate that problem”, “That’s a powerful abstraction, especially the way it’s used…” This Rite of Passage should then become what other engineers are striving for, as only the best engineers are getting public praise fests.<p>This basic formula has served me very well with my current team, in that they are one-upping themselves on code-quality. Still, however, I take on the most grueling coding tasks to set the example and lead from the front. This acts to continue to demonstrate my commitment to code quality, as well and lets the team know I would not ask them to do something that I would not do myself.
blahbapover 10 years ago
As for books, &quot;Clean code&quot; by Robert Martin is an obvious choice. It covers the fundamentals of good, clean code.<p><a href="http://www.barnesandnoble.com/w/clean-code-robert-c-martin/1101628669?ean=9780132350884&amp;itm=1&amp;usri=9780132350884" rel="nofollow">http:&#x2F;&#x2F;www.barnesandnoble.com&#x2F;w&#x2F;clean-code-robert-c-martin&#x2F;1...</a>
avigesaaover 10 years ago
Depending on the language and context, an explicit method name like &quot;findEventsFromLast6Hours&quot; isn&#x27;t that bad. If it&#x27;s just a private helper method, I&#x27;d let it pass.<p>Empirically, I&#x27;ve found that methods with ambiguous parameters (e.g. &quot;findEvents(6)&quot;) are a much bigger problem (event amongst senior programmers).
评论 #8570257 未加载
yeezulover 10 years ago
I highly recommend (to everyone here for that matter) the book Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin. It deals specifically with the mistakes you&#x27;ve mentioned in your post, such as hardcoding and naming functions.<p>Great easy read. Cheers
lukesanover 10 years ago
I would start with Refactoring by Martin Fowler. For me this is the quintessential book when it comes to basic software design principles. It introduces code smells and tells you step by step how and why to improve your code design
alwendtover 10 years ago
If some gross code gets into the tree, nominate it for a code reading with a team of three or four people. This helps a lot because the code gets improved and the reviewers&#x27; styles also improve.
tgreenhawover 10 years ago
Start by watching &quot;The Downfall of Agile Hitler&quot; <a href="https://www.youtube.com/watch?v=l1wKO3rID9g" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=l1wKO3rID9g</a>
julie1over 10 years ago
Forget all the craps about new silver bullet mantra (peer review, agile and peer coding and shit).<p>Just put them on mandatory level 2&#x2F;3 support 20% of the time for the code that is written.<p>When you have to maintain code you fully grasp the concept of «well written code»: just code that is easy to maintain.<p>And every month try to have them talk about their top 3 reasons that makes them loose time when fixing code.<p>My fear with peer review is that it is very artificial, what I like with maintaining code is that you see your mistakes sometimes due to trying to write «clean» code.<p>Magic number deserves a bullet in the kneecap, but magic numbers disguised as factories are worse. A good code is a code where mistakes are obvious. Value these coders.
alwendtover 10 years ago
Nominate crufty code for code readings. They are great to improve the quality of the code and that of the reviewers.
dharma1over 10 years ago
do a half day workshop with your team going through typical mistakes, how to avoid them, and how to write good quality code - after that there should be no excuses.<p>pull requests also essential but it&#x27;s still admin overhead for you to review everything
devb0xover 10 years ago
PRs work. Pull requests serves to manage quality but also can find issues.
thegeniusover 10 years ago
the best way you can improve the quality of code is to LEAD BY EXAMPLE. you&#x27;re not alone in that you&#x27;ve been given a leadership position in a circumstance outside your control, and it&#x27;s naive to think that even if you were given your pick of the litter, that they&#x27;d all be A players who respect you and don&#x27;t want your job, have issues with your quality, etc.<p>You absolutely cannot control people. The only way to get people to do things, and i mean the ONLY way is to get them to WANT to do it. Therefore, you have to ignore the people who aren&#x27;t cooperating with you and focus on the one&#x27;s who do. Treat them like gold and be willing to make compromises with your quality standards because they will not be the same as yours. Then, as you make inroads on the project together, the rest of the team members either have a choice to get on board or get left behind. It is that simple.
a3voicesover 10 years ago
Good coders should start new projects. Mediocre coders should maintain projects.
wapsover 10 years ago
I work at a place that requires code review and has automated checkers for &quot;code quality&quot;. Let me tell you the obvious : the best code I see has these problems, because the best code is the best code because it uses the language to it&#x27;s maximum effect, which often precludes having perfect &quot;style&quot;. The best code is tested in functional ways, which means that it doesn&#x27;t have &quot;good coverage&quot;, nor does it really use unit tests more than a little bit.<p>And the worst code I see, by people who learned to code a month ago or worse and don&#x27;t know any algorithms (but feel like they know better than people who&#x27;ve studied algorithms and languages for years) almost without exception perfectly styled. It contains moronic errors like swapping variables around (because these programmers do not know how to use the type system), it contains 5 unit tests for every single little function, because that increases the lines of code metric that is so universally used. And the reason for half the lines of good is &quot;good practices&quot;.<p>Here&#x27;s how you recognize good code : firstly it is not possible to shorten it without causing a MAJOR disaster in the readability area. Every concern is properly separated out into it&#x27;s own pieces of code, and aside from the (short) main function there is very little single-purpose code. The typing system is used well. Prices and amounts are NOT the same data type, for example, and cannot be obviously switched. Unit tests exist for core algorithmic pieces only and other than that there are system tests that confront the code with real-world situations while running almost the entire program, ideally under heavy load with half the backend unresponsive, and has a statement that says the test fails if it takes longer than 1&#x2F;10th of a second. It implicitly follows and beautifully implements a design document that is not written in word, but in a 10 to 15 line comment on top of the file&#x2F;class.<p>Note the issues : 1) hardcoding things 2) naming mistakes<p>Both of the issues you complain about can be fixed mechanically or with absolutely minimal supervision through refactoring. Yet next to all the comments below suggest DOUBLING the manual effort needed to get code into the repository. While automated fixing might be problemating, writing linters that detect these problems is trivial.<p>Unless of course the problem is that you feel that you need to fix how others program because you &quot;know better&quot;, but can&#x27;t actually write code checkers. In this case, why are you leading them ?<p>So well in that case I&#x27;d advise a slice of humble pie, and a compilers course.<p>&gt; I review commits now and then and find some of these issues - but due to the nature and timeline of the project cannot do it for each and ever commit of course.<p>You sound like someone with an MBA. A programmer would recognize this for what is is : a problem screaming to be automated. Code commits can be made dependant on code checkers succeeding - just write the ones you want&#x2F;need. Can&#x27;t do that ? You&#x27;re not a programmer - or at least not a good one - and stop whining about how difficult programming is - learn it first.