Announcement

Collapse
No announcement yet.

Google Wants To Make C++ More Fun

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #52
      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.

      Comment


      • #53
        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"?

        Comment


        • #54
          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.

          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.

          Comment


          • #55
            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.

            Comment


            • #56
              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.

              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.

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

              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; 21 June 2012, 11:01 PM.

              Comment


              • #57

                You are all wrong

                Comment


                • #58
                  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).

                  Comment


                  • #59
                    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.

                    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.

                    Comment


                    • #60
                      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.

                      Many C++ books contain example code like this... std::cout &lt;&lt; "Test line" &lt;&lt; std::endl; ...so I've always done that too. But I've seen a lot of code from working developers like this


                      (or the C++ standard, which also confirms this)
                      Last edited by strcat; 22 June 2012, 03:26 AM.

                      Comment

                      Working...
                      X