So there are quite a few components to code optimisation and refactoring of code.
The largest indicator for me is cyclomatic complexity, I work on the bases of anything over 7 should be refactored.
I want other methods of detecting code issues with large projects that other people use, specifically with SharePoint.
Regards,
Hugh
Hi Hugh
Over the last few months I’ve been doing a lot of code reviews for a clients external partner solutions;
1. I use SPCAF/SPCOP to point towards areas of SP specific bad practice
2. Code Analysis (VS and Resharper) including complexity/LOC to point towards code that may be ‘bad’
3. Make a point of looking at common points of failure/bad coding such as webconfig mods, feature receivers, event receivers, I also look at feature manifests looking for scope mismatches
I decided pretty early on that I could never review solutions enough to warrant them fit for purpose, so now when I do these I’m looking for anything that might damage the clients farm; performance, stability, availability etc.
I guess your MO for conducting internal team reviews might well be different though
I know right, just wish it wasn’t such rough terrain.
I understand the issues in a little more detail now, it also helps me understand what I am looking for.
Basically the ability to create design patterns and map them together with ratings on which is the most efficient, with a way of detecting a pattern that’s used and suggesting an alternative.
I think the best version of this would be “community” code analysis which allows you to submit code segments against design patterns or something of the ilk which would translate that into an alternative pattern. This would require some sort of CA for speed and evaluation of objects.
Okay, sounds reasonable.
I would go with custom rules for FxCop/SPCop/SPCAF, then. The issues is that there is no such a tool which knows specific API set including say asp.net, or SharePoint, or SAP, or whatsoever.
API set is the most challenging thing if we work under the particular platform, such as SharePoint. We has the same challenges with CRM, for example.
Right now, several people and I have teamed up and working on SPCAFContrib: we use SPCAF/SPCOP as an infrastructure, and extending it with the new rules to address the common pitfall both on XML/code. It includes poor performance, potential null-references issues, potential bad practices and so on.
Finally, we stumbled LOTS of challenges. As you mentioned, “Code with poor CA and CC metrics can often be poor performing and it is very rarely there are no ways around it” which basiacally means “It depends”, and leads to “some cases have to be checked manually”.
For example, we tried to implement “try-catch-finally” rule, but there are SO MANY cases where you might have empty catch statement what we almost gave up. Still working and researching, but really – some cases so hard to check/implement. Also, for examples, a good exception handling inside web controls, web pages, web parts – this is tricky thing, really. Some cases might be checked with automated rules, and most of them – not. So it leads to the false-positives and meaningless warnings, as you mentioned.
To sum up, we see that as trade off between several things:
- current code style of the current team
- manual checking of the doubtful code pieces
- tending to have no “false-positives”
- extending SPCAF/SPCOP to our needs
Mixing up these ideas to the good trade off might help to address common pitfalls and issues.Â