6 ms·
Don't use it? Nothing can salvage C++ at this point. It needs to be EOLed and put to rest.
by armitron 11y ago
Don't use it?
Nothing can salvage C++ at this point.
It needs to be EOLed and put to rest.
- vvanders 11y agoWhen you give me a language that I can specify explicit memory layout and support for generics we can talk. Otherwise C++ is going to continue filling the space for large, performance sensitive applications.
- pif 11y agoYes, support for generics. _Full_ support for generics. And RAII!
- chncdcksn 11y agoDoes Rust fit into those specifications? I understand library support is probably not quite there yet, but I was under the impression it could fill the role of C/C++.
- vvanders 11y agoThey get close but I think there's a few restrictions(rightly so from a safety perspective) that keep untyped arena allocators and in-place loading from working(see FlatBuffers for a fantastic library for in-place loading). Edit(since I can't reply yet to child): By in-place loading I don't mean placement new(which untyped arena covers). Usually in-place loading means constructing an object(usually just by reinterpret_cast<T*>(data)) over a block of memory read in from disk/network such that all data members "line up" with data as it was serialized. This also includes the ability to mutate the in-place data but have initialized to some sane values. 99% of the time this is paired with either some sort of preprocessor(usually written in the same compiler as the reader to guarantee data matching). Quite a few games use this technique to allocate levels/fixed entities such that once you've pulled them disk you just need to do some trivial pointer fixup and away you go. There's some pretty incredible speed increases(100-200x) but obviously it's incredibly fragile and complex to get right. Flatbuffers does a good job of trading off fragility for usability by encoding offsets in the placement data. Reading data is slightly slower due to needing to calculate the offset into the data but on the plus side it doesn't depend on compiler specific layouts :).
- steveklabnik 11y agoBy "in-place loading" do you mean placement new? And while Rust does have restrictions for safety, unsafe should give you the power to do anything equivalent C or C++ can do. Of course, many idioms are different, especially for safe Rust.
- steveklabnik 11y ago> Edit(since I can't reply yet to child): HN #protip: if you click on comment link itself, it will let you comment earlier. Ah, I see. This isn't my area of specialty, but it _sounds_ like what Cap'n Proto does? Anyway, it doesn't sound impossible, though it might not be the most ergonomic. I'll check out that library, thanks.
- vvanders 11y agoLearn something new every day! Yeah, Cap'n Proto is very similar, FlatBuffers has the advantage in that it compiles against almost all versions of Visual Studio where Cap'n Proto unfortunately decided to use some C++14 features. FWIW I think I've seen some ports of FlatBuffers into Rust since it's much easier to handle due to the offsets and translation on return value. The former(matching compiler layout) was the part that I was mentioning that seems like something a bit gnarlier than rust would like.
- steveklabnik 11y agoGotcha. Yeah, so the Rust Capn' Proto does compile-time codegen to write out all the structures, so the grossness is hidden away, or at least, you don't have to deal with writing it out. I believe it's basically the same as the C++ version.
- Ace17 11y agoThe D programming language anyone?
- CyberDildonics 11y agoIf D manages to get garbage collection out of their standard library and there is a one click IDE with step through debugging and code completion, then D could be a major contender. Right now it has a few big barriers that prevent it from taking significant market share on C++.
- WalterBright 11y agoD has full generics, explicit memory layout, and RAII.
- vvanders 11y agoFrom what I've seen of D(I haven't used it in detail) there isn't enough materially different(like say Rust) to warrant the loss of libraries and IDE integrations available to C++.
- Ace17 11y agoAmongst the parts of Phobos having an equivalent in the C++ standard library (algorithm, string, etc.), which ones still require garbage collection?
- WalterBright 11y agoOnly one of the algorithms in Phobos still uses the GC.
- usefulcat 11y agoAlso, library support.
- potbelly83 11y agoFree Pascal?
- krylon 11y agoNo flame-bait here, but if you are seriously looking for that, how about Ada? Realistically, I don't see C++ going away for a looong time (if ever), simply because of the huge amounts of code written in it. But if one were looking for an alternative that matches C++ both in performance and control over memory layout, Ada is where I would start. It has generics, you can do OOP, it avoids many of the syntactic pitfalls of C++... As a bonus, the language standard and the rationale are available for free.
- supernintendo 11y agoI can think of a few reasons to avoid Ada. For one, resources and community for this language are basically nonexistent compared to C++. The history of the language is obscured in proprietary implementations which has led it down the same road as Pascal in terms of longevity. Ada has "bad parts" in the same way that C++ does, although this is mitigated by SPARK. Concurrency / tasking in Ada is simple and beautiful, however. One of the most compelling features of the language, especially coming from C++.
- marvy 11y agoHow much does Ada rely on garbage collection?
- Solarsail 11y agoDoesn't have one. Reference counting is available as a (what looks like third-party) library: http://www.adacore.com/adaanswers/gems/gem-97-reference-counting-in-ada-part-1/ http://www.adacore.com/adaanswers/gems/gem-97-reference-coun... I guess you could say that is even less reliance on GC than C++ has, with smart pointers being part of the standard.
- tjr 11y agoI have observed a strong trend in avionics software development to move away from Ada towards C++. I have not yet heard a concrete reason why. I might guess that it's easier to hire people with some existing C++ experience than with Ada experience, but understanding the programming language is pretty inconsequential compared to understanding the product domain.
- adrianm 11y agoCommon Lisp's foreign function interface (either implementation specific or cross-platform a la CFFI) allows for the explicit definition of how a foreign structure should be laid out in memory. Even if I'm not using Lisp for the end product, whose SLA may not permit a runtime with garbage collection, I always find it invaluable to define low-level structures with a Lisp whose machine code compiler is available at runtime for experimental interactive development. A free and open source Lisp that you might enjoy experimenting with is SBCL, available from http://www.sbcl.org http://www.sbcl.org. Load up the REPL, and follow the manual available here http://sbcl.org/manual/index.html#Foreign-Function-Interface http://sbcl.org/manual/index.html#Foreign-Function-Interface. SBCL also allows you to interactively augment the machine code compiler, install new intrinsics, and disassemble any function interactively. Even if you never use it for production code directly, it might become an invaluable tool in your low level development process.
- ska 11y agoIn favor of what? There are lots of things it would be crazy to write in c++ in 2015 ... on the other hand there are some things that really don't have compelling alternatives.
- vvanders 11y agoI feel like Rust is getting there but AFAIK there isn't support for an untyped arena allocator(just homogeneous arena allocator) which you need if you don't want to be playing around with raw byte arrays to do Data Oriented Design. I think that they'll get there but it's going to take a bit. Also, I'm not aware of anything that has a wider set of compile targets(all the way to some larger uC up to web via emscripten).
- blinkingled 11y agoHave an up vote for a completely fair point. They keep adding stuff to C++ when the language is already ungodly complex and ambiguous enough. Just stick with C if you need low level control.
- CountSessine 11y agoI don't completely disagree with you, but in practice it's really hard to go back to C sometimes - there are a lot of tasks that are painful and error-prone to write in C. Complicated initialization and teardown logic that can fail mid-way is much easier to write incorrectly without RAII and scoped initialization objects, for example.
- AnimalMuppet 11y agoBut see, I only need low-level control for parts of a project. For the rest of it, it's really nice to have the STL, and the move operators, polymorphism, and and and...