Antique Lemmy
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Hellfire103@lemmy.ca to Programmer Humor@lemmy.mlEnglish · 2 months ago

Does this exist anywhere outside of C++?

lemmy.ml

message-square
24
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
6

Does this exist anywhere outside of C++?

lemmy.ml

Hellfire103@lemmy.ca to Programmer Humor@lemmy.mlEnglish · 2 months ago
message-square
24
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
alert-triangle
You must log in or register to comment.
  • SavvyWolf@pawb.social
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months ago

    https://docs.oracle.com/javase/9/docs/api/java/lang/System.html#lineSeparator--

    Java, of course.

  • jecxjo@midwest.social
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months ago

    They aren’t the same thing so the comparison is weird.

    endl has a flush which is important when doing something like embedded work or RTOS development. If i was doing multiple lines they all were \n until the last line when i actually want to push the buffer.

    Obviously depending on the tuning of the compiler’s optimization multiple flushes could be reduced but the goal should always be to write as optimal as possible.

    • aport@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      Who in the hell is using iostreams in an RTOS

      • KeenFlame@feddit.nu
        link
        fedilink
        arrow-up
        1
        ·
        2 months ago

        Several. Probably dozens

      • jecxjo@midwest.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 months ago

        Sometimes you work in a codebase that was decided on by others for reasons you don’t know.

  • Scrubbles@poptalk.scrubbles.tech
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months ago

    Environment.NewLine()

    • tourist@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago
      /* I'm new to this language so just imagine there is a new line here when it prints: */
      
  • xmunk@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    2 months ago

    I’m on side \PHP_EOL

  • UpperBroccoli@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    1
    ·
    2 months ago

    \n, because I ordered a newline, not a flush.

  • GideonBear@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    2 months ago

    #define endl “\n”

  • SpaceNoodle@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    2 months ago

    If I’m writing C++, I’m usually optimizing for portability over performance, in which case I would prefer std::endl as it would yield the best results regardless of platform; it also keeps the end-of-line character out of other strings, making code just a little cleaner.

    \n is for when I’m done pretending that anything that isn’t Unix-like is OK, or I’m counting the cycles of every branch instruction.

    • Oriel Jutty :hhHHHAAAH:@infosec.exchange
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

      std::endl provides zero portability benefits. C++ does have a portable newline abstraction, but it is called \n, not endl.

      • Albbi@lemmy.ca
        link
        fedilink
        arrow-up
        1
        ·
        2 months ago

        Thank you two for demonstrating the image in the post so well.

      • SpaceNoodle@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        2 months ago

        No, there’s no guarantee that in every context \n is translated portably.

        • Oriel Jutty :hhHHHAAAH:@infosec.exchange
          link
          fedilink
          arrow-up
          1
          ·
          2 months ago

          The same is true of std::endl. std::endl is simply defined as << '\n' << std::flush; nothing more, nothing less. In all cases where endl gives you a “properly translated” newline, so does \n.

          • zenforyen@feddit.org
            link
            fedilink
            arrow-up
            1
            ·
            2 months ago

            Yeah it’s an artificial dichotomy based on a popular misconception of what std::endl is and how \n is interpreted.

            Ultimately it does not ask about line endings, but about flushing, which is a completely orthogonal question.

          • SpaceNoodle@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            2 months ago

            Ahhh, I see. Looks like the magic happens somewhere further down in iostream.

            • AnyOldName3@lemmy.world
              link
              fedilink
              arrow-up
              1
              ·
              2 months ago

              It’s controlled by whether the stream’s opened in text mode or binary mode. On Unix, they’re the same, but on Windows, text mode has line ending conversion.

  • unlawfulbooger@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    0
    ·
    2 months ago

    What the heck is endl???

    • Hellfire103@lemmy.caOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      edit-2
      2 months ago

      Instead of this:

      cout << "Hello world.\n";
      

      You can do this:

      cout << "Hello world." << endl;
      
      • Daedskin@lemm.ee
        link
        fedilink
        arrow-up
        1
        ·
        2 months ago

        The fact that you used the namespace for cout but not for endl inordinately bothers me

    • vapeloki@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      std::endl is used in output streams in C++ to end the line, using the os specific line termination sequence, and flush the buffer.

      The later one is a performance issue in many cases, why the use of "\n" is considered preferred

      • xigoi@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        Don’t most terminals flush the buffer on newline anyway?

        • ClemaX@lemm.ee
          link
          fedilink
          arrow-up
          1
          ·
          2 months ago

          It is the stream itself that is buffered, so the terminal does not handle the contents until the stream is flushed.

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 140 users / day
  • 1.97K users / week
  • 3.32K users / month
  • 3.82K users / 6 months
  • 1 local subscriber
  • 36K subscribers
  • 834 Posts
  • 5.11K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • UI: 0.19.6-beta.7
  • BE: 0.19.11
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org