-20

When a user is asking a question SO has many ways of making sure the question is at high quality, SO has many guides and rules to make a good question and they are doing the job well.

I would like to have these kind of rules applied on the code posted in questions as well.

We already have some rules applied to code - the question cannot contain too much of it and too little of an explanation, but this is not enough. I am reading a lot of code that I do not understand - the code quality is low. This is hard for me and others to answer the question even if there is a paragraph of explanation.

The feature I am asking is as follows:
Define a two ratios of comments to code-lines (say 1 to 10 and 1 to 20). If the code posted does not answer the first ratio than alert the user, if the code posted does not answer the second ratio than do not let them post the question.

This is a very basic demand from users (and programmers in general), it helps us help them and it sets a higher readability standard.

6
  • 7
    If a user is unable to write readable code, do you really think they will write understandable comments so we can understand them without knowing the context, especially when they are forced to write comments? All I expect then is "bla bla bla, needed because system wants comments".
    – Tom
    Mar 28, 2020 at 14:43
  • 6
    I'm not liking this very much, to be honest. Comments are fine, but they can be misleading. I don't see how double the amount of lines in a code-block makes things easier. I like it when someone explains what the code is suppose to do in text prior to the code block and use comments to indicate special things, not int i = 0; // this is an int. Truth is that there's just noway to validate the usefulness of comments in code.
    – Scratte
    Mar 28, 2020 at 14:53
  • 6
    Are you suggesting that we encourage the comment-anti-pattern? Myself, I prefer to read code without any comments, but instead with a full and complete description in the body of the question. Mar 28, 2020 at 18:49
  • That would be seen as a hostile/toxic requirement by those who have no clue how the code they copied/plagged/downloaded works. Some way would be found to blame curators for it on Facepalm/Tattler. Mar 29, 2020 at 16:55
  • There is little more annoying about source code than 'int a,b,c,d,i,j,k,n' followed by pointless, inane comments sprinkled about the functions:(( Mar 29, 2020 at 17:14
  • The issue with bad / unreadable code is that you can't trust op. No amount of text will rebuild the trust and point you in the direction of the issue. The title will be "How to go to Paris?", the question body will describe a travel to London, the code is about Mexico and the comment are just prayer : "//Get gps coord; //Calc the best Trajectory; //Reroute the Tachyion flow through the warp drive polarity inducer;". Code comment does not describe code. Sometimes they are "Answer here", but most of the time they are just wish unrelated to the issue. Mar 30, 2020 at 7:28

2 Answers 2

9

Preamble: I do agree that code readability is very important, and if you happen to find poorly formatted code, for example, consider editing it to match a standard or more conventional format (go's fmt, Rust's rustfmt, etc.). If that isn't enough to understand it from a knowledgeable point of view, you know what to do: downvote and/or vote to close.

With that said, any hard limit based on the ratio of comments to lines of code is more likely to hinder than to help. For one, there is no reasonable ratio to begin with, much less one that works well across so many technologies out there. Plus, it would only invite users to add bogus comments with no value to understanding the problem, which in turn only makes the code noisier.

This isn't the first time I see a feature request suggesting an automatic question filter of some sort. It's very hard to come up with a good one, as much as one would want to reduce the flood. For the time being, it might be best to empower the curator base to handle bad questions quicker.

3
4

This would only encourage to add useless comments to code. Clear and short code snippets hardly ever need comments anyway, and this would make trying to understand other people's code even harder. Code should never have such arbitrary rules applied to it, if a comment is needed it should always be there, but a force or an unnecessary comment is much worse than no comment at all.

You must log in to answer this question.

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