5 ms·
Really? For me the presence of a GC disqualifies D as the main replacement for C and C++.
by rowanG077 7y ago
Really? For me the presence of a GC disqualifies D as the main replacement for C and C++.
- mhh__ 7y agoHow much software genuinely requires not having a GC? If you don't want it, don't use it, but using it can make your software completely safe and fast (Garbage Collection is often faster than RC as long as pause times are acceptable, and added memory use). A lot of the standard library ranges are inherently lazy and therefore require no interaction with the GC. Exceptions are also nogc now.
- quicknir 7y agoIf you can tolerate GC then like 20 languages (as or less obscure than D) enter the conversation. If you can tolerate GC and the performance implications that go with it, then using C or C++ is rarely a good choice to begin with (well, other than legacy, which is a valid and common reason).
- mhh__ 7y agoD isn't defined by performance or memory management, however. There are many D features which are just blisteringly professional in how they approach software development: Using D is conducive to writing good software. Metaprogramming, for example, in D is obvious and almost fun. The compile times are ridiculous compared to C++, i.e. I can build the main D compiler in three different configurations in about 5sec on my machine.
- quicknir 7y agoI'm not saying that D is defined by that. I'm simply saying that if you're comparing to C or C++, you are talking about use cases that are defined by performance and/or memory management (or else, they are being used for legacy reasons). If you have a green field project that doesn't have massive performance concerns, and doesn't have to be specifically in C or C++ for other reasons (toolchain availability, available developer resources, etc), you probably aren't using C or C++. Some people would argue that you can use D for equally high performance things to C++, and make sure you use the GC very selectively, etc. However, you don't appear to be making that argument. If you aren't, then there's just no real point comparing C++ and D. If you don't have any of those requirements, and you are ok with obscurity, you have much stiffer competition from many other languages like Haskell, Kotlin, etc.
- WalterBright 7y agoThere are people who specifically use D for writing high performance applications. They find it faster than C++ for a rather subtle reason - D code is more plastic, meaning it is easier to refactor D code trying out different algorithms looking for a faster one.
- quicknir 7y agoI'm sure these people exist but they're the exception rather than the rule. The two biggest industries in SG14, the C++ low latency study group, are games and HFT. In both these areas, D penetration is pretty much zero. And in HFT at least while many features would be nice (especially reflection), I can't imagine it would be anything but a performance hit. Just the fact that the best D implementation for performance is llvm based, and most people do not find that llvm produces assembly as good as gcc or icc, is already an instant global hit.
- WalterBright 7y agoD reflection is at compile time, not runtime, so no performance hit.
- quicknir 7y agoI didn't intend to imply otherwise but I see my wording was unclear. I meant that D generally would be a hit, though it's only really speculation either way.
- p0nce 7y agoIf you use the same backend... no. They are both native languages with "no room below". llvm vs icc could be a hit, but that's all really.
- WalterBright 7y agoThere is no inherent reason that D code would be slower than C++ code. I should know, I've written a C++ compiler and know where the bloat is buried, and designed D to eschew features that would be inherently slower than the C++ counterparts. You can even turn off the runtime array bounds checking.
- scythe 7y agoUltimately, though, this is the real tragedy of D. It started as a C clone, and continues to be named like it's a C clone, but it is no longer a C clone. It is a general-purpose memory-aware compiled programming language inspired by C++, but it is pretty different by now! People expecting a C clone miss what else it has to offer. (Can it be a C replacement? Sure, but so can Rust/Swift/Go/etc)
- riffraff 7y agoI don't believe it ever was a C clone. I remember it always presented as a C _successor_, like C++, but in a different direction.
- makapuf 7y agoGo (and some others, swift surely) cannot be used as a C replacement since they need a runtime.
- pjmlp 7y agoJust like C does for calling into main(), doing floating point emulation if CPU not available, calling library initializers (common C extension), handling VLA allocations. Just because it is tiny does not make it inexistent. Then there is the whole POSIX, which is kind of runtime that wasn't made part of ISO C, but follows it everywhere.
- makapuf 7y agoIt's not necessarily tiny but it's optional (besides main() ). Linux kernel, baremetal embedded does not use this.
- pjmlp 7y agoLinux kernel surely used it during the time they had VLAs in, they are now mostly removed thanks to Google efforts reducing memory exploits on the Linux kernel. One just links another implementation, just like printf() vs printk().
- newacct77 7y agoThe garbage collector in D can be disabled, so what exactly is your point? Or are you just spouting out bullshit?
- dang 7y agoPlease don't be rude or aggressive in HN comments. It only makes this place worse, and we're trying to have a forum that doesn't go down in flames. https://news.ycombinator.com/item?id=20340078 https://news.ycombinator.com/item?id=20340078 was much better. https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- umanwizard 7y agoI’ve seen large, poorly written Java programs[0] where an entire core at 100% is dedicated to the GC. I have never seen that behavior for things like ~shared_ptr in C++ or similar languages. Then again, OOMing due to leaks is something you’re more likely to see in poorly-written systems in non-GC languages (Objective-C, C, C++, etc), so there are certainly trade offs. [0]: Maybe “poorly written” is unfair. Perhaps “written by people who are unaware of how to write code that performs well in a GC system”.
- krzat 7y agoProbably the most important usage of C are shared libraries. How well it will work if I have D library with it's own GC, another Go library with second GC and app written in C# with yet another GC?
- jcelerier 7y ago> Garbage Collection is often faster than RC as long as pause times are acceptable I have never in my life worked in any kind of software where this was remotely acceptable
- rowanG077 7y agoYou are right most software it doesn't matter if you have a GC. However then D is not competing against C and C++ it's competing against almost every other language.
- newacct77 7y agoD's garbage collector can be disabled, so would you mind elaborating?
- CameronNemo 7y agoHow well is that supported by the ecosystem?
- rowanG077 7y agoYes and then you can't use most of the nice features of D. Forget about libraries.
- nicwilson 7y agoMere presence shouldn't. If you never allocate from it (which is able to be verified very easily with the @nogc attribute), it will never trigger. You can disable it and trigger when you feel it is needed. You can choose to just leak. The default GC is OK, but not great. However it recently was made multithreaded in the mark phase so it is much faster than it used to be. There is a fork based (on linux only IIRC) GC, used by several companies for hard realtime systems, that marks and sweeps in a separate process with CoW pages.
- WalterBright 7y agoThe -betterC switch to the compiler compiles a D subset that doesn't have a GC.