Last week someone asked me to email them a list of tips for improving code quality and I thought it would make a nice blog post; I picked just three areas and only made a few bullet points for each one:
Automated code quality
- Resharper + StyleCop Plugin – This is a fantastic product that will both spot common programming mistakes and suggest improvements. With the stylecop plugin it will enforce the Microsoft formatting standard ensuring code consistency and readability.
- FxCop – Scans your compiled dlls for known issues recorded by Microsoft, it’s a bit noisy but some of the potential problems it spots can be incredibly useful.
- GhostDoc –Auto-generates and scaffolds out your comments based on the code naming, so a method called GetCustomerRecords will create a comment that simply says “Gets the customer records”. Still requires you to fill in the comments but does the initial legwork.
- MCPD training – Sadly rife with cheating due to the answers been freely available online the MCPD certification are still a really fantastic certification, not so much for the depth of information but rather the breadth.
- Transcender – The intention of Transcender is to help people prepare for exams but I would recommend using it for people who have already passed. It will often show up gaps in their training and areas they need to work on.
- Blogs – I would recommend that every developer has a rss reader which they check every morning, my personal favourite is google reader. Below are some of the blogs I’d recommend:
- Books – A great idea is to setup a company library and regularly stock it with new books on topics like Linq, MVC and C#/SQL/HTML reference material etc. The one book I would recommend as a “must buy” is Code Complete (2nd edition) by Steve McConnell, I couldn’t recommend it enough.
- Knowledge sharing – Naturally over time developers tend to become the expert, or go-to person for a particular topic, MVC, SQL or maybe an internal system. It’s great to have someone with a deep understanding of a topic but all too often this results in everyone else having zero understanding of it. Regular knowledge sharing sessions where that expert gives a 15 minute presentation on the topic helps everyone fill in the gaps and prevents disaster occurring if that expert leaves or is unavailable.
- Code review – Formal code reviews can be quite time consuming and by extension expensive, in situations where this isn’t possible you can still encourage quick peer review of code. Before checking in the final version of their code each developer should ask a co-worker to look over their work and see if they can spot any areas for improvement. Quite often glaring mistakes can be spotted that are otherwise invisible to the person who wrote them.
- JMeter – Stress testing during development is a must to ensure that performance issues don’t creep into a project only to be found after launch. It will also help you estimate infrastructure requirements and meet any agreed upon response times.
- Continuous Integration – CI is a broad topic but I’ll steal the definition from Wikipedia: “CI implements continuous processes of applying quality control – small pieces of effort, applied frequently. Continuous integration aims to improve the quality of software, and to reduce the time taken to deliver it, by replacing the traditional practice of applying quality control after completing all development.”
- Watin – Automated testing is typically restricted to just integration or unit testing of code. Watin allows you to write tests in C# that check the webpage itself, at the minimum I would recommend a recursive Watin test that checks the entire site for 500 errors and XSLT rendering warnings.
- Nunit – Since Sitecore is so tightly coupled to the HTTP context it’s difficult to write true unit tests but integration tests can be just as useful. Coupled with Watin running on a dedicated build server you can see real leaps in code quality and a massive reduction in unseen problems been deployed to production servers.
The topic itself is massive and many books have been written on it (as I mentioned my favorite been Code Complete by Steve McConnell), make sure you post your favorites that I missed in the comments😉