-
-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[articles/mixin.dd] Add concatenation, statements, types, expressions #3209
base: master
Are you sure you want to change the base?
Conversation
Add 4 sections. Split statement spec examples into 2. Use foreach and show mixin reading variable declared in current scope. Move mixin variable declaration example to MixinDeclaration from statement.dd.
Thanks for your pull request and interest in making D better, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
There's already a struct declaration mixin there.
@maxhaton Thanks, I changed the wording as suggested. I also:
|
|
||
$(P | ||
Combining compile-time function execution with `mixin()` | ||
enables the use of domain-specific languages:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of this example. JavaScript is a general purpose programming language, a DSL is something like regex or SQL. Implementing convertJS
would be a huge undertaking, and it doesn't reflect a real use case (or at least I don't see it). Why would you write this, instead of translating the JS offline and putting the result in your .d file?
I suggest using pegged as an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why any of that really matters. If the reader can't discern "real use cases" from a demonstrative example then they're not going to get anything from any example.
Besides, JavaScript did literally start as the ultimate domain specific language a long time ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixins are a confusing feature, and their working / purpose are easily misunderstood. Consider the target audience for these articles: they're programmers who are new to D and might not have done any meta-programming beforehand. When you tell "mixin("int y;")
is equivalent to int y;
" the first question is "what does mixin
do then?".
The specification can be very dry in its explanations, but the article should help programmers understand what actual problems the feature solves. There's a tendency of new D users to complicate things with mixin
when regular functions could be used, which is not helped by poor official examples.
Change
genStruct
eponymous template to enum template.Add 5 sections: argument concatenation, declarations, statements, types, expressions. The examples added are all taken from the spec.
Add Comparison with C preprocessor heading.
Also tweak spec examples:
Split mixin statement spec examples into 2. Change for -> foreach and show mixin code reading a variable declared in current scope.
Move mixin variable declaration example to MixinDeclaration from statement.dd.
Update:
Add 'Domain Specific Languages' section with simple JS example.