6 ms·
I'll be honest, D looks like a pretty inconsistent language. It has a lot of useful features for sure, but—having not used it—seemingly of the kitchen sink vari
by nynx 6y ago
I'll be honest, D looks like a pretty inconsistent language. It has a lot of useful features for sure, but—having not used it—seemingly of the kitchen sink variety.
- mhh__ 6y agoConsistently pragmatic, is the philosophy, really. There are some pain points that could probably go but realistically the aim is to make writing efficient code easy and abstract code even easier within the same language. If you learn D you get to avoid a bunch of legalese compared to C++, and lots of runtime bugs compared to Python - there are more features to learn, but they generally make quite a lot of sense when you need them e.g. Ada-style contract programming is extremely useful the moment you don't have it.
- einpoklum 6y agoCan you point to somewhere which makes the case for D vs C++ as of 2020 or so? I always had the sense - without seriously looking into it though - that D was about avoiding some of the mistakes/mis-features of C++, but C++ is always getting new stuff, which doesn't sit exactly well with what D has chosen, and then it plays somewhat clunky catch-up. But I may be very wrong.
- mhh__ 6y agoC++ has improved a lot, but many of those solutions have been half-assed versions of things D does to completion. CTFE in D works as you would expect, constexpr is a weird hack. Concepts in C++ are ridiculously overcomplicated and are done with a much simpler solution in D. Ranges are also much better thought out in D. C++ will also never replicate D's ease of use when it comes to metaprogramming - static foreach and if for example have no alternative in C++ (if constexpr is incredibly stupid)
- einpoklum 6y agoSo, you're saying: CTFEs, concepts and ranges done right. Hmm. Sounds good, actually...
- mhh__ 6y agohttps://run.dlang.io/is/dkFWTu https://run.dlang.io/is/dkFWTu Sink your teeth into that. Code generation at compile time, functional programming etc. The compiler can actually check that this is pure for you but in this case it isn't performed so it can read from stdin
- 1980phipsi 6y agoD doesn't have concepts. It just takes a different approach.
- lionkor 6y ago> if constexpr is incredibly stupid Would you care to elaborate what's wrong with it? When I used it I always felt it was quite straightforward.
- mhh__ 6y agoD CTFE restricts what you can't do. If I write my own vector type, even with my own malloc (it would have to get it's memory from the GC when running under CTFE for obvious reasons, but still), I can do useful work on it at compile time and then save that result in the data segment of my executable. Constexpr tells you what you can do. It adds huge amounts of bulk to the standard, there is syntax soup everywhere now etc.
- acehreli 6y agoYes, C++ has been catching up since C++11. One thing C++ will never have is D's `static if`, which allows injecting declarations into scopes. Bjarne Stroustrup and others closed that door: https://isocpp.org/files/papers/n3613.pdf https://isocpp.org/files/papers/n3613.pdf
- jcelerier 6y ago> One thing C++ will never have is D's `static if`, which allows injecting declarations into scope don't be so sure https://github.com/lock3/meta/wiki/Metaprogramming-Introductory-Tutorial https://github.com/lock3/meta/wiki/Metaprogramming-Introduct... a lot of it is already implemented: https://cppx.godbolt.org/z/4arx6T https://cppx.godbolt.org/z/4arx6T
- mhh__ 6y agoSeems horrifically complicated?
- jcelerier 6y agoit allows to generate code at basically every scope and to create your own "base language elements" like "struct", "class". AFAIK D does not allow for this, does it ?
- acehreli 6y agoD's templates has always been very strong and useful compared to C++'s. The following example is similar to C macros because it generates code as string and mixes it in as code but you can combine templates as well. This example generates a struct definition. (Edit: formatting) import std; // Entire package for brevity auto memberDef(string type, string name) { return format!" %s %s;"(type, name); } auto memberDefs(string[] members...) { return (members .chunks(2) .map!(pair => memberDef(pair[0], pair[1]))); } auto structDef(string name, string[] members...) { return format!q{ struct %s { %-(%s%) } }(name, memberDefs(members)); } unittest { mixin (structDef("Foo", "int", "i", "double", "d")); auto f = Foo(42, 1.5); assert((f.i == 42) && (f.d == 1.5)); } void main() { }
- wott 6y ago> I always had the sense - without seriously looking into it though - that D was about avoiding some of the mistakes/mis-features of C++, [...] and then it plays somewhat clunky catch-up. My opinion is that D lost its goal on the way. It was indeed supposed to be a cleaner C++ without all its confusing history of layers of features over layer of features. And it was so, for sometime. But then they started adding this, and this, and that, everything and all sorts of kitchen sinks depending on the fad of the year; meta-programming, taking from C++, or lately rustifying itself. The current state looks to me is as indigestible as modern C++ (and the process to get there has largely been the same, the process the original goal of D meant to rid and avoid). A pile of templates and annotations. D's evolution has been a great disappointment to me. I can see Nim going that way too.
- einpoklum 6y agoBut, you know, C++ can't be seen as a proper, complete language as it stood in 1998. A lot of it was partial scaffolding for future development of the language. In order to clean it, you either had to fill in the missing 25-years-or-so of C++ features (in some form or another), or settle on a much more limited language.
- dunefox 6y agoIt certainly looks very complex and feature heavy.
- deleted 6y ago[deleted]
- p0nce 6y agoC++ doesn't implement the D features right. For example C++20 has constexpr, consteval, constinit, for a less powerful equivalent of D's CTFE. D use no syntax for this. Things are evaluated in CTFE when they can. The rules are simple, and you can ignore them for the first few years. It's because CTFE is considered a normal thing in D.
- WalterBright 6y agoWith D it is unnecessary to build projects out of multiple languages, as D supports conventional C type programming, template metaprogramming, OOP, and functional style. (It even has an inline assembler for metal style!) Each of those paradigms has its place, and I enjoy being able to mix and match them as appropriate in the same program.
- crazypython 6y agoYou can even use opDispatch to generate methods or values of a class at compile time based on the name, Python __getitem__/JavaScript Proxy/Ruby style.
- dunefox 6y agoThat kind of sounds like a worse Common Lisp.
- Foomf 6y agoIts definitely of the kitchen sink variety. I don't think that's a bad thing though. D is a toolbox with a ton of tools in it. You might not need them all, but its nice that they're there when you do need them. You're not forced to use the features you don't need.
- lionkor 6y agoThat's also what C++ is, but surprisingly people like to hate it for that, too :/