[HN Gopher] Idioms for the D Programming Language
       ___________________________________________________________________
        
       Idioms for the D Programming Language
        
       Author : crazypython
       Score  : 79 points
       Date   : 2021-02-11 18:51 UTC (4 hours ago)
        
 (HTM) web link (p0nce.github.io)
 (TXT) w3m dump (p0nce.github.io)
        
       | nynx wrote:
       | 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.
        
         | WalterBright wrote:
         | With 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.
        
         | mhh__ wrote:
         | Consistently 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 wrote:
           | Can 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.
        
             | acehreli wrote:
             | Yes, 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
        
               | jcelerier wrote:
               | > 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-
               | Introduct...
               | 
               | a lot of it is already implemented:
               | https://cppx.godbolt.org/z/4arx6T
        
               | mhh__ wrote:
               | Seems horrifically complicated?
        
             | mhh__ wrote:
             | C++ 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 wrote:
               | So, you're saying: CTFEs, concepts and ranges done right.
               | Hmm. Sounds good, actually...
        
         | Foomf wrote:
         | Its 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.
        
       | yrgulation wrote:
       | This can get downvoted to oblivion, but i fell for DLang first
       | time i wrote a hobby raspberry pi gpio library.
       | 
       | It just worked. It compiled without hassle. The language was easy
       | to understand - i first read about a few days prior to writing my
       | lib.
       | 
       | I absolutely think this language should get more attention, and
       | probably it should explore wasm a bit more. I know webdevs love
       | easy to read languages and DLang is an ideal candidate for
       | replacing javascript in the browser via wasm.
       | 
       | All it needs is a nice package manager and a set of basic web
       | libs to use in the browser - not the DOM kind of libs, but for
       | large'ish tables and data manipulation, a bit of audio and video
       | editing and perhaps webgl integration to showcase what it can do.
       | 
       | /end of babbling
        
         | ironmagma wrote:
         | I've heard before that there is a schism in the D community
         | between two different options, but never can remember what it
         | is. Something that fragments the ecosystem?
        
           | mhh__ wrote:
           | There was a schism the best part of 15 years ago now.
        
           | gmfawcett wrote:
           | You might mean the D1 vs. D2 schism. That was ages ago, it
           | hasn't been a live issue for a very long time.
        
           | acehreli wrote:
           | I've been in the D community since 2009. There is no schism.
        
           | [deleted]
        
           | wk_end wrote:
           | IIRC there were two different standard libs at one point. I
           | don't believe that's an issue anymore.
        
           | lhorie wrote:
           | There were two stdlibs in D1 (the official one called phobos,
           | and tango which had a more "java-like" feel). I haven't been
           | following D for years, but it looks like Tango sort of died
           | off when work on D2 started to get traction[0]
           | 
           | [0] http://www.dsource.org/projects/tango/forums/topic/920
        
           | scythe wrote:
           | D's biggest problem at this point is that everyone (including
           | me) vaguely remembers that period where it was in limbo
           | between different design strategies, and consequently frets:
           | "is it stable yet?".
           | 
           | Luckily, that seems to finally have reached a "yes!".
           | Development continues, but nobody's getting the rug pulled
           | out from under them anymore.
        
             | mhh__ wrote:
             | > finally
             | 
             | That really arrived with Andrei Alexandrescu's book which
             | was 10 years ago now.
        
               | ironmagma wrote:
               | I heard about this schism less than 5 years ago so
               | there's probably some pages/blogs/talks that need to be
               | updated.
        
               | mhh__ wrote:
               | It's mostly second hand commentary.
               | 
               | HN is an outlier in that people have even heard of D, for
               | some perspective.
        
         | Foomf wrote:
         | D does have a package manager named dub, it works well.
         | 
         | https://code.dlang.org/
        
           | moonchild wrote:
           | > it works well
           | 
           | it ... works
           | 
           | That's as much as I think can be said for it. Dub is garbage.
           | It's too complicated, too rigid, and it does too little. It's
           | also slow for larger projects because it doesn't do
           | incremental builds.
        
         | destructionator wrote:
         | I like to write really basic little games to kill time. Stuck
         | on a flight? Clone tetris or minesweeper or whatever. And of
         | course I use D.
         | 
         | Well, I wrote a version of my support library for those games
         | for webassembly too and you can play some of them online!
         | 
         | http://webassembly.arsdnet.net/
         | 
         | None of them are "finished" per se, I'd be on a strict time
         | limit and just left it where it landed when I ran out, some not
         | even really working, but there's some little playable chunks
         | there. Tends to be 60KB or so of webasm, really not too bad (no
         | need for the emscripten bloat etc since I did it all myself)
         | 
         | It amuses me to compile the same program for Windows, Linux,
         | and the browser without modification.
         | 
         | (that's all I personally use webassembly for though, since I'm
         | not a fan of SPAs...)
        
           | brobdingnagians wrote:
           | That's really cool, thank you for sharing! It is neat to see
           | a bit longer form D code in more than just sample tutorials.
        
         | Shadonototro wrote:
         | i love D, i only wish story where non-gc is needed would
         | improve (more allocator work, more gc free runtime etc)
         | 
         | after trying zig, i also wish C interop was as smooth, but zig
         | has advantage of shipping a clang compiler as library, D could
         | do the same since they got LDC (with LLVM)
         | 
         | i move between zig/rust and D; i'm happy to say that we can
         | live in a world where we can totally ignore c++
        
           | mhh__ wrote:
           | @nogc is growing, and memory safety will also be improving,
           | just that we've basically reached end of what we can do
           | before reaching the hard problems - we're definitely not
           | stopping we just need to get any changes to the language
           | right.
           | 
           | Also remember that the GC is entirely written in D, it is
           | possible.
        
           | gmueckl wrote:
           | There's also Calypso, an LDC fork that can process C++
           | headers directly. It should in theory also work with C.
        
             | Shadonototro wrote:
             | why a fork, and not a PR to LDC? fragmentation is a bad
             | thing in my opinion
        
               | mhh__ wrote:
               | Because merging an increasingly large subset of a c++
               | compiler into a compiler for a different language is a
               | recipe for disaster if you're unlucky.
        
       | marai2 wrote:
       | This is great! All languages should provide an idioms page on
       | their website.
        
       | mhh__ wrote:
       | For an introduction to the language try tour.dlang.org
       | 
       | Also, feel free to ask questions about the language (I work for
       | the D foundation).
        
         | hu3 wrote:
         | Would you recommend D for web APIs?
         | 
         | How fast is D compiler on a 100k line project?
         | 
         | Does it support incremental compilation?
         | 
         | How's the package management story and where is D heading in
         | this camp?
         | 
         | Thanks!
        
         | gus_massa wrote:
         | Remember to add the https to make it clicky
         | https://tour.dlang.org/
        
       | bachmeier wrote:
       | This is one I really like
       | 
       | https://p0nce.github.io/d-idioms/#Parallel-foreach
       | 
       | I use D as a complement to R. If I'm doing a simulation, it's
       | really simple to shift to doing them in parallel. (I know other
       | languages also provide such support, but I'm a fan of the overall
       | D language as a replacement for C in the statistical computing
       | realm.)
        
         | mhh__ wrote:
         | D is really really nice for writing code then upping the
         | performance as you go.
         | 
         | We do need better scientific programming libraries, however.
        
           | bachmeier wrote:
           | I agree. I have everything I need after 7-8 years, but that's
           | not true for everyone.
        
       ___________________________________________________________________
       (page generated 2021-02-11 23:00 UTC)