Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is a function name too long?

People also ask

How do you know when a function is too long?

Essentially, if your function is larger than what fits on your screen at one time then your function is too long. There should be no scrolling required. There are some benefits to keeping your functions at this length: It is easier to see the algorithm as a whole when you can see it all together.

How long is too long method name?

It is 65535 characters to be exact. The same rule applies to the length of the class level variables as well (but not to the local variables - the one which is defined inside a method).

Is it okay to have long variable names?

Most functions only contain two or three variables, so a long name is unnecessary.

Should function names be as short as possible?

Function names should be as short as possible. Calling a function and defining a function mean the same thing. A flowchart shows the hierarchical relationships between functions in a program. A hierarchy chart does not show the steps that are taken inside a function.


If there's a shorter, but yet descriptive way to name the function, then the function name is too long.


When you can't read them aloud anymore without taking a breath in the middle =D


A function name is too long when it starts to either over-describe what it does, or when it hinders readability of the code.


  1. If you have to scroll to the right to read it.
  2. Describes the 3 or more things that is does - it shouldn't do that many things.
  3. Your boss thinks its too long.
  4. It's longer than the code itself.
  5. It starts with Get, just like 500 other functions.
  6. Nobody wants to use it.
  7. There is another function that does the same thing with a shorter name that users understand.
  8. It can be made shorter.