supernova.place
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Hellfire103@lemmy.ca to Programmer Humor@lemmy.mlEnglish · 1 年前

Does this exist anywhere outside of C++?

lemmy.ml

message-square
61
link
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
170

Does this exist anywhere outside of C++?

lemmy.ml

Hellfire103@lemmy.ca to Programmer Humor@lemmy.mlEnglish · 1 年前
message-square
61
link
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
alert-triangle
You must log in or # to comment.
  • SpaceNoodle@lemmy.world
    link
    fedilink
    arrow-up
    50
    arrow-down
    4
    ·
    edit-2
    1 年前

    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
      35
      arrow-down
      3
      ·
      1 年前

      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
        50
        ·
        1 年前

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

      • SpaceNoodle@lemmy.world
        link
        fedilink
        arrow-up
        8
        ·
        1 年前

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

        • Oriel Jutty :hhHHHAAAH:@infosec.exchange
          link
          fedilink
          arrow-up
          15
          ·
          1 年前

          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.

          • SpaceNoodle@lemmy.world
            link
            fedilink
            arrow-up
            6
            ·
            1 年前

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

            • AnyOldName3@lemmy.world
              link
              fedilink
              arrow-up
              3
              ·
              1 年前

              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.

          • zenforyen@feddit.org
            link
            fedilink
            arrow-up
            2
            ·
            1 年前

            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.

  • jecxjo@midwest.social
    link
    fedilink
    English
    arrow-up
    22
    arrow-down
    1
    ·
    1 年前

    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.

    • lud@lemm.ee
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      10 个月前

      deleted by creator

    • aport@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      1 年前

      Who in the hell is using iostreams in an RTOS

      • KeenFlame@feddit.nu
        link
        fedilink
        arrow-up
        2
        ·
        1 年前

        Several. Probably dozens

      • jecxjo@midwest.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 年前

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

  • UpperBroccoli@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    19
    ·
    1 年前

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

  • unlawfulbooger@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    17
    ·
    1 年前

    What the heck is endl???

    • vapeloki@lemmy.world
      link
      fedilink
      arrow-up
      40
      ·
      1 年前

      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
        3
        arrow-down
        1
        ·
        1 年前

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

        • ClemaX@lemm.ee
          link
          fedilink
          arrow-up
          8
          arrow-down
          1
          ·
          1 年前

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

        • vapeloki@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          1 年前

          Maybe, but there is the internal buffer. Also, most I/O happens in files not consoles

    • Hellfire103@lemmy.caOP
      link
      fedilink
      English
      arrow-up
      11
      ·
      edit-2
      1 年前

      Instead of this:

      cout << "Hello world.\n";
      

      You can do this:

      cout << "Hello world." << endl;
      
      • Daedskin@lemm.ee
        link
        fedilink
        arrow-up
        5
        ·
        1 年前

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

      • ReversalHatchery@beehaw.org
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 年前

        something has replaced your lessthan signs with their HTML counterparts. such a silly thing to do in a code block

        • fubbernuckin@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          3
          ·
          1 年前

          I think that’s client side. Doesn’t happen for me.

          • Cyberfishofant2@lemm.ee
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 年前

            same here. AP isn’t standardized enough, apparently

            • ReversalHatchery@beehaw.org
              link
              fedilink
              English
              arrow-up
              1
              ·
              edit-2
              1 年前

              nah its a lemmy app on android that didn’t get an update in ages. probably just uses a faulty markdown renderer

    • gon [he]@lemm.ee
      link
      fedilink
      English
      arrow-up
      7
      ·
      1 年前

      https://cplusplus.com/reference/ostream/endl/

      • unlawfulbooger@lemmy.blahaj.zone
        link
        fedilink
        arrow-up
        12
        arrow-down
        1
        ·
        1 年前

        Boy am I glad I don’t do C++ anymore. That string handling with the overloaded bitshift operator was wild.

        • vext01@lemmy.sdf.org
          link
          fedilink
          arrow-up
          1
          ·
          1 年前

          Ah, so you’re a println! kinda guy?

          • unlawfulbooger@lemmy.blahaj.zone
            link
            fedilink
            arrow-up
            2
            ·
            1 年前

            🦀 🦀🦀🦀🦀🦀🦀🦀

      • SqueakyBeaver@lemmy.blahaj.zone
        link
        fedilink
        arrow-up
        2
        ·
        1 年前

        Alternatively:

        https://en.cppreference.com/w/cpp/io/manip/endl

        p.s. The site isn’t entirely mobile friendly

        (I’m a cppref lover tbh)

    • allywilson@lemmy.ml
      link
      fedilink
      arrow-up
      3
      ·
      1 年前

      From memory it’s a way to declare a line ending after your string.

    • jaybone@lemmy.zip
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 年前

      God bless your soul.

  • GideonBear@lemmy.ml
    link
    fedilink
    arrow-up
    15
    ·
    1 年前

    #define endl “\n”

  • Scrubbles@poptalk.scrubbles.tech
    link
    fedilink
    English
    arrow-up
    12
    arrow-down
    1
    ·
    1 年前

    Environment.NewLine()

    • tourist@lemmy.world
      link
      fedilink
      arrow-up
      8
      ·
      1 年前
      /* I'm new to this language so just imagine there is a new line here when it prints: */
      
  • besselj@lemmy.ca
    link
    fedilink
    arrow-up
    14
    arrow-down
    4
    ·
    1 年前

    \r\n gang

    • SpaceNoodle@lemmy.world
      link
      fedilink
      arrow-up
      19
      arrow-down
      1
      ·
      1 年前

      Get out

      • xmunk@sh.itjust.works
        link
        fedilink
        arrow-up
        4
        arrow-down
        1
        ·
        1 年前

        Yeah \r gang4lyfe

    • aport@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      1 年前

      Are you a modem by any chance?

      • besselj@lemmy.ca
        link
        fedilink
        arrow-up
        1
        ·
        1 年前

        No, I’m a teapot

  • lengau@midwest.social
    link
    fedilink
    arrow-up
    11
    arrow-down
    2
    ·
    1 年前

    os.linesep

    Lol jk none of my stuff runs on Windows anyway

  • xmunk@sh.itjust.works
    link
    fedilink
    arrow-up
    8
    ·
    1 年前

    I’m on side \PHP_EOL

    • grandel@lemmy.ml
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 年前

      I like that you added the absolute namespace identifier or whatever its called

      • xmunk@sh.itjust.works
        link
        fedilink
        arrow-up
        1
        ·
        1 年前

        I don’t always namespace but when I do I fully qualify.

  • SavvyWolf@pawb.social
    link
    fedilink
    English
    arrow-up
    6
    ·
    1 年前

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

    Java, of course.

  • lnxtx (xe/xem/xyr)@feddit.nl
    link
    fedilink
    English
    arrow-up
    5
    ·
    1 年前

    Rebel side \0

  • nope@jlai.lu
    link
    fedilink
    arrow-up
    5
    ·
    1 年前

    Environment.NewLine might exist in C#

    • MrScottyTay@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 年前

      It might do. I encountered it last week as I needed it for a powershell script. So it exists in that at least

    • HiddenLayer555@lemmy.ml
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      2
      ·
      1 年前

      Microsoft really creating the problem and then forcing you to use their solution.

  • pewpew@feddit.it
    link
    fedilink
    arrow-up
    7
    arrow-down
    2
    ·
    1 年前

    \r\n

  • bramen49@lemmy.ml
    link
    fedilink
    arrow-up
    4
    ·
    1 年前

    Well, Java has System.lineSeparator so, maybe no?

  • dave@feddit.uk
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 年前

    vbCrLf

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.

  • 19 users / day
  • 689 users / week
  • 1.66K users / month
  • 5.92K users / 6 months
  • 1 local subscriber
  • 42K subscribers
  • 1.94K Posts
  • 36.9K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.12
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org