Talk:C++/Archive 8

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Archive 5 Archive 6 Archive 7 Archive 8 Archive 9 Archive 10 Archive 12

Problem Domain

A discussion on the C++ problem domain could benefit this article. C++ is a general purpose language that can be applied to most programming problems, but often times other languages are considered more appropriate. I think this has some overlap with "Adoption and reception". The following questions could be answered with citations:

  • What is the original problem domain of C++? (answered in part already)
  • Where has C++ been used in the past (and why)?
  • Where is C++ used today (and why)?
  • For what problems do experts recommend using C++?
  • etc.

This article could be a can of worms for opinions and original research. Some camps declare it a dead language, others declare its better than almost any language thats' out there. So we must be extra careful to approach this with neutrality. The views of industry and research papers should be presented with citation, and we should avoid weasel words in the main article such as, "Most/Few web applications are programmed in C++[1]....." and "The use of C++ is believed to be increasing/declining.[2]" even if they are accompanied by citations. Instead i would prefer active voice citations such as "Reliable source X stated that X% of web applications are programmed in C++." or "Reliable Source Y states use of C++ is increasing/declining." In this way, we can at least limit our unconscious bias to the citations we find, rather than how we present them.Gsonnenf (talk) —Preceding undated comment added 02:06, 4 April 2009 (UTC).

This could be useful. Claims would need to be verified of course.

http://www.research.att.com/~bs/applications.html

Gsonnenf (talk) —Preceding undated comment added 02:25, 4 April 2009 (UTC).

Attempt to resolve the Hello, World! debate

To accomodate both sides, both of which are correct, I updated the hello world sample in a table format with both versions side-by-side along with a note about the differences. I think it presents both versions, do not clutter, and contributes information while not confusing the issue. Mikademus 130.243.247.165 (talk) 12:22, 6 August 2008 (UTC)

I've reverted this because I think the comments around the consensus version make it quite clear that the consensus version shouldn't be changed without discussion. The Bjarne Stroustrup version is cited to a reliable source whereas the recommended practice[who?] version is essentially original research. With that in mind, I have also removed the {{examplefarm}} tag since I cannot imagine a better example in this case. SHEFFIELDSTEELTALK 13:14, 6 August 2008 (UTC)

Oh, it is not a question of references (which should be obvious since I even mentioned the specific section in the Standard, it is a question of providing a good overview and an immediately digestible illustration of something that apparently causes confusion to both newbies and seasoned verterans. Face it, if the section is changed two times per week, as the scare comments suggest, then there is a problem with the section. Not necessarily anything wrong, but a problem nonetheless. For sake of discussion, this is the update to the section I suggested (here placed inside a border not intended for the article):

Standard-compliant minimal Hello, World! Recommended-practice Hello, World!
#include <iostream>  // provides std::cout

int main()
{
   std::cout << "Hello, world!\n";
}

#include <iostream>  // provides std::cout

int main()
{
   std::cout << "Hello, world!" << std::endl;
   return 0;
}
All C++ functions, unless of void type, must return a value except for main(), which by section 3.6.1, paragraph 5 or the Standard allows for implicit return of 0. For syntactic consistency the recommended practice version explicitly returns 0 from the main() function and usees "std::endl" instead of the C-syntax "\n" for newline.

Use this and you (1) retain the Standard example, (2) illustrate a subtle aspect of the Standard that cause confusion, (3) avoid confusion, and (4) avoid edit warring. I get the feeling there is turf protection and pride somewhere in this, which of course is silly. Information and education is more important. 130.243.247.165 (talk) 14:31, 6 August 2008 (UTC)

But then we'll be revisiting the dreary discussions of whether <ostream> should be included, whether std::endl is even "recommended" at all (we don't want suggest that "\n" is synonymous with std::endl because excessive flushing can be a problem), and whether we should return 0 or EXIT_SUCCESS (one could argue that 0 is platform-specific and hence inappropriate). The Stroustrup code was chosen because it avoids all these issues, and the strength of the citation is obvious. Xerxesnine (talk) 15:06, 6 August 2008 (UTC)
The problems with the proposed two-example version don't end there, Xerxes. To have two competing examples side-by-side is frankly bizarre. And where is the justification for such non-neutral terminology as "minimal" and "recommended" - again, recommended by who?
Generally, the fact that these edits occur frequently does not imply that the changes are correct or desirable. I think the problem is that many programmers are in the habit of discussing, optimising and generally editing code, considering what they know about the language and not considering inline comments, footnotes, Talk page discussions, or Wikipedia policies. "Welcome to Wikipedia: the encyclopedia anyone can edit", in combination with "Hey, it's hello world, I know that" seems to be an irresistible combination for many editors. I don't know what to suggest. I think the only thing we haven't tried is deleting the section altogether. It may be the only way to prevent good-faith disruption of the article. SHEFFIELDSTEELTALK 15:37, 6 August 2008 (UTC)
At least some of this disruption is coming from anon IP's that are causing disruption elsewhere on Wikipedia. May I suggest semi-protection? Steve CarlsonTalk 00:29, 7 August 2008 (UTC)

This whole "Hello world" debacle... Quoting the creator of C++ himself:

"People love arguing about things that don't matter, because it's so easy to have an opinion about those things."

Bjarne Stroustrup [1][2]

--Juliano (T) 14:42, 12 August 2008 (UTC)

Despite its source, I have to agree that the Stroustrup version's missing return statement is bewildering. Our first example of a C++ program should be a typical one that does not point out exceptional cases. Newbies are prone to overgeneralization of new concepts, and this compounds the issue. I don't care so much about other details (0 or EXIT_SUCCESS, \n or std::endl), but pedagogy demands a return statement. Dcoetzee 20:29, 12 August 2008 (UTC)

I wonder what would happen if we would vote between those two versions (see above)? - 83.254.214.192 (talk) 15:17, 15 August 2008 (UTC)

What does the ANSI or ISO standard say? I feel their documentation should be consulted as they are recogized standards organizations.Gsonnenf (talk) 22:26, 26 March 2009 (UTC)

The standard does not contain a complete "Hello World!" program. All of the frequently discussed variations are well-formed according to the standard. decltype (talk) 16:53, 31 March 2009 (UTC)

Hello World \n

In C and C++, \n is an escape character for the newline character in strings. However, if written to a text stream (as cout), it also represents an actual newline. It's one of the tasks of the input/output library to recognize this character and do whatever is necessary in the host OS to cause a new line. If Visual Studio gets this wrong, its not conforming. I would be surprised about the first, but not about the second. I don't have a strong opinion on the whole "Hello World" thing yet. But a version with neither '\n' or std::endl is plain broken. --Stephan Schulz (talk) 07:09, 12 August 2008 (UTC)

I thought the \n translation was strictly related to files. In any case, it doesn't work for me (doesn't represent a newline on the console), and it would surprise me if the worlds' most used version of C++ wasn't standards-compliant. Whose to say a Hello World should have a newline anyway? Honestly, though, I think it should. I just wish SheffieldSteel & XercesNine would stop trying to own this article, and allow the rest of us to put a 'std:endl' where it should be. —Preceding unsigned comment added by Wikipendant (talkcontribs) 07:23, 12 August 2008 (UTC)
Try something like std::cout << "Hello, world!\nabc\ndef\n"; to better see the the effect. Well, Microsoft not being standards-compliant - who would be surprised? --Stephan Schulz (talk) 07:36, 12 August 2008 (UTC)
I would, not being standard compiliant is not a shame, really. I can think myself of perhaps 1 fully compiliant (modulo bugs) compiler, no its not gcc. Also, how did MS compiler get involved in hello world sample ? There is nothing platform specific in this sample (there may be implementation specific things though, but they arent highlighted or disputed, as concensus version is how you see it now) 83.25.78.242 (talk) 18:06, 13 August 2008 (UTC)
Personally I am not interested in owning this article. I just want to make sure that the content is compatible with generally accepted policies, such as Wikipedia:No original research. The world is full of programmers who can write their own version of hello.cpp and it is our job as editors, not to argue for our own preferred version, but to decide which of the published versions is best suited for use as an example here. So, anyone who wants to change the example just needs to provide a citation to a reliable source and we can start discussing this like Wikipedians, rather than arguing about it like programmers. SHEFFIELDSTEELTALK 02:07, 13 August 2008 (UTC)
Code is not considered "original research" on Wikipedia, and it seems ridiculous to impose this restriction of having to "cite" a hello world example. No other article on a programming language does this. The entire concept of "citing" a block of code is ludicrous, as anybody can easily verify that the code works. A logical, honest debate can actually yield a much higher quality block of code than one that was cited from some random document 20 years ago. Again, no other article on programming language has this restriction. We shouldn't just make up rules as we go along. —Preceding unsigned comment added by Wikipendant (talkcontribs) 03:00, 13 August 2008 (UTC)
There are about 400 billion different ways to write a hello world program, but only one of them has the very special distinction of being authored by the inventor of the language and published in the principle reference for the language. It has nothing to do with me or the other editors here "owning" the article (personally, it's not my favorite version of hello world either), it has to do with this being a very contentious topic (for some ungodly reason) and in cases like that it's best to stick to the version that has rock-solid sourcing. That's all. Now can we drop it now and move on? Is this really so important? :-) ATren (talk) 05:23, 13 August 2008 (UTC)
There are 400 billion ways to write a sentence, too. That doesn't mean that all are equally correct. I didn't realize this was such a contentious topic (I'm new), but at the same time, the management of this article is frustrating. Going back hundreds of diffs, there seems to be hundreds of editors all clamoring for the "standard" cout << "Hello World" << endl; approach. That seems like consensus to me. The only reason it doesn't stay that way is because most editors don't realize that there's a talk page, or that this topic is so controversial for some reason. The hello world stays the way it is because it is correct in the eyes of the few, persistent editors (ATren, Xerxesnine, and SheffieldSteel), and in fact doesn't represent the opinion of the community at large. Just going back through the diffs irrefutably validates this fact. The workflow seems to be:

1. A new editor stumbles across the page. 2. The editor notices the obviously strange hello world, and changes it. 3. ATren, SheffieldSteel, or Xerxesnine instantly reverts it. 4. The new editor, oblivious to the reversion, goes on his way. This seems to happen over and over and over again. Anybody not trying to prove a point, or own the article, would've noticed the pattern by now. I don't mean to drag this discussion out of the grave, but I wasn't there for it, and it seems like enough people want to see a "more correct" version of hello world on wikipedia that it is still an issue. I don't want to be argumentative, but the matter-of-fact way that the reverts are handled, and the obnoxious warnings all over the hello world section seem pretentious and reeks of ownership problems. I can only imagine how frustrating this has been to the untold number of people who try to improve this article, only to have it instantly reverted by this small set of editors with an opinion on the hello world and the article on their watchlist. There's a better hello world - you know it, I know it, and hundreds of other people who have edited the article in the past know it. Is there a reason we're not using it? Citing a 20 year old example from the birth of C++ isn't sufficient, regardless of pedigree, and in fact showcases a weird artifact of the language (the newline escape-character overload) that will be confusing for a long time after learning the language. I'm sorry if I seem combative, but this is just an unbelievably frustrating introduction to the Wikipedia community, in which the community itself seems to actively resist the improvement of an article because of a handful of influential, active editors opinions. —Preceding unsigned comment added by Wikipendant (talkcontribs) 17:21, 13 August 2008 (UTC)

Add me to the "cabal" as well, i do reverse HW to consensus version whenever i can too, also most of times HW was disrupted by people whe rarely did come back to this article (only interest here seem to be changing HW sample). Conesnus should be achieved by contributors no? What do you mean better ? Why do you see flushing a buffer before its flushed anyways as better than current version? Your deffinition of better seems kindof strange too me. Also cant see how you see outputing "\n" as an artifact, surely in C++ you use endl whenever you can? Whats the point of having buffered streams than? Also, have a look at history, if it wasnt for some consensus version that is reverted to, instead of HW sample we would have ended up with a horrible abomination ;) 83.25.78.242 (talk) 18:06, 13 August 2008 (UTC)
OK, there's the three editors Wikipendant mentioned, plus this IP, plus Stephen Schulz, plus the depated Yamla, and I think there may be a few others all in support of this consensus. That's half a dozen users against one editor here and a few passerbys over the last 6 months. I think that can safely be considered a solid consensus for such a mild issue, but you do have recourse if you like: if you really believe you have a case, then you should bring it to dispute resolution by filing a WP:RFC to solicit wider input. Personally, I wouldn't do it (remember, as I said before I don't even like this version, but it works and it's well-sourced so I accept it) but it's there if you want it. But absent that, the consensus here is quite clearly against you. ATren (talk) 20:17, 13 August 2008 (UTC)
Don't speak for Stephen Shulz, or Yamla - Let them speak for themselves if they must! Stephen was against my edit, which to be honest, I didn't even agree with fully. And as for the anon IP's comments, endl isn't going to flush the buffer twice. The compiler will take care of that. The reason \n is confusing is because it's an overloaded escape character. MacOs & Windows don't actually use '\n' to signify a new line: People familiar with programming know this. However, C++ weirdly changes this for certain stream operations, and doesn't change it for other functions related to I/O. Confusing, no? This could potentially cause seriously strange behavior that a newbie to C++ wouldn't understand - mora than this, he shouldn't HAVE to understand it. Almost ever hello world example for c++ uses cout << "hello World" << endl, and with good reason: It's easily readable, and not subject to the confusion '\n' causes. I'll look into this RFC thing if I have to - I just thought the community would be more willing to discuss this than it has been. —Preceding unsigned comment added by Wikipendant (talkcontribs) 00:22, 14 August 2008 (UTC)
Compiler wont take care of things its forbidden to take care of, anyways we dont discuss compilers here but C++ language, and according to it your HW version would flush std::cout twice once in std::endl (which is not much more than '\n' + std::flush), and another time at destructor of ios_base::Init object which purpouse is just to do that - flush builtin streams at program termination. Also, '\n' is no more confusing than std::endl, as the later uses the former, plus whats so confusing? Could you point out?. There is no such thing as overloaded escape character afaik, how OS interprets any character is beside the scope of this article imo. Btw, wer willing to disscuss here, its what we do just now dont we? 83.25.95.6 (talk) 18:29, 14 August 2008 (UTC)
But where are all these hello world examples? And should your preferred version have used "std::endl" or would it be better to use "using namespace std"? What happens if another editor disagrees with you? Are they entitled to edit war to enforce their preferred version of the article? What if they post a few times on the Talk page first?
I hope you can see the problem we have here. The standard for content in Wikipedia is Verifiability, not what one particular programmer thinks is best. Our No Original Research policy is a cornerstone of the project, and it says that you simply can't put what you think into the articles. In conjunction with the consensus model of discussion, it is the best and only solution we have to the general problem of this being, well, the encyclopaedia that anyone can edit. If you have a reliable source, please provide it. SHEFFIELDSTEELTALK 00:39, 14 August 2008 (UTC)

Count me towards the std::endl approach - it's the only one that makes sense around here. —Preceding unsigned comment added by 12.46.54.53 (talk) 12:01, 14 August 2008 (UTC)

Bjarne uses "using namespace std" for trivial code, for the record (see: "How do I write this very simple program?", http://www.research.att.com/~bs/bs_faq2.html) —Preceding unsigned comment added by 12.46.54.53 (talk) 12:11, 14 August 2008 (UTC)
Ha! Double edged sword ;) Note how he uses "\n" and not std::endl in example you provided 83.25.95.6 (talk) 18:32, 14 August 2008 (UTC)


If you want to be pedantic about this, Bjarne's code examples are presented throughout the book in Times bold-italic, and not a fixed-width font, for reasons explained in section 1.1.1 "Notes to the Reader" (special edition, 2000), in which the example given actually says std::cout << "Hello, new world!\n"; but whatever . — CharlotteWebb 19:23, 14 August 2008 (UTC)

Since close adherence to the example given at page 47 iirc in The C++ Language 3rd ed. seems of paramount importance I changed the font face to Times. I expect any change to this to be to change it to italics and bold. Any reversion would be a deviated from the example invoked and indicate inconsistency on the behalf of the very vocal advocates above for the sancrosanctity of Bjarne's Example. 130.243.247.165 (talk) 19:09, 23 August 2008 (UTC)
I have reverted you. Please read WP:POINT. ATren (talk) 01:23, 24 August 2008 (UTC)
I reverted your revert. I assume good faith (please read WP:AGF) and that you were misguidedly trying to improve the article, but you changed the example to one not exemplified by Strostrup in the C++ Programming Language 3rd edition. To avoid confusion for visitors to the article, and since the confusing "hello, world!" sample should be consistent with the reference given for it, the example should be exactly as in the cited book, which is the consensus according to all above debate. Please discuss here before reverting 130.243.247.165 (talk) 02:35, 24 August 2008 (UTC)
There is no need to copy typefaces verbatim to be compliant with a source. The content is what matters. And the current typeface conflicts with all other code snippets in the article itself and across the encyclopedia. The version I am reverting back to is both 100% compliant with the cited source and consistent with other code snippets. It is also the consensus version which has stood for a significant amount of time, so it is up to you to gain consensus to change it.
Once again, I suggest you file an WP:RFC if you want to pursue this, but let me suggest an alternative: why not just let it go? Is this little piece of code so important that you are willing to edit war against consensus? And I'l also repeat that the cited version is not MY preferred version either, but it is sourced to an impeccably reliable source so it should stand. Now please don't revert again without further discussion here. ATren (talk) 14:16, 24 August 2008 (UTC)

I argue this issue to be silly on grounds of triviality. A non-C++ programmer does not need to understand the HW example, it is merely to show what the code looks like. Other examples, which may demonstrate to the coder specific features, are what need to be clear and readable. An experienced C++ programmer will not use it as a reference of how to code because s/he will have learned how to code already. We do not need to demonstrate good practices because it is trivial and is not an apropiete reference. I think a version that demonstrates TYPICAL C++ CODE would be most apropriete here, as the goal of putting a HW example in (seemingly) every programming language article is simply to show what the language looks like, and in a comparible way. The argument in my opinion should be on whether the given example is typical code. I can't really answer that. —Preceding unsigned comment added by SplinterOfChaos (talkcontribs) 23:01, 25 August 2008 (UTC)

BTW: There must be hundreds of examples of published Hello Worlds out there. As mentioned, no other programming-language article is forced to cite a published source on Hello World, so doesn't that mean we are being inconsistent with Wikipedia? And what does verifiability mean here? That it compiles? Well, it's obvious it will. What makes Bjarne's HW more verifiable than the homeless guy's down the street? Posted by: SoC (talk) -- Posted at:: 23:07, 25 August 2008 (UTC)

Reading this discussion, I have to point out that the '\n' escape character is handled by C++, and not the "operating system", as 83.25.78.242 has stated. It also is overloaded, in the sense that the '\n' character's meaning changes from streaming to file operations, sometimes representing the newline character, other times representing the operating system's newline, depending on context. It is therefore confusing, and I vote it to be replaced with the more sensible std::endl, or follow the more readable standard of "using namespace std;", therefore allowing the code to be less confusing. The std:: prefix is ugly and can be confusing to a new user of C++, as can the fact that we rely on an escape character whose meaning shifts under context. —Preceding unsigned comment added by 168.105.121.38 (talk) 23:17, 1 September 2008 (UTC)

Overloading has a well defined meaning in scope of C++ language. Usage of std::endl is no less confusing than usage of '\n' - the former uses the later, and does some other things as well - being more compilcated id say endl may be more confusing than '\n' (also note that '\n' is pretty universal among languages, whereas std::endl is not). '\n' is just a character constnat, what happens when outputed to a file stream (in whatever mode) or console is implementation specific (language spec doesnt mention what happens there, maybe theres something in C lang spec that gets inherited, but i dont have a copy of C draft/spec handy) and thus depends on underlying operating system. Prefixes being ugly is just your personal opinin, also why would 'using namespace std;' be more readable than explicit qualification of names? - and for new to C++ it may cause even more confusion as it introduces 2 new keywords. 83.25.88.189 (talk) 20:00, 3 September 2008 (UTC)

Basis for discussion

If editors here can agree on any one version as being the absolute best example of hello.cpp, I will not object to changing the article to include that version. The flipside, however, is that I will revert any change to the article that does not reflect consensus. SHEFFIELDSTEELTALK 14:10, 2 September 2008 (UTC)

The issues that have been raised are as follows:-

  1. (A) include <iostream> (B) include <istream> and <ostream> separately
  2. (A) '\n' (B) std::endl
  3. (A) std:: where necessary (B) using namespace std;

What about using std::cout; and using std::endl; before the cout line? Anyway, my vote is for what's typically seen in real-life code (which is what I think a Hello World in any language should be an example of). #include <istream> is rarely seen in the code I've looked at, so I vote for <iostream>. I've seen using std::whatever; in code where that thing is used a lot, but rarely else where, so seeing as cout and endl are only used once, I vote for using std:: where necessary. Posted by: SoC (talk) -- Posted at:: 09:16, 3 September 2008 (UTC)

That works with most, but not all compilers (Tru64 is an exception) Tedickey (talk) 09:58, 3 September 2008 (UTC)
The using keyword is standard; any compiler that does not support it is non-standard conforming. Do we really need to worry about them? I'm inclined to believe that only the standard can define what the language is, so those compilers are can be omitted in this discussion.Posted by: SoC (talk) -- Posted at:: 04:45, 5 September 2008 (UTC)
Agree, provided that editors remember to use the term standard, rather than provide nonfactual discussion Tedickey (talk) 09:53, 5 September 2008 (UTC)
The argument for "real-life code" misses the point of the hello world example, which is to provide a simple programming example. The std::endl, return statement, and using namespace declaration all unnecessarily add to the complexity of the code. "Hello World" examples are generally intended to be as understandable as possible to beginners and non-programmers with as little explanation as possible. They do not exist to show best or common practice. Krelborne (talk) 14:36, 17 September 2008 (UTC)

Discussion