2

There are many ways to write working code that does the same thing, but some look better than others. For example,

function F(){ var x = 3;
              var y =2 ;
              var z= y +x;
console.log(x+" " + y +" " +z);}

is perfectly good code and will produce no errors, but nobody writes code like that. My question = if I happen to not know whether that code is styled correctly / what would be correct, would that be a question for StackOverflow, another StackExchange site, or another website altogether?

3
  • 7
    Code formatting style is an opinion-based decision (which one you feel is preferable), and that makes questions related to formatting style off-topic for every Stack Exchange site of which I'm aware.
    – Ken White
    Commented Nov 12, 2015 at 4:08
  • 3
    Well, the only site where formatting is on-topic is Code Review. But even there, the formatting is simply one of the things that are reviewed, it's still the wrong site for debating the merits of a common style. Commented Nov 12, 2015 at 5:22
  • Asking about a way to discuss coding style may be on-topic (likely duplicate) on programmers.stackexchange.com ("how to set coding style for my team"). Commented Nov 12, 2015 at 7:46

1 Answer 1

6

None1 .

Style discussions are generally prohibited everywhere2 (sites/real life) due to completely opinion based nature and being well known flame war topic.

If you are looking for "style to use in StackOveflow/Code Review questions" - code auto-formatted with defaults in any editor/beautifier supporting your language is fine. Any consistent style is ok.

Note that there are some cases where "formatting" is actually changes meaning of the code and forces particular style of some formatting - i.e. JavaScript almost universally uses Egyptian Brackets due to Automatic semicolon insertion & return statements. While question about that type of style choices could be on-topic on SO ("is there any reason JavaScript prefers Egyptian Brackets") it is unlikely to be new question and will be closed as duplicate (with enough downvotes due to lack of research).


  • 1 - Code Review may give formatting suggestions, but you must start with decent formatting. Discussing formatting options would be off-topic there.
  • 2 - unless flame war or just pointless discussion is the goal - i.e. in a bar.

You must log in to answer this question.

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