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

Enum Parameters #232

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

Enum Parameters #232

wants to merge 18 commits into from

Conversation

Bolpat
Copy link
Contributor

@Bolpat Bolpat commented Oct 13, 2022

No description provided.

@mdparker
Copy link
Member

@Bolpat Thanks for submitting this, but next time please wait until your first draft is complete before submitting the PR. I'd rather keep in-development DIPs out of the queue. Thanks!

Copy link
Contributor

@dukc dukc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this DIP interesting. It has fairly high potential for design problems that are hard to foresee, since many expressions that are currently always runtime can become compile-time. But it also enables so much new patterns that I think this is worth exploring further.

However, I'm less convinced about the @nodbi attribute. It solves a problem that can be mostly solvedl by simply assigning an enum parameter to a local variable in the function. I do get the attribute has some advantages over that, but enum arguments are already an advanced language feature that is at the limits of what most people can reasonably comprehend. Having an attribute that adds more rules on top of that probably isn't worth it.

DIPs/1NNN-QFS.md Outdated Show resolved Hide resolved
@Bolpat
Copy link
Contributor Author

Bolpat commented Nov 22, 2022

@dukc, thank you for reading.

However, I'm less convinced about the @nodbi attribute. It solves a problem that can be mostly solved by simply assigning an enum parameter to a local variable in the [caller]. I do get the attribute has some advantages over that, but enum arguments are already an advanced language feature that is at the limits of what most people can reasonably comprehend. Having an attribute that adds more rules on top of that probably isn't worth it.

I thought that as well. I put it in because it can easily be removed later and one of the first reactions I got when I put the idea on the forum was: “But what about (template) bloat?” Had I found a workaround to get the benefits it provides, it’d never seen the light of day. I’ve marked it optional for now and I’m currently considering alternative syntax like in enum as a replacement for @nodbi enum. My general feeling is that people dislike new attributes far more than combining existing ones with new semantics.

Another rationale for talking about @nodbi is that people might ask for it. The sections dedicated to it also serve to expose how complicated and subtle the thing they’re having in mind actually is; e.g. the rule “a @nodbi parameter may only be used in constraints and static assert” won’t do. (If someone finds a simpler rule, I’ll appreciate.)

@Bolpat Bolpat marked this pull request as ready for review November 22, 2022 09:47
@schveiguy
Copy link
Member

I'm all for this idea, sans the @nodbi mechanism (which seems orthogonal and can be added later, also the name needs attention). Technically, also the optimizations can be added later, but do help describe how to avoid template bloat.

FWIW, a similar discussion on the forums brought this idea to the forefront:

https://forum.dlang.org/post/unseru$167e$1@digitalmars.com
https://forum.dlang.org/post/ojotybtiosjikmmcxemw@forum.dlang.org

So glad to see this all fleshed out and ready to go!

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

Successfully merging this pull request may close these issues.

4 participants