dormi.zone
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Hellfire103 to Programmer Humor@lemmy.mlEnglish • 1 month ago

Does this exist anywhere outside of C++?

lemmy.ml

message-square
62
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
175

Does this exist anywhere outside of C++?

lemmy.ml

Hellfire103 to Programmer Humor@lemmy.mlEnglish • 1 month ago
message-square
62
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
alert-triangle
You must log in or register to comment.
  • @SpaceNoodle@lemmy.world
    link
    fedilink
    50•
    edit-2
    1 month 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:
      link
      fedilink
      36•1 month 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
        49•1 month ago

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

      • @SpaceNoodle@lemmy.world
        link
        fedilink
        7•1 month ago

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

        • Oriel Jutty :hhHHHAAAH:
          link
          fedilink
          16•1 month 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.

          • @SpaceNoodle@lemmy.world
            link
            fedilink
            7•1 month ago

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

            • AnyOldName3
              link
              fedilink
              4•1 month 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.

          • @zenforyen@feddit.org
            link
            fedilink
            3•1 month 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.

  • jecxjo
    link
    fedilink
    English
    23•1 month 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.

    • @lud@lemm.ee
      link
      fedilink
      3•1 month ago

      but the goal should always be to write as optimal as possible.

      Within reason.

      Over optimization is a curse on getting done.

    • @aport@programming.dev
      link
      fedilink
      2•1 month ago

      Who in the hell is using iostreams in an RTOS

      • jecxjo
        link
        fedilink
        English
        2•1 month ago

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

      • @KeenFlame@feddit.nu
        link
        fedilink
        2•1 month ago

        Several. Probably dozens

  • @UpperBroccoli@lemmy.blahaj.zone
    link
    fedilink
    20•1 month ago

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

  • @unlawfulbooger@lemmy.blahaj.zone
    link
    fedilink
    17•1 month ago

    What the heck is endl???

    • @vapeloki@lemmy.world
      link
      fedilink
      40•1 month 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
        link
        fedilink
        English
        3•1 month ago

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

        • @ClemaX@lemm.ee
          link
          fedilink
          9•1 month ago

          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
          2•1 month ago

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

    • Hellfire103OP
      link
      fedilink
      English
      10•
      edit-2
      1 month ago

      Instead of this:

      std::cout << "Hello world.\n";
      

      You can do this:

      std::cout << "Hello world." << endl;
      
      • @Daedskin@lemm.ee
        link
        fedilink
        6•1 month ago

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

      • @ReversalHatchery@beehaw.org
        link
        fedilink
        English
        1•1 month ago

        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
          3•1 month ago

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

          • @Cyberfishofant2@lemm.ee
            link
            fedilink
            English
            1•1 month ago

            same here. AP isn’t standardized enough, apparently

            • @ReversalHatchery@beehaw.org
              link
              fedilink
              English
              1•
              edit-2
              1 month ago

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

    • gon [he]
      link
      fedilink
      English
      7•1 month ago

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

      • @unlawfulbooger@lemmy.blahaj.zone
        link
        fedilink
        12•1 month ago

        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
          1•1 month ago

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

          • @unlawfulbooger@lemmy.blahaj.zone
            link
            fedilink
            2•1 month ago

            🦀 🦀🦀🦀🦀🦀🦀🦀

      • @SqueakyBeaver@lemmy.blahaj.zone
        link
        fedilink
        2•1 month ago

        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
      3•1 month ago

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

    • @jaybone@lemmy.zip
      link
      fedilink
      English
      2•1 month ago

      God bless your soul.

  • @GideonBear@lemmy.ml
    link
    fedilink
    16•1 month ago

    #define endl “\n”

  • @besselj@lemmy.ca
    link
    fedilink
    14•1 month ago

    \r\n gang

    • @SpaceNoodle@lemmy.world
      link
      fedilink
      20•1 month ago

      Get out

      • @xmunk@sh.itjust.works
        link
        fedilink
        4•1 month ago

        Yeah \r gang4lyfe

    • @aport@programming.dev
      link
      fedilink
      2•1 month ago

      Are you a modem by any chance?

      • @besselj@lemmy.ca
        link
        fedilink
        1•1 month ago

        No, I’m a teapot

  • Scrubbles
    link
    fedilink
    English
    13•1 month ago

    Environment.NewLine()

    • @tourist@lemmy.world
      link
      fedilink
      9•1 month ago
      /* I'm new to this language so just imagine there is a new line here when it prints: */
      
  • @lengau@midwest.social
    link
    fedilink
    12•1 month ago

    os.linesep

    Lol jk none of my stuff runs on Windows anyway

  • @xmunk@sh.itjust.works
    link
    fedilink
    9•1 month ago

    I’m on side \PHP_EOL

    • grandel
      link
      fedilink
      English
      2•1 month ago

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

      • @xmunk@sh.itjust.works
        link
        fedilink
        1•1 month ago

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

  • pewpew
    link
    fedilink
    7•1 month ago

    \r\n

  • lnxtx (xe/xem/xyr)
    link
    fedilink
    English
    5•1 month ago

    Rebel side \0

  • SavvyWolf
    link
    fedilink
    English
    5•1 month ago

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

    Java, of course.

  • @nope@jlai.lu
    link
    fedilink
    5•1 month ago

    Environment.NewLine might exist in C#

    • MrScottyTay
      link
      fedilink
      English
      2•1 month ago

      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
      1•1 month ago

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

  • Digital Mark
    link
    fedilink
    English
    5•1 month ago

    If you write to a text (as opposed to binary) stream, \n produces \n or \r\n (or \r if old enough) depending on platform just fine.

    Nobody should be using C++ anyway, but plenty of languages have silly system newline constants, which do nothing useful.

    • MrScottyTay
      link
      fedilink
      English
      4•1 month ago

      Why should no one be using c++?

      • @easily3667@lemmus.org
        link
        fedilink
        English
        4•
        edit-2
        10 days ago

        deleted by creator

        • @thebestaquaman@lemmy.world
          link
          fedilink
          1•1 month ago

          Memory unsafe C++ is a choice. With modern C++ you have no excuse for accessing raw pointers or arrays without range checking if memory safety is a priority.

          • Oriel Jutty :hhHHHAAAH:
            link
            fedilink
            3•1 month ago

            Yeah, just don’t make any mistakes and you’ll be fine. Come on guys, how hard can it be?

            • @thebestaquaman@lemmy.world
              link
              fedilink
              1•1 month ago

              As I said: There are tools in place in modern C++ that are designed to catch the errors you make. If you are using a raw pointer when you could have used a reference, or accessing an array without range checking, those are choices you’ve made. They may be valid choices in your use-case, but don’t go complaining that the language is “unsafe” when it gives you the option to code with guard rails and you choose to forgo them.

              • @Harlehatschi@lemmy.ml
                link
                fedilink
                1•1 month ago

                I’m a full time C++ developer, mostly doing high performance data processing and some visualization and TUI tools, and as someone loving C++, it’s not as simple as you frame it. In sufficiently complex code you still have to deal with these problems. Rust has some good mechanisms in place to avoid these and there are things on the way for c++26 though.

                • @thebestaquaman@lemmy.world
                  link
                  fedilink
                  1•1 month ago

                  I don’t mean to say that C++ is in any way without faults. If performance is crucial, that can definitely be a reason to forgo some of the guard-rails, and then you’re on your own.

                  I guess my issue with the “C++ is unsafe”-trope, is that it usually (in my experience) comes from people not having heard of all the guard-rails in the first place, or refusing to use them when appropriate. They write C++ as if they were writing C, and then complain that the language is unsafe when they’ve made a mistake that is easily avoided using stl-containers.

        • MrScottyTay
          link
          fedilink
          English
          1•
          edit-2
          1 month ago

          I think the memory stuff is pretty good nowadays. I’m sure I saw modern C++ can have a garbage collector. And the syntax is only runelike until you learn it, like any language really. As an industry C# developer I’ve recently taken up C++ as a hobby to better learn the workings of low level code and I’ve been enjoying it so far.

          • @easily3667@lemmus.org
            link
            fedilink
            English
            1•
            edit-2
            10 days ago

            deleted by creator

  • @bramen49@lemmy.ml
    link
    fedilink
    4•1 month ago

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

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.
  • 1.07K users / day
  • 1.52K users / week
  • 2.22K users / month
  • 10.1K users / 6 months
  • 35.6K subscribers
  • 1.71K Posts
  • 37.6K Comments
  • Modlog
  • mods:
  • @AgreeableLandscape@lemmy.ml
  • @cat_programmer@lemmy.ml
  • BE: 0.19.3
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org