13 ms·
Idioms for the D Programming Language
- mhh__ 6y agoFor an introduction to the language try tour.dlang.org Also, feel free to ask questions about the language (I work for the D foundation).
- gus_massa 6y agoRemember to add the https to make it clicky https://tour.dlang.org/ https://tour.dlang.org/
- hu3 6y agoWould 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!
- destructionator 6y ago> How fast is D compiler on a 100k line project? I have a 140k line multi-purpose library that compiles in 2 1/2 seconds on my i5 computer w/ ssd. But this varies very heavily depending on what language features you use (compile time execution of functions can make a 3 line program compile in many minutes, or simple C-style code can compile 100k lines in a fraction of a second). So don't generalize too fast! Re web APIs, I've been doing serving and consuming with D for a long time now, I like it a lot. Using some of the compile time reflection stuff is really cool. Like this little demo site: http://arsdnet.net/cgi-bin/survey/record-survey http://arsdnet.net/cgi-bin/survey/record-survey has this source code: ``` import arsd.cgi; import arsd.dom; import arsd.jsvar; struct Survey { string thisIsFakeDontSpendRealTimeOnIt; string whyD; int yearsUsingD; string[] thingsYouWantMost; } struct AboutYou { string yourName; } class Site : WebObject { @AutomaticForm auto recordSurvey(/* @Flatten */ @DisplayName("") Survey s, @DisplayName("") AboutYou y) { struct Result { string message; Survey surveyAnswers; AboutYou aboutYou; } return Result("Thank you!", s, y); } // you can also specify things on functions @(Cgi.RequestMethod.GET) @DefaultFormat("json") int giveMeJson(int a) { return a; } // or have plain boring ones string hello() { return "hello, world!"; } @UrlName("different-url") string[] anyName(string other) { return ["Hello", "Friends", other]; } } void handler(Cgi cgi) { cgi.dispatcher!( "/".serveApi!Site ); } mixin GenericMain!handler; ``` The form is generated from function params, the html from return values, etc. OR you can do json too of course http://arsdnet.net/cgi-bin/survey/different-url?format=json&other=hello http://arsdnet.net/cgi-bin/survey/different-url?format=json&... so it is nice. On the client side, I also generate some code so the usage looks like ``` var result = gitlab.rest.users[myuid].pull_requests.GET; ``` and similar so it generates all those things as it needs it (the url made from the dot members, the return value just a dynamic dype). Not like perfect but plenty convenient.
- mhh__ 6y agoHN code-ifies text if it's indented after a newline
- crazypython 6y agoD can compile your entire 140KSLOC project faster than Rust, TypeScript, or C++ can compile a single file. (The lexer has tricks like skipping multiple spaces at once in order to achieve this.) So, there isn't really a need for incremental compilation yet.
- p0nce 6y agoIt depends on the style of code. In both C++ and D world, code with many template instantiation builds slower.
- mhh__ 6y ago> Would you recommend D for web APIs? vibe.d is quite good > How fast is D compiler on a 100k line project? The D reference compiler takes a few seconds on my machine and is about 450k lines. > Does it support incremental compilation? Not very well if at all. > How's the package management story and where is D heading in this camp? Uninspiring but more than enough to be productive - i.e. infinitely better than C++
- p0nce 6y ago> How fast is D compiler on a 100k line project? On Apple M1, a full rebuild of one of my product (approx. 80kloc) is 6 seconds. 1 seconds incremental.
- nynx 6y agoI'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...
- yrgulation 6y agoThis 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 6y agoI'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__ 6y agoThere was a schism the best part of 15 years ago now.
- gmfawcett 6y agoYou might mean the D1 vs. D2 schism. That was ages ago, it hasn't been a live issue for a very long time.
- deleted 6y ago[deleted]
- wk_end 6y agoIIRC there were two different standard libs at one point. I don't believe that's an issue anymore.
- scythe 6y agoD'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.
- bachmeier 6y agoThis is one I really like https://p0nce.github.io/d-idioms/#Parallel-foreach 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__ 6y agoD is really really nice for writing code then upping the performance as you go. We do need better scientific programming libraries, however.
- bachmeier 6y agoI agree. I have everything I need after 7-8 years, but that's not true for everyone.
- O_H_E 6y ago> ** is really really nice for writing code then upping the performance as you go. We do need better scientific programming libraries, however. This is pretty much a rephrasing to few of the main goals of Julia. You start prototyping using the dynamic python/lispy, and add some typing or some optimization to got C/Fortran performance. It is really finding it's space in scientific computing. Check out Flux.jl, DifferentialEquations.jl, and SciML.jl for a preview of the cool projects Dynamic Dispatch is enabling. Bonus points for excellent Macros: MLstyle.jl
- dunefox 6y agoYep, I often hear people say their favourite language would be great for scientific programming, it only needs scientific libraries and people to use them. Julia already has those things, they're not easy to get.
- mhh__ 6y agoWe already have a library called Mir which has laid down a lot of the hard stuff to begin with. Its very very fast even relative to the small number of people working on it.
- marai2 6y agoThis is great! All languages should provide an idioms page on their website.
- msoucy 6y agoGood to see D getting some acknowledgement now and again! I haven't touched it in a while, but have a soft place in my heart for it. Features I absolutely love that I wish I could use at work (stuck in C++98 land, slowly upgrading) include ranges, template metaprogramming, and inout. So much of the surrounding toolset could be removed if only I had those capabilities.