-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about detected function length #8
Comments
I read through your documentation on why I guess my question is if your how is the best way. |
Hi Jeffery @jdhitsolutions , Here is how
The reasoning behind this comes from how other code metrics tools work, for example :
But this is arguable for many reasons :
For all these reasons, I'm happy with NOT deciding alone and arbitrarily what is included/excluded in the Lines of Code metric. I think it belongs to the PowerShell community to decide that, and once we have some kind of consensus, I would be very happy to change the code in That's why I'm glad you raised this subject and your opinion/suggestions are very welcome. Does this answer your question(s) ? |
That helps. I might have to disagree about comments. Properly inserted code comments are valuable and something the PowerShell community recommends. Remember, many people writing or using PowerShell modules aren't developer oriented and using comments is considered a best practice. I would never assume a lot of comments means the code is poor. I would not penalize for it. The whole "a shorter function" is better metric seems completely arbitrary. If I need 200 lines, excluding any comments and blank lines to properly achieve a result, and my code is well formed, then that's what it needs. My function is completely healthy. Or here's another illustration. Suppose I need to include a hashtable in my code. It could be written like this (using simple values to save some typing:
With real values this could be a very long line and something that I find hard to read. I prefer and recommend this:
Obviously I've increased the number of lines of code but I would say this is "healthier" because it is easier to read and troubleshoot. |
I also have a question on how you determine what a proper function length is. From your blog post I appreciate the notion that sometimes you need to refactor. But sometimes a function is long by design. For example, in a function I tested I get 78 lines of code. But if you don't count commented lines or my lines of Write-Verbose (or someone might use Write-Debug), then I'd get a line count of 60 which your analyzer would report as "better". For that matter if don't count white space, my function gets down to 46 lines of actual code that does something.
I completely understand where you are going with this metric but I'm trying to figure out how it is being determined and if that is the "best" way.
The text was updated successfully, but these errors were encountered: