Page 6 of 7 FirstFirst ... 4567 LastLast
Results 51 to 60 of 61

Thread: Google Wants To Make C++ More Fun

  1. #51
    Join Date
    Jul 2010
    Posts
    333

    Default

    I think both the C++ variants need to include '<< std::endl' or '<< "\n"' :-)

  2. #52
    Join Date
    Dec 2010
    Location
    Calgary
    Posts
    123

    Default

    Quote Originally Posted by BlackStar View Post
    I mean something like this:
    Code:
    #include <iostream>
    #include <boost/lexical_cast.hpp>
    
    int main(int argc, char *argv[])
    {
        std::cout << boost::lexical_cast<std::string>(42);
        return 0;
    }
    versus

    Code:
    10 PRINT 42
    Which looks higher level to you?
    I think you are picking your language features carefully, Blackstar. As Drago pointed out that lexical cast is unneeded because cout can handle all the elementary types already.

    As for BASIC, IIRC it has PEEK and POKE that do direct memory manipulation though not as versatile as pointers. Which language is more high level now?

    More importantly, some people take "high level" to mean more powerful and capable of more subtle control of a computer; others take high level to mean more abstracted from the hardware.

    By the first definition, C++ is more high level than BASIC, by the second definiton BASIC is more high level (and your average scripting language like python or perl even more so).

    So, what do you mean by high level? I still think you and your other correspondent are arguing English semantics.

  3. #53
    Join Date
    Dec 2010
    Location
    Calgary
    Posts
    123

    Default

    Quote Originally Posted by archibald View Post
    I think both the C++ variants need to include '<< std::endl' or '<< "\n"' :-)
    I agree, but the question still stands: is std::endl more or less high level than "\n"?

  4. #54
    Join Date
    Oct 2007
    Location
    Under the bridge
    Posts
    2,045

    Default

    More importantly, some people take "high level" to mean more powerful and capable of more subtle control of a computer; others take high level to mean more abstracted from the hardware.
    Irrelevant. "High-level" is a well defined term, even if some people confuse it with "powerful". Those people should open a textbook.

    Quote Originally Posted by hoohoo View Post
    I think you are picking your language features carefully, Blackstar. As Drago pointed out that lexical cast is unneeded because cout can handle all the elementary types already.
    Indeed, I picked my "hello world" example very carefully.

  5. #55
    Join Date
    Mar 2011
    Location
    Canada
    Posts
    30

    Default

    Quote Originally Posted by hoohoo View Post
    I agree, but the question still stands: is std::endl more or less high level than "\n"?
    I know it was a joke, but using std::endl is the exact same thing as '\n', except it also flushes the stream.

  6. #56
    Join Date
    Apr 2010
    Posts
    1,946

    Default

    Quote Originally Posted by hoohoo View Post
    More importantly, some people take "high level" to mean more powerful and capable of more subtle control of a computer; others take high level to mean more abstracted from the hardware.

    By the first definition, C++ is more high level than BASIC, by the second definiton BASIC is more high level (and your average scripting language like python or perl even more so).

    So, what do you mean by high level? I still think you and your other correspondent are arguing English semantics.

    Quote Originally Posted by BlackStar View Post
    Irrelevant. "High-level" is a well defined term, even if some people confuse it with "powerful". Those people should open a textbook.
    High-level is defined as "as close to human dialect as possible".

    The problem is that human language does not match that of the hardware and hence, while "high-level" languages are easier for humans to use, they are very inefficient translators.

    On contrary, "low-level" language is very close to that of hardware and it results in opposite effects.

    So hoohoo is correct.

    Your example, BlackStar is incomplete. Because the
    PRINT 42
    construction basically expands to that of C++ equivalent in logic, although never directly ofc. What you are loosing here, is the control over relevant parts.

    C/C++ was designed to offer both of the worlds, being both powerful by staying close to hardware language (no relevant parts missed), yet being much easier to understand by humans than assembler.

    This is why many refer to C as "middle level" language.

    ---

    But, because all three language levels are only logic abstractions between machine and programmer, they offer various balances between flexibility and difficulty. They will be translated into machine language anyway, this is why "what is better" is wrong question.

    "What is better WHEN" is correct question. "WHEN" at this level is expanded to circumstances, conditions, awaited result.

    You are basically comparing mice to elephants, one claims elephants are stronger, other claims mice are more flexible.

    Don't do that, this is silly.

    Well elephant can't pass into the hole; mice cannot lift trees.

    Use right tool for the job. There is no "better" here.

    Quote Originally Posted by BlackStar View Post
    Indeed, I picked my "hello world" example very carefully.
    Thou art of trolling is a brilliant one

    Quote Originally Posted by strcat View Post
    I know it was a joke, but using std::endl is the exact same thing as '\n', except it also flushes the stream.
    I think the idea to include "endl" was to improve portability by replacing system-specific constants (such as '\n') by a much more flexible automatic. Also, '\n' in this context applies to streams and as such it justifies its existence.
    Last edited by crazycheese; 06-21-2012 at 10:01 PM.

  7. #57
    Join Date
    Sep 2008
    Posts
    987

  8. #58
    Join Date
    Mar 2011
    Location
    Canada
    Posts
    30

    Default

    Quote Originally Posted by crazycheese View Post
    I think the idea to include "endl" was to improve portability by replacing system-specific constants (such as '\n') by a much more flexible automatic. Also, '\n' in this context applies to streams and as such it justifies its existence.
    It's a very common misconception that endl is somehow more portable than '\n'. Both of them will use the system-specific newline representation, but endl also flushes the stream (which is sometimes but not always desirable, and stream.flush() also works).

  9. #59
    Join Date
    Apr 2010
    Posts
    1,946

    Default

    Quote Originally Posted by allquixotic View Post
    Good read, but I don't see where it comes into conflict with what I was saying.
    Using this articles own words, if you need recursive programming, you don't use BASIC. And thats ok.
    Thanks for the article.

    Quote Originally Posted by strcat View Post
    It's a very common misconception that endl is somehow more portable than '\n'. Both of them will use the system-specific newline representation, but endl also flushes the stream (which is sometimes but not always desirable, and stream.flush() also works).
    I don't believe it to be "common misconception", because from my point of view, it is better to "endl" than to work on this one. Please prove me wrong.

  10. #60
    Join Date
    Mar 2011
    Location
    Canada
    Posts
    30

    Default

    Quote Originally Posted by crazycheese View Post
    I don't believe it to be "common misconception", because from my point of view, it is better to "endl" than to work on this one. Please prove me wrong.
    The only difference between endl and '\n' is that endl flushes the stream. The endl function simply prints '\n' and then flushes the stream. It's no more portable than '\n', which does correctly use the platform's newline when written to a file in text mode (including a stream). Using endl all the time when you don't actually want to flush the stream will cause a performance hit for no reason, it's simply cargo cult programming.

    http://stackoverflow.com/a/213977/1009916
    http://en.cppreference.com/w/cpp/io/manip/endl
    (or the C++ standard, which also confirms this)
    Last edited by strcat; 06-22-2012 at 02:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •