Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Looking at the Getting Started section... Is this really the best way to write text out to the console in C++, or is it just traditional?

    cout << "Hello World!" << endl;
It seems like something a bit simpler, readable and predictable would be better for beginners and/or experienced devs alike. I look at that and wonder where did cout come from? Is << a heredoc or some sort of pipe indirection, or am I bit-shifting? And is endl a keyword? Does it always follow cout? Is this like a Pascal endif? Oh, it's basically just a newline. What's wrong with just "\n"? I think C++ devs purposefully make their language as obtuse as possible.

Maybe NOT starting with streamio and operator overloading might be a more modern way to start teaching the language?



Anecdotally, beginners have less issues with this than trying to remember printf format strings.


> Oh, it's basically just a newline. What's wrong with just "\n"?

Not all platforms use “\n” for a new line.


The std::stream will translate '\n' to what's required for the underlying platform, so it is a perfectly portable way to terminate a line.

What std::endl really does is flush the internal stream buffer if any.


For beginners I didn't have trouble with `cout` and `<<`. Just teach that that's how you print without going in details.

This is more a problem with folks with experience in other languages, who know bitshift or heredoc syntax. But those can be teached in a more advanced way.


> I look at that and wonder where did cout come from?

This is the biggest issue with this. STOP TEACHING “using namespace std;”. This is bad, bad, bad, and it sucks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: