Talk:While loop

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing (Rated Start-class)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
 

Bad examples[edit]

The example given on this page is badly chosen, when the number of iterations is known a For loop is the better choice than a while loop. It is the main difference between a for and a while loop, for a while loop you do not need to know the number of iterations up-front, that is, a while loop is more powerful and the example should illustrate that. Alas, I am not knowledgeable in all ten languages presented on the page and can thus not change the example.

Perl example[edit]

Regarding "Very similar to C and C++, but the while loop could also have been written on one line:":

Why is this example used? Apparently to show off Perl's compactness compared to C and C++, except that C and C++ can do it in one line also, just as compact. That part should be deleted. —Preceding unsigned comment added by Codehead1 (talkcontribs) 19:32, 1 June 2009 (UTC)

Source code format[edit]

This was a good edit. The source code format with { on the same line is more compact and has at least as much popular support as any other format. The article should use it that way. @Totoajax? Andy Dingley (talk) 20:51, 11 May 2016 (UTC)

"Good" is a value judgement, and popularity of this can be difficult to measure. There are many different styles! And each has its adherents, and pros and cons.
More important is what style should wikipedia consistently use.
Having a browse around, there really is no consistency on brace usage currently within wikipedia:
C_(programming_language)#.22Hello.2C_world.22_example
C_data_types#Structures
C_data_types#Unions
C99#Example
And this one C_syntax has more than one style in the one document.
Having programmed in C/C++ for over 3 decades, I do have my own views. But I don't want to start a code-formatting war! And I'd really like to see some consistency. I do understand the compactness argument, but I also like the consistency of open brace always on its own line (the "Allman" style), for start of function as well as start of block.
  • According to [1] this is widely used in the MS world
  • [2] has this "expansive" style as ANSI and ISO standard.
  • And [3] (not necessarily a reliable source) has the "Allman"" (expansive) style as the most popular (although it did generate a massive amount of comments!)
  • And [4] only generated controversy.
I was surprised that I couldn't find a wiki link to brace wars, although there should probably be some more said in this Indent_style#Styles page.
I'm OK with C and C++ pages being different, as they are different languages.
What do you think? I'm not quite up to going and updating all the C code in wikipedia...
How do we get a wikipedia standard?
peterl (talk) 08:40, 12 May 2016 (UTC)
TL;DR. As originally noted:
  • Both formats are used. You cannot claim that either is exceptional
  • No-one is trying to compile this, or even claim it is one particular language rather than another. Most subtle syntax issues simply don't matter here.
  • This is Wikipedia. Readability to humans does matter, but not machine-readable syntax.
  • At least two editors here have expressed a preference for the more compact form.
Andy Dingley (talk) 09:26, 12 May 2016 (UTC)
It's not really fair to reject my arguments without reading them.
  • I'm not claiming either is exceptional. And there's more than two.
  • I'm not claiming anyone is trying to compile the code.
  • I agree. Readability to humans does matter. It is of considerable debate which is more readable to humans.
  • Two editors out of the millions programming C and the millions editing wikipedia doesn't make consensus.
peterl (talk) 23:58, 12 May 2016 (UTC)