Why are C++ devs afraid of ToString()

Don't get me wrong i'm not hating on C++ or trying to shill rust but why do C++ devs prefers to do something like this
ostream &operator<<( ostream &output, const Point &P ) {
output << "( " << P.X<< ", " <<P.Y << ")" ;
return output;
}

Instead of

String ToString() {
return "(" + this.X + "," + this.Y + ")"
//or std::format
return std::format("({}, {})", this.X, this.Y);
}

Thalidomide Vintage Ad Shirt $22.14

The Kind of Tired That Sleep Won’t Fix Shirt $21.68

Thalidomide Vintage Ad Shirt $22.14

  1. 3 weeks ago
    Anonymous

    Why would you want to allocate a new string everytime you call toString when you can just append stuff to an already existing stream

    • 3 weeks ago
      Anonymous

      >why do C++ devs
      generalization fallacy. C++ is infamously segmented in that most developers end up rolling their own STL and use the bits out of the vendors library they like. if you actually look at most code in production, frick all people actually use streams. nobody outside of first year computer science homosexuals actually use stream operators. they're only here to pander to the dumbc**ts that think programming is just reading a line from stdin and writing numbers to stdout.

      Fun factoid: Douglas McIlroy, BORN IN New York CITY, a mathematician and language "designer," is the one who pushed for C++ stream operators after his previous life achievement of shitting up POSIX io with pipe operations in place of actual interfaces. if you cant tell by those descriptors already, he's a worthless israelite homosexual.

      frick off nocoding homosexual. it doesnt matter whether you overload the << or += operator.

      • 3 weeks ago
        Anonymous

        >nobody outside of first year computer science homosexuals actually use stream operators

        $ find . -name "*.cpp" -o -name "*.h" | xargs grep "operator<<" | wc -l
        362

        Yeah that's just not true. They're not ubiquitous, I see plenty of toString-like methods in real C++ codebases, but it's consider idiomatic C++ to overload the operator. Perhaps most commonly they're used for things like debug/diagnostic logging.

        t. someone who has probably been working on ""Real"" C++ longer than you

        • 3 weeks ago
          Anonymous

          >linux gay thinks grepping his ganu/gentoo source directory proves anything
          >fell for the reddit midwit meme of citing STOODIES and IMPERICAL DATA without actually putting it into context, stating his hypothesis, and drawing a conclusion
          >skips past the part that'd make his response look like a dumbass
          >IM THE EXPERT I SWEAR. TRUST ME BRO
          average IQfy midwit

          • 3 weeks ago
            Anonymous

            it's my work codebase moron. I work at an F500 and you probably wouldn't be posting on this forum if not for that codebase lol

          • 3 weeks ago
            Anonymous

            >it's my work codebase moron. I work at an F500 and you probably wouldn't be posting on this forum if not for that codebase lol
            you're just digging yourself a deeper hole. there's not "probably" about it. nobody give heres a single solitary frick about your alleged non-neet status. you cannot even put data into perspective or assert anything without a "probably". also, nobody working for a F500 is posting partial and completely useless stats about their codebase to flex on IQfy. even if they were, congrats on feeding a glowBlack person friendly website your IP and an admission you dont give a frick about your NDA (and its guarded trade secrets)

          • 3 weeks ago
            Anonymous

            Go back to studying for your algo class zoomie moron. You should be kissing senior engineer feet for gracing you with wisdom.

          • 3 weeks ago
            Anonymous

            Say that again, but without crying.

          • 3 weeks ago
            Anonymous
          • 3 weeks ago
            Anonymous

            also: grep misses *std::*ostream
            also: fricking std streams
            yea you're a larping grifter.

          • 3 weeks ago
            Anonymous

            I work for a "Fortune 50" and I don't care and it's still bad practice and a bad stdlib feature. "We" use it out of practicality. just admit it.

          • 3 weeks ago
            Anonymous

            Of course we use it out of practicality. Why the frick else would we use it? Not arguing the virtues of it, just whether it's actually used in industry, which is most definitely is.

        • 3 weeks ago
          Anonymous

          >t. someone who has probably been working on ""Real"" C++ longer than you
          If this were true, surely you would realize that there is no such thing as idiomatic C++, because different people using it subscribe to loads of different idioms with very little common ground between them.

      • 3 weeks ago
        Anonymous

        >Fun factoid: Douglas McIlroy, BORN IN NEW YORK CITY, a mathematician and language "designer," is the one who pushed for C++ stream operators after his previous life achievement of shitting up POSIX io with pipe operations in place of actual interfaces. if you cant tell by those descriptors already, he's a worthless israelite homosexual.
        but pipes are good and you are not forced to use C++ streams

        • 3 weeks ago
          Anonymous

          >but pipes are good
          everything is text and can be piped between small programs of the UNIX philosophy is a cancer on the industry. only toy programs can deal with this shit. everything else justifies real interfaces. we're so desperate that you have c**ts going around using HTTP and protobuf for everything.

          • 3 weeks ago
            Anonymous

            >everything is text and can be piped between small programs of the UNIX philosophy is a cancer on the industry.
            don't you mean "everything is a file"? I don't know if I can take you seriously when you misstate aphorisms like that. pipes are IPC. are you complaining about unix software that uses machine unfriendly output? they're increasingly being patched to include JSON output or something similar, what is the issue really? btw, what industry?

          • 3 weeks ago
            Anonymous

            >everything is text and can be piped between small programs of the UNIX philosophy is a cancer on the industry.
            don't you mean "everything is a file"? I don't know if I can take you seriously when you misstate aphorisms like that. pipes are IPC. are you complaining about unix software that uses machine unfriendly output? they're increasingly being patched to include JSON output or something similar, what is the issue really? btw, what industry?

            nocoder, could one of you fellas answer my questions?

            What's the issue with pipes exactly? They're text only? since when? They're just byte streams and agnostic to what you're sending over them aren't they?

            What exactly is an interface? Do you want a unified standard for communication like sockets? And if pipes don't meet your demands what issue is there with using a shared memory space for inter process communication?

      • 3 weeks ago
        Anonymous

        >complains about generalizing
        >says "nobody outside of first year computer science homosexuals actually use stream operators"
        sir?

  2. 3 weeks ago
    Anonymous

    For me it's
    printf("%i dead Black folkn", INT_MAX)

    • 3 weeks ago
      Anonymous

      t.

  3. 3 weeks ago
    Anonymous

    they prefer the latter. former is just a cutesy hack that is god awful in practice.

  4. 3 weeks ago
    Anonymous

    Its an overload for the string operator so you can do std::cout << myClass

  5. 3 weeks ago
    Anonymous

    >overloading the bitshift operator to concatenate strings
    Stroustrup gets the rope.

  6. 3 weeks ago
    Anonymous

    Sepples programmers think more complex == better. It's impossible to reason with them, just leave them be.

    • 3 weeks ago
      Anonymous

      nah, sepples programmers are slowly unfricking their broken shitware, sadly they also add a bunch more for memes, but hey, a win is a win.
      LOOK MA NO COUT BROKEN BULLSHIT
      https://en.cppreference.com/w/cpp/io/print
      whoever invented cout, the string builder shit and others needs to be roped. streams are fricking awful.

  7. 3 weeks ago
    Anonymous

    You are supposed to define your own formatter so that your type would work with std::format. It allows you to do the formatting while avoiding unnecessary allocations.

  8. 3 weeks ago
    Anonymous

    no one really does do that, most to/from conversion functions are template metaprogramming hell
    although apparently the nodejs devs convinced themselves they were high performance and codebase uses them extensively for some dumb reason
    std::format would be the most modern thing while std::to_chars and std::from_chars are meant to be the ultra-fast non-allocating lightweight converters
    that being said i've seen arguments for using streams specifically for buffered IO, so like a stringbuffer in java

  9. 3 weeks ago
    Anonymous

    IIRC to_string in c++ uses the global locale which uses a lock to access so only one double at a time can be converted to a string. Though I think it's fixed in newer c++ versions.

    • 3 weeks ago
      Anonymous

      That depends on implementation and some indeed have/had such issues. But it is not exclusive to C++, I think in iOS st some point snprintf would hold a global locale long for too long.

  10. 3 weeks ago
    Anonymous

    toString is a satanic invention by Java, simple as

Your email address will not be published. Required fields are marked *