Hi the recommended naming convention for function:
Don’t repeat parameter names in the function name. For example, use
cube(int number) instead of
cubeNumber(int number), or
printStudent(String name) instead of
Is there any disadvantage in doing so? Or why we want to do that?
@suragch any suggestions?
Let me start by saying that’s it’s not wrong to repeat the parameter name in the function name. However, there are a few reasons to prefer not repeating:
- All other things being equal, short names are easier to read than long names. Long function names are good when they are descriptive, but redundant information doesn’t convey additional information. Since Dart supports named parameters, it’s easy to make this information visible to the reader. Languages like C, C++ and Java don’t have named parameters so it might be better to include the parameter name in the function name when programming in these languages.
- Longer function names make it more likely that a given line of code will have to likewrap when formatted. Code that linewraps is generally harder to read that code that appears on a single line.
As a general rule, choose the function name that is the most readable.
Thank you, very clear explanation.