Re: From the D Blog: Driving with D
On Tuesday, 1 June 2021 at 11:57:34 UTC, Mike Parker wrote: Dylan Graham writes about his experience using D in a I have translate this article into `chinese`: [用d开车](https://fqbqrr.blog.csdn.net/article/details/118571177)
Re: Beerconf July 2021
On Sunday, 11 July 2021 at 14:01:43 UTC, Steven Schveighoffer wrote: # BEERCONF! IMO, we should `tag` the `posts/reply` in `D` community. We can first raise about `20 common` tags. Then `new posts/good replies/important people's answer` should be tagged. `Old posts` should also be tagged according to their importance. Meanwhile, someone should be responsible for `classifying the posts` in the Forum according to their tags,This can be convenient for `newbies` to `find their need` and `learn from it`. We didn't `make good use of` the forum at all, `the previous excellent discussions` is wasted.
Re: record: C# like records for D
On 7/16/21 4:11 PM, Dylan Graham wrote: On Friday, 16 July 2021 at 19:37:53 UTC, Steven Schveighoffer wrote: I would possibly suggest that instead of a record template that accepts directives using inline lambdas, etc, just accept a model type and use udas to adjust the record type. That is a good idea, and to be honest I haven't looked at it that way. So the record is a separate type from its model? Ie: `class MyRecord {}` based off `struct RecordModel {}`? Or did I misunderstand? With regards to things like properties and methods, do you have RecModel inlined in the class and then forward the calls to it? Ie: ```D struct RecModel { @get int x; auto doubleOfX() { return x; } } class Rec { private RecModel instance; @property auto x() { return instance.x; } auto doubleOfX() { return instance.doubleOfX; } } ``` Yeah, something like that. Though there are multiple ways to go about it. One is to write a string that represents what you want it to do, and then mixin that thing. The way I do it is using `opDispatch` which is super-powerful for forwarding calls like that. I'm assuming you are already doing something like this anyway! It's just, what are the instructions? I really can't wait to reveal the sql library I've been nursing along with my web project. I don't want to post it yet here, because it will just garner more questions. I can point you at some early ideas I had on this kind of model-based programming, in a Boston meetup I did a talk for a number of years ago: https://www.youtube.com/watch?v=ZxzczSDaobw I do like the lambda directives as it, in my mind at least, enforces the idea that the record/class must be a simple data type (ie no crazy methods and such). I'm not sure what you think is a "crazy" method, but lambdas can do whatever a method can do. I like using models vs. template directives because you get to use the actual language to enforce your "model" is sane, and to make readable instructions for the metaprogramming processor. Like in one of your methods, you have: ```d property!("getMultipleOfX", (r, m) => r.x * m, int) ``` What is that `int` for? It's not clear from the usage, I have to go look it up. Most likely, it's the return type, but it's not nearly as clear as: ```d int getMultipleOfX(int m) { return x * m; } ``` Plus, I can debug my model without having to debug the metaprogramming stuff. I do have to admit this was more an exercise in metaprogramming, and since I did manage to make something I figured I'd share it. It's cool, I love using metaprogramming to write code for me. It's without a doubt the best reason to use D. Learning how to use to avoid writing boilerplate is life changing! -Steve
Re: record: C# like records for D
On Friday, 16 July 2021 at 19:37:53 UTC, Steven Schveighoffer wrote: On 7/16/21 10:52 AM, Dylan Graham wrote: On Friday, 16 July 2021 at 13:54:36 UTC, vit wrote: What adventage has record over normal immutable/const class? In terms of mutability, none. The duplicate method, however, lets you copy and mutate (once at duplication) a record without impacting the integrity of the original. You can do this with an immutable class, but then you have to roll your own. Really, it's more a convenience / less typing sort of feature, as it implements all the common boilerplate for you, which should help with consistency of code. What about a UFCS `duplicate` method? I'm not doubting there are good reasons to define types this way in C#, but D has pretty good tools when it comes to boilerplate. I would possibly suggest that instead of a record template that accepts directives using inline lambdas, etc, just accept a model type and use udas to adjust the record type. i.e.: ```d struct RecModel { @get_set float y; @get int x; auto getDoubleOfX() { return x * 2; } ... // etc } alias MyRecord = record!RecModel; ``` I use this kind of thing to great success in my SQL database system. -Steve That is a good idea, and to be honest I haven't looked at it that way. So the record is a separate type from its model? Ie: `class MyRecord {}` based off `struct RecordModel {}`? Or did I misunderstand? With regards to things like properties and methods, do you have RecModel inlined in the class and then forward the calls to it? Ie: ```D struct RecModel { @get int x; auto doubleOfX() { return x; } } class Rec { private RecModel instance; @property auto x() { return instance.x; } auto doubleOfX() { return instance.doubleOfX; } } ``` I do like the lambda directives as it, in my mind at least, enforces the idea that the record/class must be a simple data type (ie no crazy methods and such). I do have to admit this was more an exercise in metaprogramming, and since I did manage to make something I figured I'd share it.
Re: record: C# like records for D
On 7/16/21 10:52 AM, Dylan Graham wrote: On Friday, 16 July 2021 at 13:54:36 UTC, vit wrote: What adventage has record over normal immutable/const class? In terms of mutability, none. The duplicate method, however, lets you copy and mutate (once at duplication) a record without impacting the integrity of the original. You can do this with an immutable class, but then you have to roll your own. Really, it's more a convenience / less typing sort of feature, as it implements all the common boilerplate for you, which should help with consistency of code. What about a UFCS `duplicate` method? I'm not doubting there are good reasons to define types this way in C#, but D has pretty good tools when it comes to boilerplate. I would possibly suggest that instead of a record template that accepts directives using inline lambdas, etc, just accept a model type and use udas to adjust the record type. i.e.: ```d struct RecModel { @get_set float y; @get int x; auto getDoubleOfX() { return x * 2; } ... // etc } alias MyRecord = record!RecModel; ``` I use this kind of thing to great success in my SQL database system. -Steve
Re: From the D Blog: Driving with D
On Tuesday, 1 June 2021 at 11:57:34 UTC, Mike Parker wrote: Dylan Graham writes about his experience using D in a microcontroller project and why he chose it. Does anyone know of any similar projects using D? I don't. This may well be the first time it's been employed in this specific manner. Golem has translated the article into German and republished it: https://www.golem.de/news/programmiersprachen-durchstarten-mit-d-2107-157716.html
Re: record: C# like records for D
On Friday, 16 July 2021 at 13:54:36 UTC, vit wrote: On Wednesday, 14 July 2021 at 23:16:05 UTC, Dylan Graham wrote: [DUB](https://code.dlang.org/packages/record) [Github](https://github.com/hmmdyl/record) This is record. It aims to implement records similar to what C# has by leveraging D's metaprogramming. [C# Example 1](https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/types/records) [C# Example 2](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/records). Future steps are going to be adding a record struct; default value support; init-only-setters like in C#, wherein at the end of construction or duplication, the init lambda for the field is called, and the field can be set that once. What adventage has record over normal immutable/const class? In terms of mutability, none. The duplicate method, however, lets you copy and mutate (once at duplication) a record without impacting the integrity of the original. You can do this with an immutable class, but then you have to roll your own. Really, it's more a convenience / less typing sort of feature, as it implements all the common boilerplate for you, which should help with consistency of code.
Re: record: C# like records for D
On Wednesday, 14 July 2021 at 23:16:05 UTC, Dylan Graham wrote: [DUB](https://code.dlang.org/packages/record) [Github](https://github.com/hmmdyl/record) This is record. It aims to implement records similar to what C# has by leveraging D's metaprogramming. [C# Example 1](https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/types/records) [C# Example 2](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/records). Future steps are going to be adding a record struct; default value support; init-only-setters like in C#, wherein at the end of construction or duplication, the init lambda for the field is called, and the field can be set that once. What adventage has record over normal immutable/const class?
Re: record: C# like records for D
On Friday, 16 July 2021 at 13:14:22 UTC, Dylan Graham wrote: On Wednesday, 14 July 2021 at 23:16:05 UTC, Dylan Graham wrote: [DUB](https://code.dlang.org/packages/record) [Github](https://github.com/hmmdyl/record) ```D module myapp; class A{} auto MyRecord = record!(get!(A, "a")); // would throw an error as it could not find A ``` That should read ```D [...] alias MyRecord = record!(get!(A, "a")); // would throw an error ```
Re: record: C# like records for D
On Wednesday, 14 July 2021 at 23:16:05 UTC, Dylan Graham wrote: [DUB](https://code.dlang.org/packages/record) [Github](https://github.com/hmmdyl/record) Found and squashed some critical bugs. Thanks to Adam and Rikki for the help. Before, record would throw a compilation error due when passed types declared outside of drecord or its imports. Example: ```D module myapp; class A{} auto MyRecord = record!(get!(A, "a")); // would throw an error as it could not find A ``` This was due to improper usage of `.stringof` and mixins. This has been corrected and replaced with idiomatic D. The string generation functions for the constructor and opEquals have been removed and replaced in accordance to above.
Re: Beerconf July 2021
On 16/07/2021 11:45 PM, Iain Buclaw wrote: Just a forewarning, it was brought to my attention last month that for some people, Beerconf would fall on the Sunday/Monday 25-26th for them. Why? If you're living in Apia, Saturday 24th July would begin on Friday 23rd at 13:00 CEST, while in neighbouring Alofi, Sunday 25th ends on Monday 26th at 13:00 CEST. Wooow, thanks Iain!
Re: Beerconf July 2021
On Sunday, 11 July 2021 at 14:01:43 UTC, Steven Schveighoffer wrote: # BEERCONF! In 2 weeks we will have the 14th [mensual](https://www.merriam-webster.com/dictionary/mensual) online Beerconf on July 24-25! Just a forewarning, it was brought to my attention last month that for some people, Beerconf would fall on the Sunday/Monday 25-26th for them. Why? If you're living in Apia, Saturday 24th July would begin on Friday 23rd at 13:00 CEST, while in neighbouring Alofi, Sunday 25th ends on Monday 26th at 13:00 CEST. So this month as an experiment I'll be starting the Jitsi meeting at a time that suits people living on the edge of the positive side of UTC (mostly Auckland and East-coast Australia). If you are living in Europe or America, this would be Friday afternoon or evening for you. Depending on how it goes, either we'll see more of a spread out meet-up, or start being more centric around UTC. See you all next week!