9 ms·
How does D improve on C++17?
- TheAceOfHearts 12y agoD looks like a really interesting language, I had never checked it out prior to reading this. unittest blocks look like they'd be super helpful. And it has modules, which I consider a must-have. In what areas would D excel? What are its downsides? What did you like and dislike the most? I'd be really interested in hearing about people's experiences.
- Profan 12y agoAs a D programmer currently making a small game engine + networked rts game in the language, invariant blocks are another thing I really enjoy about the language: http://dlang.org/contracts.html#Invariants http://dlang.org/contracts.html#Invariants Lets you specify contracts which are asserted on construction and destruction, it's great. The meta programming is also wonderful for things like serialization of data, simply iterating over a type's members at compile-time to generate serialization code, cutting out much bloated code. It's worth noting that it's metaprogramming for humans, _compared_ to c++, but sometimes leaves a bit to be desired documentation-wise, all the building blocks are there, but sometimes you'd like to not need to reinvent the wheel every time you attempt some metaprogramming-related task. Things I don't enjoy include the core language's reliance on the GC, including things like exceptions relying on GC allocations. Thankfully they've made it a bit easier to track down things which may allocate gc memory lately with accompanying flags to the compiler, which prints a trace of where it may happen.
- yoklov 12y agoI'm always on the look out for improvements to C++, and it's been a while since I looked at D... Hope you don't mind if I ask you a couple questions. Can you still turn off the GC? Lets say I don't like exceptions, and that I don't mind implementing library code on my own, would turning GC off impact anything else? How is the story for deploying executables to mac/win/lin? Is it as easy as C/C++? Also, do you know if anybody's shipped high quality games with it before? It's been a while now, I'd hope so, but I haven't heard of any. Pretty sure no AAA games have used it but maybe some indie?
- CyberShadow 12y ago> Can you still turn off the GC? Lets say I don't like exceptions, and that I don't mind implementing library code on my own, would turning GC off impact anything else? You can turn off the GC in the sense that memory allocation will always request more memory from the OS instead of occasionally starting a collect cycle. However, you can alternatively use manual memory management (malloc/free, allocators/RAII on top of that, etc.), which will never trigger the GC. > How is the story for deploying executables to mac/win/lin? Is it as easy as C/C++? Yes. I think for Posix systems, you can optionally link dynamically to the runtime/standard library. > Also, do you know if anybody's shipped high quality games with it before? IIRC, Remedy Games used D for engine scripting on XBox 360. Manu Evans talked about this at DConf 2013. Here's a commercial indie game written in D: http://www.inventivedingo.com/mayhemig http://www.inventivedingo.com/mayhemig
- yoklov 12y agoWell, a couple things about it make me nervous, but CTFE and a not horribly broken compilation model might make it worth trying out next weekend...
- Profan 12y agoYou can definitely survive without the GC, personally I've gone through eliminating exceptions entirely and implementing my own allocators throughout. There are a few gotchas sometimes, like array literals of certain kinds sometimes allocating when you don't expect them to, but these can usually be sorted. Something which also might bite you, but can be caught with the gc-tracking compiler flag, is the fact that delegate _closures_ use the GC, regular delegates however will not need the GC, one thing to keep in mind. There's quite a bit of info about how the GC impacts things, and how to get by without it around, so I think you'll survive without it's presence. Lately as well, efforts to annotate portions of the standard library which don't use the GC at all with a special annotation @nogc has been underway, which makes it explicit if something can allocate or not (this is transitive, so a @nogc annotated function can only call @nogc annotated functions which can't do any gc allocation in turn).
- WalterBright 12y agoA bit of an overlooked area where D excels are its support for transitive immutability and function purity. We're discovering more and more things that are now practical because of this.
- ekianjo 12y ago> In what areas would D excel? Making games? :) I'm half joking here, Kenta Cho has made tons of shoot'em up games, mostly written in D (and released as Open Source) for years: https://en.wikipedia.org/wiki/ABA_Games https://en.wikipedia.org/wiki/ABA_Games
- giancarlostoro 12y agoI'm curious how many people out there on HN actully use D and what for? I don't typically see D based projects here on HN so it would be interesting to find out about any use cases where D was found a perfect fit.
- maxerickson 12y agoWalterBright uses it in his compiler.
- RyJones 12y agoHe's a little more involved in D than using it in his compiler :)
- edmccard 12y ago>WalterBright uses it in his compiler. Ironically, the dmd compiler is written in C++.
- WalterBright 12y agoD didn't exist when the dmd compiler was written. But Daniel Murphy has written a C++ to D converter, and it's looking like the next release will have dmd written in D.
- edmccard 12y ago>it's looking like the next release will have dmd written in D. Is that going to make it trickier for GDC/LDC to stay in sync with DMD? (Either way, it's exciting news!)
- WalterBright 12y agoTricky or not, they're on board with the jump.
- 12y ago
- CyberDildonics 12y agoD is a fantastic language. C++ is so difficult to unseat as a systems language now since it is back as a moving target which is both evolving and has extremely robust tools to go with it. Challenging it on the language level is not enough.
- fsloth 12y agoYeah. C++ has so good tooling that despite what new language I try, I always hit some implementation, ecosystem or tooling issue that always leads me to conclude I would have been more productive with C++. Which sucks monkeyballs as aesthetics go.
- ridiculous_fish 12y ago> D has no need for a preprocessor How does this work, specifically conditional compilation? I have lots of code like this: #if __APPLE__ /* do things the OS X way */ #else /* do things the Linux way */ #endif Where the OS X way calls functions that do not exist on Linux, and vice-versa. How does D handle this?
- vitaut 12y agoIn many cases you don't need preprocessor for this even in C++. For example you can detect the availability of system functions using function overloading as described in http://zverovich.net/2015/03/13/reliable-detection-of-strerror-variants.html http://zverovich.net/2015/03/13/reliable-detection-of-strerr...
- kevinnk 12y agoMaybe someone with more D experience can chime in, but D has conditional compilation (ie "static if") http://dlang.org/version.html http://dlang.org/version.html
- WalterBright 12y agoCheck out https://github.com/D-Programming-Language/phobos/blob/master/std/file.d https://github.com/D-Programming-Language/phobos/blob/master... at line 33 and on. You'll see: version (Windows) { ... } etc. For the specification on how this works: http://dlang.org/version.html http://dlang.org/version.html The salient point is that conditional compilation in D is not text based, it is AST based. Furthermore, for 'static if', the conditional expression has access to the full symbol table and power of the D language - it is not a separate preprocessor language with its own rules and separate symbol table.
- ridiculous_fish 12y agoThank you for the reply. That's very elegant!
- deleted 12y ago[deleted]
- jA_cOp 12y agoI was working on a similar article just a couple of weeks ago for the D wiki, but I wanted to focus on the really big things, and I want to include more examples: http://wiki.dlang.org/Coming_From/C_Plus_Plus_WIP_article http://wiki.dlang.org/Coming_From/C_Plus_Plus_WIP_article
- p0nce 12y agoYeah, my article is a bit of a quickie and not very good, I didn't expect people would post them here and on reddit. Moreover, it isn't a big picture post.
- iwwr 12y agoD looks great, but I feel like depending on a GC is kind of a deal-breaker. If that is accurate, then D fills the same niches as Google's Go rather than C++'s. Rust looks more like a proper replacement for C++.
- f3llowtraveler 12y agoYou can still "delete" by hand in D. The GC just does it if you fail to.
- ryanobjc 12y agoIs now the time for D? I really wonder, I am not really sure. Certainly a lot of languages go thru a period of obscurity before success, but I'm still uncertain. The one issue that sticks for me was the dual standard libraries. Just seems so messy.
- WalterBright 12y agoThe dual library issue ended 7 years ago or so.
- ryanobjc 12y agoenh shows how much i know. Honestly, I'm pretty excited for Rust. Having a strong proof of lifetime enforced by compiler is very compelling idea.
- frankzinger 12y ago> D has a package manager. C++ has none that is popular in its community. Therefore, using a third-party library is many times easier. This comes up all the time in reference to C++. C++ doesn't need a package manager because it has excellent support from distro package managers. Most libraries are in the system package manager. And yes, sometimes you need a newer version of a package or one not quite widely-used enough to be in the system package manager, in which case you need to do compile it yourself or install it manually. But that is a problem common to all package managers and there is nothing about D which will make it any easier.
- p0nce 12y agoAlmost every C++ codebase out there vendor all dependencies. Looks like they are not using the system package manager. Windows has no package manager with such library releases. Language package managers have problems, but they do make the work easier. Anyone here unhappy with pip?
- frankzinger 12y ago> Almost every C++ codebase out there vendor all dependencies. Looks like they are not using the system package manager. Yeah, e.g. Chromium. But that was also the reason why Fedora refused to provide packages for Chromium. Distros don't like projects that include their own versions of libraries because it goes against how things are supposed to work (maintenance and, by implication, a security nightmare). I know that there are many C++ projects in the various distro package repos, and no way do 'most of them' include their own copies of dependencies.
- p0nce 12y agoIn the closed source world I'd say most codebases are like Chromium (difficult to say of course). It's a bit like distributing an application with binary libraries and a no-go for security indeed.
- frankzinger 12y ago
- sprw121 12y agoD is a awesome language to work with, it's got many useful language features that make the activity of code writing a pleasure. - I hope this criticism is taking constructively. However not a beat a dead horse, but if you want to process more than a trickle of data in it you run into problems with the GC really quickly. I really feel the language would be better off without the GC. These are not the same issues address by the JSON compiler post or w/e that surfaces a couple months ago. From what I can tell, theres a global lock around everything in the GC, including allocations. In a multi-core world, this just simply doesn't work and it one of the major pain point of the language. I write data-intensive processing on high core count machines (32), and have had to resort to 0-allocation strategies, or in map-reduce contexts actually sharding at the process level, writing the results to disk, and then running a reducer process over the results. You can write performant D code, but you give up large amounts of code safety. It's essentially just whatever you'd write in C++ without the ownership semantics it gives you. You can't have a core part of your language being an essentially unavoidable massive point of contention. I've literally seen 20x or more speedups in multithreaded cases just by making sure I reuse every buffer rather than create new ones. I feel this is really holding back an otherwise great language to work in. This is discussed in the reddit thread in more detail.
- pjmlp 12y agoWhile true, it is more a consequence of quality not of having a GC. D with an Hotspot comparable GC quality would be quite good.
- Zardoz84 12y agoI got a speedup of around 13,32 on a 16 core Opteron machine a few years ago, using a simple parallel foreach on a N Body problem simulator. I didn't do anything special for it. I thought using SIMD to accelerate it more on the integrator and acceleration calculation, inside of the parallel for.
- chrisseaton 12y agoUnless you are creating or destroying bodies then your n-body implementation won't need to allocate any memory will it? So is it relevant to what he's talking about?
- kruczek 12y ago> No more header files, today > Even when C++ compilers implement modules and you can finally use them, headers will still survive alongside modules for backward compatibility. Uh, that one is just weird. So, a reason to use D is because C++ can support older projects?
- avinassh 12y agoKinda related: Apple's blog post on how they borrowed an idea from D, about assert statements: https://developer.apple.com/swift/blog/?id=15 https://developer.apple.com/swift/blog/?id=15
- pyabo 12y agoI use C++ but I don't really like it, but ... we need all the libraries that exist in C++ rewritten in D. And also, the same compiler support in the development frameworks. Otherwise, it will be a failure.