Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Feb 9, 2022

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.

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.
@dlang-bot
Copy link
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

articles/mixin.dd Outdated Show resolved Hide resolved
@ntrel
Copy link
Contributor Author

ntrel commented Feb 10, 2022

@maxhaton Thanks, I changed the wording as suggested.

I also:

  • Added a section on 'Domain Specific Languages'.
  • Moved the 'Generating Declarations' heading to the top.


$(P
Combining compile-time function execution with `mixin()`
enables the use of domain-specific languages:)
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants