Abbreviation methods / variable names?

This is considered to be a bad style for using long descriptive method names such as "neighboring LocationsByState ()", and if so, would it be better to shorten it to something like "adjLocByState", which is definitely shorter, but also less readable in mine opinion

+6
source share
5 answers

Do not make me think.

When I read your code, if I need to stop and think about what the method name may mean, it usually means that the method name is incorrect. Longer method names are preferred when it adds a useful context to the method.

+10
source

Keep in mind: code reads 10 times more than it is written.!

You really write code that is often read over and over again. The more meaningful your names are, the more comprehensible the code is.

You declare classes, fields, methods, variables, and many others. You think about them, you develop a well-defined structure. You make tough decisions all the time. The names you give your entities (classes, fields, ...) reflect all your thoughts on this subject. They reflect the intent of your code.

Conclusion: names are the most important properties of your code. So, you should always think deeply about the names that you give your variables, methods, etc. And you should not always cut them in any way.

+2
source

The longer version is more readable, and the code itself is documented. So a good method is name = responsibility method. Adj can be understood as being custom or related etc.

+1
source

When writing code, basically two rules follow:

  • It should read like plain text that the human eye is used to from books and the media (so adjLocByState is wrong)
  • Maximize brevity, use programming methods - code conventions and default states. They can be used when some of the running terms appear too often.

So, adjacent LocationsByState () are read well, but it can be shortened to:

adjacentLocations()

which by default will return locations by their state and adjacentLocations(STATE) or chains using the free interface , which allows more options for having criteria: adjacentLocations().by(STATE) . STATE is a member of the enum LocationCriteria here.

So, at the end of the day, it might look like this:

  • adjacentLocations()
  • adjacentLocations().by(STATE)
  • adjacentLocations(STATE)

Of course, there is a sacrifice of time spent coding the 2nd and 3rd forms.

+1
source

Its part of the documentation.

Usually everyone likes to write code in two phases before committing:

  • Implementation
  • Documentation

Example (step 1):

 ObjectOutputStream oos = ... List a : ob.getSOE(); for(Object a: b){ oos.writeObject(a); } 

Then phase 2:

 ObjectOutputStream stackOverflowElementOuputStream = ... List stackOverflowElements : ob.getStackOverflowElement(); for(Object currentStackOverflowElement: stackOverflowElements){ stackOverflowElementOuputStream.writeObject(currentStackOverflowElement); } 
0
source

All Articles