-4

When I see a question like this I often ask myself if it would be appropiate to tell the person that his code does not match the Java Styling Conventions. I'm not talking about brace or indent style, as it compiles down to the exact same.

However, something like

  • Wrong method name case
  • Wrong variable / field name case
  • No data encapsulation / public fields without getters

really bothers me as it does matter in some cases and could be bad.

Example: The method AddNewListings should instead be addNewListings to match Java's "lower camel case".

Is it rude, inappropiate, or bad in any way to tell the person?

5
  • 1
    Point it out only in situations where it actually does matter. For example if the code actually fails to compile because of the incorrect capitalization (which in turn leads the question to being closed as a typo question).
    – BoltClock
    Mar 23, 2018 at 10:30
  • 3
    I think leaving a comment that points out that the naming style is against common code style (what you named) is OK.
    – Uwe Plonus
    Mar 23, 2018 at 10:40
  • 1
    Not problematic or rude, but can be very noisy and distract from the question's real issue / answer's real point. Every post can become an argument the advantages of one convention over the other.
    – yivi
    Mar 23, 2018 at 11:15
  • 7
    If you are providing solution of code based on questions code, apply those examples and add some very brief mention about those changes. In this case you are providing proper example and you leave to that person to either accept or disregard it but you did you part in accepted manner that should be obstacle or moving away from subject topic. Mar 23, 2018 at 12:18
  • @MiroslavRanisavljevic That would be a good answer for this question.
    – BSMP
    Mar 23, 2018 at 15:35

3 Answers 3

5

If you are providing a solution of code based on the question's code, apply those examples and add some very brief mention about those changes. In this case you are providing a proper example and you leave to that person to either accept or disregard it, but you did your part in an accepted manner that shouldn't be an obstacle or departure from the subject topic.

3

Java does not care what convention you use so long as you are consistent. In all frankness, when it comes to questions, neither should you.*

Don't feel bad about using good conventions in your answer, though.

*: In cases in which it makes the code truly unreadable, then a polite comment is sufficient. However, if the problem is easy to understand irrespective of the conventions used, there's no cause to make mention of them.

1

Is it rude, inappropiate, or bad in any way to tell the person?

It is fine to give extra advice, as long as it is based on objective reasons, going beyond mere personal preference (official conventions are good enough support). It helps to clearly indicate the advice is tangential to the actual question. In such cases, for instance, I often begin comments with "On a tangential note [...]". Adding a P.S. to an answer and paraphrasing the OP's code (as Miroslav Ranisavljevic suggests) can also work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .