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

Initial draft of Flags Enum Operators proposal. #241

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AdamSpeight2008
Copy link
Contributor

@AdamSpeight2008 AdamSpeight2008 commented Jan 7, 2018

Potential solution for #228
Proposal for Flags Enum Operators.

@franzalex
Copy link

franzalex commented Jan 16, 2018

Much as I like [and appreciate] the work that this is receiving, I think that using the extension methods (after a relaxation of the generic type parameter rules to allow Enums) is more readable. Better still, this could be built into the Framework itself instead of using extension methods.

I find the code below to be more readable

Dim someColor As Flags
someColor.Set(Flags.Red)
someColor.Set(Flags.Green)

If Not someColor.IsSet(Flags.Blue) Then
    ' do something
End If

It may be verbose, but it the intent is clearer. Plus, it ties in better with other similar implementations such as Jon Skeet's UnconstranedMelody and Tyler Brinkley's Enums.NET.

Note as well that the latter developer is even trying to get some of Enums.NET's improvements into corefx in this proposal which has gained quite a lot of traction. So my opinion is that we try to make design this to look and work similarly rather than coming up with new and potentially obscure operators.

My two cents.

@AdamSpeight2008
Copy link
Contributor Author

AdamSpeight2008 commented Jan 16, 2018

@franzalex I see them as complimentary, the corefx proposal cover the framework api. This covers a possible language support. Akin to ValueTyples

I think have a language feature, we could do a form of constant folding on the setting and clearing of flags.

@AdamSpeight2008
Copy link
Contributor Author

Screenshot of how it looks
enumflagoperators02

The states!Blue = True assignment targeting isn't supported, has I not yet looked at how to implement it. Supported states!Red '(IsSet), states!+Red ' (Set Flag) and states!-Red '(Clear Flag)

@ghost
Copy link

ghost commented Feb 13, 2018

@franzalex
I agree. I said something like that in:
#228 (comment)
I don't like the !+ and !- sympoles.

@AdamSpeight2008
Copy link
Contributor Author

Comparisions

Quick Token Accumulator
Currently
Using Feature

SynthesizedMethod.vb
Currently
Using Feature

@gafter
Copy link
Member

gafter commented Feb 14, 2018

@AdamSpeight2008 The first step in designing a language feature is to open an issue on the vblang repository requesting or proposing the feature where it can be discussed by the community and the LDM. If and when the LDM believes it has converged on a language approach to the problem identified (note that the LDM starts by considering the problem to be solved), then (and only then) it makes sense to add a specification draft. This PR is premature.

@AdamSpeight2008
Copy link
Contributor Author

@gafter I did is in in #228

@AdamSpeight2008
Copy link
Contributor Author

As proposed the ! IsSet operator, is treated as are all these flags set.
Should we also support are any of these flags set ?

@gafter
Copy link
Member

gafter commented Feb 14, 2018

#228 does not indicate that the LDM decided on this form of a language feature for the problem.

@AdamSpeight2008
Copy link
Contributor Author

I'm considering implementing

  • !/ as the IsAnyFlagSet binary operator.
  • extending the flag part to include ParenthesiesExpressions as well
    • As it will allow passing a variable identifier as the argument on the right.
    • Dim HasRedAndGreenFlag As Boolean = enumFlags ! ( Flags.Red !+ Flags.Green )
    • Dim HasRedOrGreenFlag As Boolean = enumFlags !/ ( Flags.Red !+ Flags.Green )

@AdamSpeight2008
Copy link
Contributor Author

flagsenumoperatorswithparanethisedexpressions

Note to self: Update the specification

@AdamSpeight2008
Copy link
Contributor Author

The following branch has an experimental prototype implementation. stable but don't use on anything vital
Prototypes/VB_EnumFlagExpression

Base automatically changed from master to main March 9, 2021 19:15
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.

3 participants