News for hackers. Stuff that matters.
Re:Idioms for the D Programming Language by mhh__ on Thursday February 11, 2021 @02:15PM (#26105830)
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).

Re:Idioms for the D Programming Language by gus_massa on Thursday February 11, 2021 @02:59PM (#26106338)
Remember to add the https to make it clicky https://tour.dlang.org/
Re:Idioms for the D Programming Language by hu3 on Thursday February 11, 2021 @05:56PM (#26108576)
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!

Re:Idioms for the D Programming Language by mhh__ on Thursday February 11, 2021 @06:24PM (#26108899)
> 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++

Re:Idioms for the D Programming Language by p0nce on Tuesday February 16, 2021 @12:00PM (#26155996)
> 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.

Re:Idioms for the D Programming Language by destructionator on Thursday February 11, 2021 @06:16PM (#26108826)
> 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 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&...

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.

Re:Idioms for the D Programming Language by crazypython on Thursday February 11, 2021 @08:18PM (#26109761)
D 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.
Re:Idioms for the D Programming Language by p0nce on Friday February 12, 2021 @06:21AM (#26112471)
It depends on the style of code. In both C++ and D world, code with many template instantiation builds slower.
Re:Idioms for the D Programming Language by mhh__ on Thursday February 11, 2021 @06:26PM (#26108911)
HN code-ifies text if it's indented after a newline