8 ms·
Why I Like D
- dbi 5y agoInteresting points, but the up sides of dlang are over shadowed by the fact that rust won the hearts of many low level developers and has gotten traction. I know of a few companies that are having difficult finding skilled developers because of this.
- WalterBright 5y agoI suppose it depends on whether you want to do something you enjoy, or follow the crowd.
- bachmeier 5y ago> the up sides of dlang are over shadowed by the fact that rust won the hearts of many low level developers and has gotten traction Then wait until you see how Rust usage compares with C and C++ usage. Sorry, but I fail to see the point of your comment.
- type_enthusiast 5y agoA colleague (who is probably one of the smartest people I've met) made VectorFlow targeting D: https://github.com/Netflix/vectorflow https://github.com/Netflix/vectorflow I've never had a chance to look at it much, but I think the magic is in the metaprogramming capabilities. It's more principled than C++ templates, more ergonomic than Scala macros, and more practical than Template Haskell. Somehow. (At least this was my impression from discussing it)
- riwsky 5y agoThe library looks impressive, but I dunno about that sales pitch: isn't "more principled than C++ templates"… a pretty low bar? And isn't "more practical than Template Haskell"… also a pretty low bar? I would have asked the same rhetorical question of Scala macros a couple years back, but the Scala 3 macro redesign is indeed pretty nice.
- WalterBright 5y agoWhile the design D picked for templates looks (and is) straightforward, it wasn't obvious. It's only obvious in retrospect (which is something a good design aspires to, like putting an eraser on the other end of the pencil).
- riwsky 5y agoI agree. That one can e.g. lift every binary operator at once with just a few lines of code makes even python overloading feel heavy—but readers can still understand it easily. My point isn't that "D doesn't meet that bar", but that the GP picked strange points of comparison: the steelman argument for C++ templates would focus on power (e.g. Eigen) instead of principles, and those for Template Haskell on safety instead of practicality. And of course, no macro comparison would be complete without gesturing vaguely in the direction of Lisp while muttering something about parentheses. It's like the "Always Be Closing" speech in Glengarry Glen Ross: Dlang macros as John Travolta truly do kick ass in that scene—but why not have Al Pacino there to represent as top dog of the local branch?
- exdsq 5y agoThat's what she said! On a more serious note it's cool to see the languages creator quite frequently on HN - it is the reason I took a look at it a while ago :)
- WalterBright 5y agoThe D test suite takes too long to run, so I wind up here.
- exdsq 5y agoTest suites are my bread and butter! Happy to help contribute if you can point me in the right direction - it’s be a nice way to play with D a little more.
- mhh__ 5y agohttps://github.com/dlang/dmd/tree/master/test https://github.com/dlang/dmd/tree/master/test I work on D too, feel free to email.
- riwsky 5y ago> For example you cannot have multiple inheritance of classes (only of interfaces) so you cannot fall into the diamond problem like in C++ or Java. This is a weird thing to call out java for: you cannot inherit from multiple classes there. You can only get a diamond if you inherit two interfaces with default implementations of a method on a shared parent interface. Over a decade of writing java, I hit this zero times. In any case, Java treats it as a compile error and forces explicit resolution instead of silently doing something confusing.
- jhhh 5y agoI started learning D in 2012 and will echo that Andrei's book is great, and imo one of the most entertaining and informational technical books I've read. The D forum was a great example of dogfooding and the people seemed nice when I would post things. But, I think one of the things that people seemed very happy about feature-wise that started to turn me off the language was UFCS. I don't deny that it makes the written code look more elegant but I think to me it existed as a net negative for other people who are unfamiliar with the code they are reading. There was an example someone gave years ago on reddit that was supposed to convey how clean the code to solve the problem was but it included an UFCS expression of the form 'a.b!c.d' which was sans-UFCS 'd(b!c(a))'. Trying to determine which reordering the compile would going to eventually choose seemed like more work than should be necessary for simple expression like that. Having said all that it still might be a good choice for certain development environments and I should see whether there's a second edition of TDPL.
- WalterBright 5y agoUFCS is one of the most popular features. It's utility is in extending the functionality of a struct without adding member functions that would get private access, but don't need private access. It helps keep structs small and simple, rather than becoming kitchen sinks.
- jhhh 5y agoI don't disagree that it can be useful (eg. from one of the other projects mentioned in the thread: https://github.com/Netflix/vectorflow/blob/master/src/vectorflow/layers.d#L175 https://github.com/Netflix/vectorflow/blob/master/src/vector...), and I definitely saw plenty of people that liked it. I think it existed in the same realm as a feature like lisp macros which are incredibly useful but when overused can turn the code into an inscrutable mess. The question for me was always how much the community would use or overuse them. When talking with other people it seemed like their own use of UFCS was obvious, but then again they wrote the code so of course they were going to understand it. Without knowing any of the associated types and members how many interpretations could the prior expression 'a.b!c.d' have with UFCS and parens-less calling conventions (and any other feature that might contribute to different semantics)? b!(c.d)(a) b!(d(c))(a) d(b!c(a)) d(a.b!c) Might be more? Don't get me wrong I see the benefit. The vectorflow example I think is a good use case thought because it allows a more natural conceptualization of object -> member access -> conversion rather than having to call to!ulong(W.length) which forces the reader to start with the (pending) conversion. You get this same dataflow/conceptualization benefit in threading macros in clojure (->, ->>, etc). Anyway, thank you for all the work you've done.
- scavenger5 5y ago
- dinkleberg 5y agoGotta head over to Reddit for those posts.
- WalterBright 5y agoBetterC got a lot of resistance at first, along the lines of who needs it. (BetterC is a subset of D that only relies on the C standard library.) But over time it has accumulated a lot of users, as being C without the troubles. We've gone a step further with ImportC, and now C code can be imported directly into the D compiler, which makes it easy to interface D code to your existing C base.
- bachmeier 5y agoYou seem to have some familiarity with the language. Nonetheless, you're understating a bit the degree of integration with C. You can also: create a shared library in D and call it trivially from C or any language with a FFI, call C shared libraries with little effort from D, compile a C file and add the .o file to your D program compilation command directly, use dstep to write C bindings for you, and directly #include a C header file with dpp. C is more or less a subset of D at this point. C programmers can stick with what they know but use D for incremental elimination of pain points. Edit: I added that first sentence because it's awkward to tell the creator of the language that his answer was incomplete.
- zem 5y ago> You can also: create a shared library in D and call it trivially from C this is definitely a killer feature; i can think of very few languages that can do this. i think rust and zig are the only other two that have gotten any sort of popularity, though i would love to hear of any language i've missed.
- mlyle 5y ago> You seem to have some familiarity with the language. Just to note: Walter Bright, whom you replied to, is the creator of D.
- mrfox321 5y agoThe person you are replying to created D.
- baseballdork 5y ago
- perrohunter 5y ago
- ouch_ 5y ago
- hypertele-Xii 5y agoD makes a compelling promise, but it's still ongoing metamorphosis. Changes too rapidly for libraries to take root. Every time I look at it there's a "new, better way" of doing everything so all the tools and libraries are out of date, at all times. And the whole thing doesn't sound so clean and elegant anymore.
- destructionator 5y ago> Changes too rapidly for libraries to take root. I have code that has worked unmodified for many years. The language doesn't change that often.
- WalterBright 5y agoAll languages (even C to some extent) that are in wide use evolve towards new and better ways, and obsolete old ways. I don't even recognize C++ anymore, and I wrote a frakkin compiler for it.
- raphlinus 5y agoSpeaking of people who have written C++ compilers, what do you think of Circle? Have you given any thought to targeting GPU shaders from D? I think "C-like low level control but with strong compile time metaprogramming" might be something of a sweet spot, though there is a lot of complexity to the space (mostly the oddball storage spaces).
- WalterBright 5y agoI don't know anything about Circle. Sorry.
- WebFreak001 5y agothere is DCompute for writing D programs on the GPU: https://github.com/libmir/dcompute https://github.com/libmir/dcompute it's pretty awesome
- 5y ago
- VHRanger 5y agoYes, I just wished more people liked D so it got momentum.
- WalterBright 5y agoD doesn't have evangelists or a marketing team. It's just people who find it really useful.
- VHRanger 5y ago
- pyjarrett 5y ago> compile times, ugly syntax, ergonomics This is why I write in Ada--it's C++98 with cleaner syntax and a bunch of nice/new features (array bounds, pre/post conditions, etc). It's package-based, so types do not "contain functions", so free functions, member function, who cares, it's all written and callable the same ways. There's even a real module system built in for decades with packages. You have to get over `begin` and `end` though.
- WalterBright 5y ago> You have to get over `begin` and `end` though. Ada would be smart to get rid of that.
- pyjarrett 5y agoIt's probably not removable after almost 40 years. It has expression functions which you can wrap a return result in () and avoid it. The important part is that it's surprisingly consistent in that 3 of the 4 structural elements are nearly all self-similar in their declare/begin/end format (protected type being the 4th and the difference).
- 5y ago
- lkajlskjdf 5y ago
- leetrout 5y ago> Go did not have generic types at the time so I excluded it immediately I wonder how many people are missing out on Go for a feature they wouldnt miss 80-90% of the time?
- christophilus 5y agoI’ll be honest. It kept me away from Go for far too long. Now, I really appreciate Go, and hope the new generics implementation doesn’t ruin the culture. I do wish Go had sum types, and that it didn’t have null. Those are my main gripes.
- WalterBright 5y agoGeneric code is written with D a lot more than I'd originally anticipated.
- leetrout 5y agoOh I dont deny that at all. D is on my list of languages to try precisely because it is more powerful / flexible than Go (and thank you for making it). Just surprises me how quickly people write it off. Horses for courses!
- schveiguy 5y agoThe only way you can be saying this is if you haven't experienced metaprogramming in D. C++ does not compare at all. Generics do not compare at all. You can take D metaprogramming from my cold dead hands.
- leetrout 5y agoIf you were in the authors shoes and you disliked C++ templates would you also have written off Go without trying it, though? No argument on going from D to something else but to not know either and not even try Go is what surprises me.
- he_the_great 5y ago
- christophilus 5y agoWhat’s the web story like in D these days? The thing I really like about Go is how easy it is to spin up a decently high performance web service.
- WebFreak001 5y agoif you want to use vibe.d as a fairly complete solution to most tasks. You will not have the fastest web service, but you will be really productive. I think with vibe.d you can easily beat node.js in comfort for writing web services, especially because most errors can be found and fixed at compile time already. vibe.d is pretty similar to express.js There are also other non-vibe web service libraries like arsd cgi (can't tell you much about that one) or hunt-framework (which is probably the highest performance library for the D ecosystem if you can believe the benchmarks, but doesn't have much documentation)
- marcodiego 5y agoAccording to wikipedia: "...was originally released under a custom license, qualifying as source available but not conforming to the open source definition. In 2014..." Which has been a different path other more popular languages took to increase popularity. The standard D2, which is now D, introduced breaking changes and stabilization only came around 2010. Parallel to this, other programming languages became more popular and evolved, particularly C++. This certainly affected D's "novelty value". I wonder how much these facts negatively influenced D adoption.
- destructionator 5y agoThey're wrong: the D parts of the compiler were released under the GPL in 2002. What is now called gdc got started shortly thereafter, bolting it on to the gcc backend, creating a fully-GPL D compiler. This is easy to verify by looking at the archived releases.
- WalterBright 5y agoI originally underestimated the value of Open Source, which was definitely a mistake. Now I do everything in Open Source. The latest was releasing my disassembler, originally written in 1982, under a Boost License. (It may be old, but it disassembles the latest Intel instruction sets.) It's now part of the dmd D compiler. Just throw the -vasm switch, and it'll display the generated code on the console. I see many uses for a freely available disassembler. For example, you can add it to your favorite text editor! Admit it, you've always wanted to disassemble your text. https://github.com/dlang/dmd/blob/master/src/dmd/backend/disasm86.d https://github.com/dlang/dmd/blob/master/src/dmd/backend/dis...
- marcodiego 5y ago> I originally underestimated the value of Open Source, which was definitely a mistake. Now I do everything in Open Source. Humble comment. It is very good to hear this. Will guard this for future examples.
- mhh__ 5y ago> latest Intel instruction sets. I'm impressed with -vasm, but fo the record this isn't strictly true. It supports most everything you'll see day to day but AVX2 (for example) is emphatically not the latest and greatest. AVX512 adds quite a lot of stuff for example. Entirely new set of mask registers for example. Even with the VEX prefix Intel did new instructions just recently (VNNI). As long as it doesn't blow up I think it's fine to not support these, just want to make it clear that if you use (say) TSX via inserting raw bytes in an AsmStatement (which I have done) then the disassembler will not pick it up.
- gitgud 5y agoInteresting language // Increment all elements by one (array-wise expression) half[] += 1; Is this really that useful? Seems like a weirdly specific code smell...
- rezonant 5y agoWish I had this in JS tbh
- trynumber9 5y agoIt can be a bit more general https://dlang.org/spec/arrays.html#array-operations https://dlang.org/spec/arrays.html#array-operations Looking at the notes, it may have separate syntax to make compiler vectorization and parallelization easier. Plus it's pretty terse.
- sodapopcan 5y agoI don't know D and just learning this syntax myself, and I'm genuinely interested in where you feel the smell is because I really like this syntax! For example: I know Ruby, so here is what I'm used to: half.map { |i| i + 1 } I also know Elixir: Enum.map(half, fn i -> i + 1 end) ...and JS, I guess because we have to: half.map(i => i + 1) // It looks just like the Ruby one ...vs whatever the Python version is... I don't know Python very well, but I imagine it involves list comprehensions... Compare all those to the aforementioned D version : half[] += 1; I'm really feeling the D version! EDITED to fix little mistakes.
- gitgud 5y agoSorry I should have been more clear. Incrementing every element in an array is much less useful than ".map()" which can execute a function on every element. It just seems like a weirdly specific syntactic sugar... which is a "language smell"... to me
- schveiguy 5y agoYou can use arrays as if they were individual operands, and it will expand out the loop and apply the expression to all the values (and can use optimization/vector tricks if posssible). e.g.: arr1[] += arr2[] / 10.0 + 5; TBH, I don't use this feature much, because I work with ranges more than arrays, which do not have this ability. This feature predates ranges (and the std.algorithm.map function, which can do what you say as well).
- zem 5y agoi really want to use D for something, but it's just in that awkward spot where for any given project i can use ocaml instead. ocaml is in roughly the same part of the speed/expressiveness/pleasantness box as D is, plus i already know it. i had two abortive attempts to use the language for specific projects - one was to wrap a C++ library and use it from D, but it turned out the swig bindings didn't work. the second was to find an active gtkd-based app and contribute to it, to get a feel for desktop gui development (which seems on the surface like a very compelling use case for the language), but after asking on reddit no one could suggest anything other than tilix, on which development has stalled :( i would still love to do this, if anyone has something to suggest. if anyone is involved in a fun desktop-based D project (CLI, TUI or GUI are all fine) please recommend it!
- zombinedev 5y agoRegarding GtkD, you may find this blog interesting: https://gtkdcoding.com/ https://gtkdcoding.com/
- zem 5y agoi have read that with great interest :) it's part of why i was so surprised that no one seemed to be actually writing gtkd apps.
- pabs3 5y agoAre there linters and other static analysis tools for D?
- WalterBright 5y agothere's dscanner https://github.com/dlang-community/D-Scanner https://github.com/dlang-community/D-Scanner
- pabs3 5y agoThere is also dfmt, which potentially can be used as a style linter if you wrap it in diffs. https://github.com/dlang-community/dfmt https://github.com/dlang-community/dfmt