-6

I'm wondering if perhaps it would be beneficial to start having style checks that run on all code blocks on SO.

Beginners, who are more prone to look things up on SO, would be exposed to good style earlier and perhaps get them to adopt good style in their own code sooner rather than later. As a byproduct, programmers who don't visit SO (do those exist?) indirectly benefit because when they exchange code with programmers that do visit SO, they're also exposed to good code style.

I feel like this aught to be something like a spell check. Don't force people to use good style, but at least alert them that they're using bad style.

I realize that there are some style choices that are personal, but there are others that aren't, or are fairly unanimously agreed upon as bad.

6
  • Related: meta.stackoverflow.com/questions/266806/…
    – JonK
    Aug 14, 2014 at 13:04
  • It's also possible that something "invalid" in the styling could be important. Aug 14, 2014 at 17:08
  • @AndrewBarber - Which is why it's more like a spell check, pointing out mistakes, rather than forcing code to comply. Aug 14, 2014 at 18:39
  • 1
    I think this is a good idea, although probably only applied to answers not questions. It would promote good coding practices! No automatic changes as you say, but maybe flagging up possible issues, there could even be a review queue for this Jul 7, 2017 at 16:37
  • @Chris_Rands - Oh I like the idea of adding a review queue for it! Although I disagree that it should be applied to only answers and not questions. I see no reason to limit it to just one or the other. Jul 7, 2017 at 17:51
  • Well maybe it could apply to questions too but I was thinking there might be cases where the questions might be 'solved' by the linter. Anyway, broadly I think it's a great idea worth much further discussion, I don't know why it was downvoted! Jul 7, 2017 at 19:23

1 Answer 1

1

Good code would be chock full of error-checking, too. Do you think we should include that in all of our Stack Overflow answers?

This misses the point—Stack Overflow is not a tutorial website to teach people how to program. We answer detailed questions about specific programming problems. If the error-checking or stylistic aspects are not relevant to the problem being discussed, then it doesn't really matter.

If beginners want to be exposed to good style, they can and should read code from open source projects. This is a great way to be exposed to good style. Code snippets on Stack Overflow aren't shouldn't be designed for easy copy-pasting into an actual code base. They're explanatory tools only.

And if you still aren't happy with that, it is worth noting that we have a failsafe. If you see something where the formatting or style is actively interfering with legibility (like excessive horizontal scrolling or indentation), then you can edit the post to fix the problem. This gets a human involved, hopefully one who is semi-knowledgeable about the domain, and who is therefore less likely to make mistakes.

You must log in to answer this question.

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