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
SPCAF definitely is a good basis for code analysis I agree and it has a lot of relevant rules, but it wasn’t best practices I was aiming at. It was optimisation for the most part and testing for the next as well as maintainability.
Our team for example has a single toolset for a target version of SharePoint for any common functionality, this is something that gets refactored often.
CC ( I will also use this from now on and CA for Code Analysis) is a very useful tool which can give markers for each of those issues.
What I am really looking for is something that will spot “hidden” issues with code. For example an accidental reference to a object when its parent is disposed.
It feels like an extension for resharper would do the trick to spot known issues or possible known issues. SPCop shows a lot of these up when it shouldn’t IE when you extend the SPList object with new functionality it throws a multitude of errors that are meaningless.
There are also other methodologies of refactoring which at the moment we use componentisation as a main methodology of breaking things down and rename method to allow us to not have to do as much refactoring in the first place.
But also code optmisation is about the speed of code as well as maintainability. Code with poor CA and CC metrics can often be poor performing and it is very rarely there are no ways around it. Also there are better design patterns for some tasks that can be spotted (Resharper does this on occasion especially with linq) and this can help code readability and speed.
This is a subject I feel requires a lot more thought.
I would definitely suggest SPCAF/SPCAFContrib for the deep and custom analysis of both XML/SharePoint object model.
On the other hand, cyclomatic complexity might not the critical as code works well with both high/low cyclomatic complexity. So, unless “developers just want to be perfect”, in the real life and project it might be quite hard to get the budget, time and, finally, people who understand what CC is 🙂