-3

There are many questions being asked which does not follow Drupal coding standards and concepts. Do we really need to support them?

I think we there is no need to entertain such questions, and moderators should have sufficient message to close the question.

The current closing reason I can see is this:

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form.

Is it enough? Do we need more?

| |
  • 4
    Side note: this would pretty much obliterate new users to Drupal getting help from this website. They simply won't know these standards and concepts, that's why they're coming here - to learn – Clive Dec 13 '12 at 10:46
  • @Clive, i know that on a 100%. But none of the answers shows a Drupal way to do that. All are helping them with current code. – niksmac Dec 13 '12 at 10:49
  • 1
    Am confused what do you mean by Drupal way ? Are you referring to Drupal APIs ? Because there is no separate Drupal coding standard, pear coding standards for PHP is followed. – GoodSp33d Dec 13 '12 at 10:53
  • @NikhilM Ah ok, maybe the focus of the question should shift to something like "How can we encourage answerers to point out problems with coding standards and proper API usage?". If you did want to do that I'd ask a separate question, this is an interesting one in its own right and I think should be left standing. Although I don't see any proper naming conventions in there so I might close it ;) – Clive Dec 13 '12 at 10:59
  • 1
    @2-Stroker Drupal does have it's own coding standards, they're only "loosely based" on PEAR's :) – Clive Dec 13 '12 at 11:00
  • 1
    Do you have some examples for us to look at? – mpdonadio Dec 13 '12 at 12:17
  • Sure, i will post them with my question. – niksmac Dec 14 '12 at 2:23
4

Bad formatted code, or not following specific coding standards, is not the reason to close a question.

If you find any post where the code can be better formatted, feel free to edit the post, remembering not to change the code. If the code contains (for example) a call to array_mrge(), instead of array_merge(), just leave a comment, and let the author of the post edit it, if the case. When the post is a question, that typo could be the reason the code doesn't work; if you edit the typo, the user could not find the reason why the code doesn't work.

Don't flag a question just because the code is not well formatted; editing poor formatted code is not a task of moderators (to which the flags are directed). The flag will be probably declined, if moderators don't find anything for which the post should be deleted (e.g. the post is spam).

As for the closing reason you are referring, that is not for bad formatted code; it's for questions that are too broad to be understood, or for something that is not a question at all (e.g. a question containing "I like Drupal.").

| |
2

With all due respect, I think closing the question / answer just because the user doesn't follow coding standards is not correct.
We mostly code in PHP for our Drupal development. And if one is familiar with PHP and Drupal API, it won't be difficult for a person to understand what the OP is trying to do (even if the code does not follow coding standards).

Also, the Coding Standards for Drupal, mainly deal with formatting the code (i.e. making it more readable and easy for maintenance), rather than pointing out the use of (or flaws behind) the logic behind the programming (as there can be many different ways to solve the same problem, depending on the user's understanding).

So, when an user posts a question containing code which does not follow the coding standards, we should encourage other users (who are aware of the coding standards) to go ahead and edit the post and adjust the code to make it compatible to the coding standards (of course, without changing anything in it; which would change the logic behind it). And after editing you should leave a comment in the Edit summary of the question that the edit was made to adjust the code to the coding standards, which would make the OP aware about the coding standards when s/he sees the summary of the edit.

Yesterday, an user posted an answer to the question and posted the code which was not formatted according to coding standards. I've edited the post and adjusted the code to fit the coding standards without actually changing anything. You can see the edit summary here. I've also mentioned in the "Edit summary" - code formatted according to coding standards.

So, my answer to the question would be, we should support the questions / answers that doesn't follow the standards, but should encourage the users the adhere to them; as many of the newbies are not aware that the standards are actually present.

| |
  • 2
    I think intention of OP question is not explained properly. By coding standard think he meant usage of Drupal APIs rather than PHP api. Like drupal_goto() instead of header(Location:... – GoodSp33d Dec 13 '12 at 10:42
  • 2
    @2-Stroker Same answer applies though really. Why on earth would we close a question just because someone uses strlen() instead of drupal_strlen() for example? Educate by way of comments, sure, but closing the question is categorically not an option in my opinion – Clive Dec 13 '12 at 10:45
  • @Clive I dont support closing questions due to improper Coding standards followed, just thought that OP had this in mind, rather than closing, proper answers has to be given out. – GoodSp33d Dec 13 '12 at 10:50
  • 3
    @2-Stroker - I agree to your point about proper answers (in the sense of using Drupal API rather than plain PHP). But, I feel its an individual choice if a person wants to follow coding standards or not. If he does, than he'll get benefits in long term of site maintenance, and if he doesn't than it is he who'll pay the price. What we as a community could do is to promote use of coding standards, by editing, leaving comments, etc. – AjitS Dec 13 '12 at 10:56
1

The other 2 answers have covered the fact that this shouldn't be done, but I wanted to add what I see as a breakdown of which parts of a question/answer could be changed according to coding standards, and which parts shouldn't

Feel free to improve

Do not 'improve'

  • Operators - moving an operator can change the meaning of the code in some cases, especially with complex ++ or -- statements.
  • Quotes - Changing double to single quotes (and vice versa) can mess things up with interpolation/escaped characters.
  • Including Code - this could easily be an area where an error is introduced so it's best to leave include/require statements in their original state.
  • Semicolons - Missing semicolons could easily be the cause of any error so don't add these.
  • Example URLs - I personally don't see any gain in forcing people to use example.com.
  • Naming Conventions - This one would bother me the most if I was on the receiving end. Drupal doesn't always know 'best' (I use inverted commas as 'best' is a very subjective term when talking about naming conventions). If someone wants to name their variables in a different convention, let them - it's their choice.

Oh, and any true brit will defiantly ignore the following statement from that page:

Comments and names should use US English spelling (e.g., "color" not "colour").

You can have my 'u's when you pry them from my cold dead keyboard :)

| |
  • Just curious. Colour is British English spelling of color, which is widely used worldwide. Why shouldn't users use it? – AjitS Dec 13 '12 at 11:16
  • 1
    @indrock I thought US English was the standard, like in CSS colour is invalid but color is valid. – GoodSp33d Dec 13 '12 at 11:36
  • @indrock that's the wrong way round... color is the Americanisation of the English word colour :P I'm not suggesting that American English users convert, just that ill be using what I consider to be the correct spelling in my code :) – Clive Dec 13 '12 at 11:40
  • That choice should be left to the users, when it comes to comments. I think @2-Stroker makes a valid point; in CSS color works while colour won't. – AjitS Dec 13 '12 at 11:45
  • @indrock I think there's a misunderstanding here. I'm agreeing with you. I'm just saying that in my posts ill be using the British spelling, I certainly won't be editing others' posts to change it – Clive Dec 13 '12 at 11:56
  • I am going to have to disagree big time on this one. We should point out API mis-uses. We should edit posts to fix egregious formatting problems so we can read the code easier. We should trim horizontal and vertical whitespace for the same reason. Beyond that, there is a standard for code on drupal.org, but formatting is a preference. – mpdonadio Dec 13 '12 at 12:16
  • 1
    @MPD I've changed that first should to could, to better express what I'm actually trying to say. I don't see the disadvantage in applying the 'whitelist' above to code in a question/answer but I'm all ears if there are any (beyond individual users saying "well I want it a different way", that attitude doesn't really fly on SE sites anyway) – Clive Dec 13 '12 at 12:44

You must log in to answer this question.

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