What is the size of the method/function "screens" is considered normal?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
10 views
Several times I saw habré comments where it was stated that if your methods/functions have a size (in rows vertically) more than x * screen size (where x = 0.5..1) that you are a bad programmer writing bad code.


How appropriate this statement? I write on ASP.NET C# to the enterprise, and some methods take two or three screen because it's all sorts of checks on all sorts of wacky conditions, data access, output and formatting, etc., which would be happy to break into smaller pieces, but it will not look very don't you for example to assign values to controls of 1..10 in one method and 11..20 in the other. I understand when it is appropriate to highlight some action in a separate function, but do not always succeed, as I wrote above.


In General, do I need to worry about it or you can score? How much great function you have? Especially interested in the opinion of web developers .Net.
by | 10 views

7 Answers

0 like 0 dislike
Then one abrowser generally admitted that the code directly on the mobile phone writes... In his case at all hard with this issue to dock
by
0 like 0 dislike
The point of this rule is to method was obetrim at a glance.
\r
Maybe the method of just five lines, but 4 levels of nesting such long expressions that need to spend half an hour to understand. So the point is not the number of rows and the total complexity of understanding the method.
\r
In addition to the number of rows is the length of the lines, it is also better to limit. I have been writing in C# and often do within the code indentation, blank lines, insert regions (#region). Margins slightly increase the number of lines, and the regions significantly reduce (in minimized state).
\r
In addition, I have a widescreen monitor rotated 90 degrees, so that one screen includes two usual :)
by
0 like 0 dislike
Long functions/methods I in the General case, find relevant perhaps only if some nontrivial mathematical calculations. A case of mathematical functions/methods longer than 50-60 lines (pair of screens) are already starting to strain.
\r
However, much more annoying than the number of rows and their content :)
by
0 like 0 dislike
Compactness!
First rule: functions should be small. Second rule: functions should be even smaller. I can't scientifically substantiate his claim. Do not expect me links to studies showing that very small functions are better large. I can only say that I'm almost four decades, wrote the functions of all sizes. I had a chance to create horrible monsters in 3000 rows. I wrote countless features with length from 100 to 300 lines. And I wrote the functions from 20 to 30 lines. My practical experience has taught me (at the cost of many trial and error) that the functions should be very small. <...> However, the strings must consist of 150 characters, and the functions of 100 lines. It is desirable that the length function does not exceed 20 lines.
Robert Martin, "Clean code" (though the examples are in Java, I think that the book is still useful).
by
0 like 0 dislike
Well, it's not an absolute rule.
\r
If the size method is more than a certain limit — it's just a signal that something is possible. not so. But it may be a false alarm.
If in doubt (as now) — ask colleagues, atribuit.
\r
By the way, formatting can be assigned to the template engines.
by
0 like 0 dislike
If the code is repetitive, you and a long function to write. I begin to wonder if more than two screens (C). If anything, the source is a function of Python and 2000 lines :) While Python is a very good example of C-code.
by
0 like 0 dislike
so that you can describe with words, making method, and to hold it all in memory. IMHO, no more than 10-20 lines.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
28,032 users