News for hackers. Stuff that matters.
Re:Carbon Language: An experimental successor to C++ by mhh__ on Tuesday July 19, 2022 @05:15PM (#32158081)
Most C++ codebases would be exactly the same with or without a GC. Probably 90% of collective programmer-intuition about memory allocation is either completely wrong or from thinking about a scaling to a point that most products don't get anywhere near.
Re:Carbon Language: An experimental successor to C++ by dymk on Wednesday July 20, 2022 @12:01AM (#32161277)
Probably not, or they'd just be written in Java.
Re:Carbon Language: An experimental successor to C++ by mhh__ on Wednesday July 20, 2022 @12:26AM (#32161405)
There is more to performance than allocating memory. In fact some very performance-centric codebases do use a GC like unreal engine.

On the subject of games it always makes me chuckle when I see people complaining about garbage collection but then having 20 calls to malloc in their hot loop. All memory allocation is slow and not necessarily bounded.

I have written code that uses SoA, cache aware metaprogramming, inline asm, SIMD etc, with a GC because I knew I didn't need to allocate often.

On the subject of Java, I'm no fan of it but lots of projects would probably be fine - probably not quite as fast, but not horrifically so. On hackernews we only discuss extremely careful or expertly written code whereas in real life a lot people use C++ because it's what they got hammered into them at university 20 years ago as the fast language.

For example a lot of engineering and finance codebases are written in a very bad style of C++ code that would be improved by not having the programmers worry about memory too much - infrastructural code is more subtle, but most code serves a direct purpose like implementing some model. In these cases memory allocation is merely a means to an end rather than part of some grand strategy (i.e. it's not like writing a library)

Re:Carbon Language: An experimental successor to C++ by skl131313 on Wednesday July 20, 2022 @11:13AM (#32166905)
I love when people bring up that UE has a GC, if it was written in Java, do you think they would have built a GC on top of Java's GC?

I guess it depends on the GC at that point, 20 mallocs isn't a lot but like the GC in D, it pauses all threads to do it's collection when you allocate. There's also a few games that use C# that have a really bad stutter because of the GC. There's nothing they can do about that though.

Re:Carbon Language: An experimental successor to C++ by dataangel on Wednesday July 20, 2022 @10:54AM (#32166615)
Unreal Engine mostly uses GC for game world objects. Only C++ classes that inherit from a special base class and opt-in are subject to GC. If they used GC for everything the performance would be much worse.
Re:Carbon Language: An experimental successor to C++ by mhh__ on Wednesday July 20, 2022 @12:04PM (#32167746)
Sure, but I'm saying that most C++ code in the wild is probably firmly in the former category.