www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Idioms for the D programming language

reply Walter Bright <newshound2 digitalmars.com> writes:
https://news.ycombinator.com/news

The page being discussed:

https://p0nce.github.io/d-idioms/

and on reddit:

https://www.reddit.com/r/programming/comments/lhssjp/idioms_for_the_d_programming_language/
Feb 11
next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Feb 11, 2021 at 12:12:36PM -0800, Walter Bright via
Digitalmars-d-announce wrote:
[...]
 https://p0nce.github.io/d-idioms/
Not bad, but it seems to be missing some of the newer idioms. Like the templated static this trick for transparently encoding compile-time information at runtime. For example: import std.regex; void main(string[] args) { foreach (arg; args) { if (arg.match(Re!`some.*regex(pattern)+`)) { ... // do something } } } template Re(string reStr) { Regex!char re; static struct Impl { static this() { re = regex(reStr); } } string Re() { return re; } } The Re template captures the regex string at compile-time and injects it into Impl's static this(), which compiles the regex at program startup at runtime, then the eponymous function Re() simply returns the precompiled value. The result: - Regexes are automatically picked up at compile-time; - But expensive compile-time generation of the regex (which consumes lots of compiler memory and slows down compilation) is skipped; - Compilation of the regex happens only once upon program startup and cached, and thereafter is a simple global variable lookup. - Multiple occurrences of the Re template with the same regex is automatically merged (because it's the same instantiation of the template). D features used: - compile-time string parameters - static this() - eponymous templates - reuse of template instantiations that have the same arguments [...]
 https://www.reddit.com/r/programming/comments/lhssjp/idioms_for_the_d_programming_language/
There doesn't appear to be any discussion happening here. T -- If it breaks, you get to keep both pieces. -- Software disclaimer notice
Feb 11
parent reply Guillaume Piolat <first.last gmail.com> writes:
On Friday, 12 February 2021 at 00:26:09 UTC, H. S. Teoh wrote:
 On Thu, Feb 11, 2021 at 12:12:36PM -0800, Walter Bright via 
 Digitalmars-d-announce wrote: [...]
 https://p0nce.github.io/d-idioms/
Not bad, but it seems to be missing some of the newer idioms.
It's because I lack the time to update it. It was always a page to let _me_ understand the language better, and then I got to a point where I wasn't following the D development enough.
Feb 12
next sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Friday, 12 February 2021 at 11:19:26 UTC, Guillaume Piolat 
wrote:
 On Friday, 12 February 2021 at 00:26:09 UTC, H. S. Teoh wrote:
 On Thu, Feb 11, 2021 at 12:12:36PM -0800, Walter Bright via 
 Digitalmars-d-announce wrote: [...]
 https://p0nce.github.io/d-idioms/
Not bad, but it seems to be missing some of the newer idioms.
It's because I lack the time to update it. It was always a page to let _me_ understand the language better, and then I got to a point where I wasn't following the D development enough.
For someone coming to D today, would you say most of the content there is still valid? Thanks
Feb 12
parent reply Guillaume Piolat <first.last gmail.com> writes:
On Friday, 12 February 2021 at 11:44:31 UTC, Imperatorn wrote:
 On Friday, 12 February 2021 at 11:19:26 UTC, Guillaume Piolat 
 wrote:
 On Friday, 12 February 2021 at 00:26:09 UTC, H. S. Teoh wrote:
 On Thu, Feb 11, 2021 at 12:12:36PM -0800, Walter Bright via 
 Digitalmars-d-announce wrote: [...]
 https://p0nce.github.io/d-idioms/
Not bad, but it seems to be missing some of the newer idioms.
It's because I lack the time to update it. It was always a page to let _me_ understand the language better, and then I got to a point where I wasn't following the D development enough.
For someone coming to D today, would you say most of the content there is still valid? Thanks
It's mostly valid, but it lacks about fifty new articles that would need to be added.
Feb 12
parent Guillaume Piolat <first.last gmail.com> writes:
On Friday, 12 February 2021 at 12:25:32 UTC, Guillaume Piolat 
wrote:
 It's mostly valid, but it lacks about fifty new articles that 
 would need to be added.
Also keep in mind it's not a structured learning resource, it was all about emphasizing this or that particular and rarely needed aspect of D and edge cases. Which I think a few of us have been fond of at one point.
Feb 12
prev sibling parent TheGag96 <thegag96 gmail.com> writes:
On Friday, 12 February 2021 at 11:19:26 UTC, Guillaume Piolat 
wrote:
 On Friday, 12 February 2021 at 00:26:09 UTC, H. S. Teoh wrote:
 On Thu, Feb 11, 2021 at 12:12:36PM -0800, Walter Bright via 
 Digitalmars-d-announce wrote: [...]
 https://p0nce.github.io/d-idioms/
Not bad, but it seems to be missing some of the newer idioms.
It's because I lack the time to update it. It was always a page to let _me_ understand the language better, and then I got to a point where I wasn't following the D development enough.
I'd love if you'd pick up again. Years ago, when it was a bit more active, I'd check it all the time. I've learned a lot from the page. Thanks for all your work on it!
Feb 12
prev sibling next sibling parent reply James Lu <jamtlu gmail.com> writes:
On Thursday, 11 February 2021 at 20:12:36 UTC, Walter Bright 
wrote:
https://news.ycombinator.com/news
I've gotten Dlang to the frontpage of HN 3 other times: Specification for the D Programming Language https://news.ycombinator.com/item?id=21993208 D 2.0.93.0 https://news.ycombinator.com/item?id=23859448 Ask HN: Why do you use Rust, when D is available? https://news.ycombinator.com/item?id=23494490 If you have any particularly interesting and specific pages on D, feel free to send them to me, so I can post them to HN at the optimal time. (Furthermore, if you authored it, you should a comment that explains why you made it and offering to answer questions– I have found this can turn a regular post into a frontpage post.)
Feb 11
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/11/2021 5:53 PM, James Lu wrote:
 On Thursday, 11 February 2021 at 20:12:36 UTC, Walter Bright wrote:
https://news.ycombinator.com/news
I've gotten Dlang to the frontpage of HN 3 other times: Specification for the D Programming Language https://news.ycombinator.com/item?id=21993208 D 2.0.93.0 https://news.ycombinator.com/item?id=23859448 Ask HN: Why do you use Rust, when D is available? https://news.ycombinator.com/item?id=23494490
Thank you!
 If you have any particularly interesting and specific pages on D, feel free to 
 send them to me, so I can post them to HN at the optimal time. (Furthermore,
if 
 you authored it, you should a comment that explains why you made it and
offering 
 to answer questions– I have found this can turn a regular post into a
frontpage 
 post.)
Yes, having the author do an AMA is very productive.
Feb 12
next sibling parent Guillaume Piolat <first.last gmail.com> writes:
On Friday, 12 February 2021 at 08:31:13 UTC, Walter Bright wrote:
 Yes, having the author do an AMA is very productive.
I'm literally busy writing D!
Feb 12
prev sibling parent reply James Lu <jamtlu gmail.com> writes:
On Friday, 12 February 2021 at 08:31:13 UTC, Walter Bright wrote:
 On 2/11/2021 5:53 PM, James Lu wrote:
 On Thursday, 11 February 2021 at 20:12:36 UTC, Walter Bright 
 wrote:
https://news.ycombinator.com/news
I've gotten Dlang to the frontpage of HN 3 other times: Specification for the D Programming Language https://news.ycombinator.com/item?id=21993208 D 2.0.93.0 https://news.ycombinator.com/item?id=23859448 Ask HN: Why do you use Rust, when D is available? https://news.ycombinator.com/item?id=23494490
Thank you!
Thanks for the kind words :)
 If you have any particularly interesting and specific pages on 
 D, feel free to send them to me, so I can post them to HN at 
 the optimal time. (Furthermore, if you authored it, you should 
 a comment that explains why you made it and offering to answer 
 questions– I have found this can turn a regular post into a 
 frontpage post.)
Yes, having the author do an AMA is very productive.
I once resubmitted with an AMA-style comment, which was the difference between getting 12 points and not getting on the frontpage, and getting on the frontpage with 158 points.
Feb 13
parent Walter Bright <newshound2 digitalmars.com> writes:
On 2/13/2021 7:57 AM, James Lu wrote:
 I once resubmitted with an AMA-style comment, which was the difference between 
 getting 12 points and not getting on the frontpage, and getting on the
frontpage 
 with 158 points.
Yup. Another critical thing is to make the first post. The first post has a strong tendency to set the tone for the entire topic. The first post should be a brief synopsis of what the article is about, said in a positive manner. Leaving this to chance has led too many times to having a topic essentially sabotaged by someone making a first post that is strongly negative. The topic never recovers. Always always when submitting a link, make the first post.
Feb 14
prev sibling parent James Lu <jamtlu gmail.com> writes:
On Friday, 12 February 2021 at 01:53:25 UTC, James Lu wrote:
 If you have any particularly interesting and specific pages on 
 D, feel free to send them to me, so I can post them to HN at 
 the optimal time. (Furthermore, if you authored it, you should 
 a comment that explains why you made it and offering to answer 
 questions– I have found this can turn a regular post into a 
 frontpage post.)
I wanted to add: What I do is I take a post that could be submitted to Hacker News, then I am an "optimizing compiler" for it. I post at 3pm on Monday through Thursday, add comments, tune the submission title, and various small HN-specific optimizations– my submissions have been on its frontpage 20 times, I know what I'm doing.
Feb 13
prev sibling next sibling parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 11 February 2021 at 20:12:36 UTC, Walter Bright 
wrote:
https://news.ycombinator.com/news

 The page being discussed:

 https://p0nce.github.io/d-idioms/

 and on reddit:

 https://www.reddit.com/r/programming/comments/lhssjp/idioms_for_the_d_programming_language/
👍
Feb 11
prev sibling parent reply James Lu <jamtlu gmail.com> writes:
On Thursday, 11 February 2021 at 20:12:36 UTC, Walter Bright 
wrote:
https://news.ycombinator.com/news

 The page being discussed:

 https://p0nce.github.io/d-idioms/

 and on reddit:

 https://www.reddit.com/r/programming/comments/lhssjp/idioms_for_the_d_programming_language/
A question for you: What is the most interesting (shows the language) and beginner-friendly source code file of DMD? I want to link to the compiler source to do that. It needs to be readable by a beginner, yet also provide interesting and substantial information on how D or compilers work. * Demonstrate DMD is open-source * Get DLang more attention * Demonstrate how good DMDFE is
Feb 13
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Saturday, 13 February 2021 at 16:06:31 UTC, James Lu wrote:
 On Thursday, 11 February 2021 at 20:12:36 UTC, Walter Bright 
 wrote:
https://news.ycombinator.com/news

 The page being discussed:

 https://p0nce.github.io/d-idioms/

 and on reddit:

 https://www.reddit.com/r/programming/comments/lhssjp/idioms_for_the_d_programming_language/
A question for you: What is the most interesting (shows the language) and beginner-friendly source code file of DMD? I want to link to the compiler source to do that. It needs to be readable by a beginner, yet also provide interesting and substantial information on how D or compilers work. * Demonstrate DMD is open-source * Get DLang more attention * Demonstrate how good DMDFE is
"readable by a beginner" && "interesting and substantial information" might be hard to find. Did you mean front- or backend? If you want to show compiler u might look at https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d for example. But I think it might be better to begin with some kind of overview so you understand what you're looking at 🐢
Feb 13
parent reply James Lu <jamtlu gmail.com> writes:
On Saturday, 13 February 2021 at 16:39:12 UTC, Imperatorn wrote:
 On Saturday, 13 February 2021 at 16:06:31 UTC, James Lu wrote:
  [...]
"readable by a beginner" && "interesting and substantial information" might be hard to find. Did you mean front- or backend? If you want to show compiler u might look at https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d for example.
Frontend, to show the language.
Feb 14
parent Bruce Carneal <bcarneal gmail.com> writes:
On Sunday, 14 February 2021 at 17:56:00 UTC, James Lu wrote:
 On Saturday, 13 February 2021 at 16:39:12 UTC, Imperatorn wrote:
 On Saturday, 13 February 2021 at 16:06:31 UTC, James Lu wrote:
  [...]
"readable by a beginner" && "interesting and substantial information" might be hard to find. Did you mean front- or backend? If you want to show compiler u might look at https://github.com/dlang/dmd/blob/master/src/dmd/compiler.d for example.
Frontend, to show the language.
If you are looking for high level understanding of a D front end https://github.com/SDC-Developers/SDC might help, either standalone or as a supplement to your DMD readings. On the minus side, SDC is a hibernating prototype. On the plus side, SDC employs a strong architecture that factors out many of the dependency issues facing DMD. What remains is very readable.
Feb 14