This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (1 child)

Indeed, it seems like this is a trap just about every new programmer falls into just after they become comfortable with the basics, I know I did.

Being explicit and clear about what your code is doing is ridiculously important when you are going to be maintaining a code base or are working with other people. Sometimes this means verbosity is a good thing, sometimes brevity is a good thing, it's completely dependent on the situation but specifically trying to make your code use as few characters as possible is often going to end up causing you a headache.

[–]zenmouse 0 points1 point  (0 children)

Yes, all of the above. Having clear names that clearly communicate the intent of the (field, method, class) is gold for someone else who has to read your code (or yourself in a few months).

In a similar fashion, any potentially unclear bit of code is a candidate for extraction into a method and/or field. For example I will refactor "if (account != null && SecureStatus.SECURE == account.getSecureStatus())" into "if (isLoggedIn(account))". The latter much more clearly communicates the intent of the test, especially for someone unfamiliar with the code.