Skip to content

Enhance ValidateRange attributes #4477

Closed

Description

@iSazonov

From #4084 (comment)

We could enhance and unify Ranges. Currently Min and Max values are allowed but user can want to exclude them. Ex., "Positive" exclude zero. So the "Positive" range looks:

ValidateRange(0, int.MaxValue, RangeOption.ExcludeMin)

"Negative":

ValidateRange( -int.MaxValue, 0, RangeOption.ExcludeMax)

Exclude both (allow 0.5):

ValidateRange( 0, 1, RangeOption.ExcludeMin+RangeOption.ExcludeMax)

And we can move switch (rangeKind) to a constructor (with assigning a specific error message) and implement general ValidateElement method.

Activity

  1. added
    WG-Engine
    Issue-Enhancement
    on Aug 3, 2017
  2. iSazonov commented on Aug 3, 2017

    @iSazonov
    CollaboratorAuthor

    David Christian (@dchristian3188) Please confirm if you plan continue the work.

  3. dchristian3188 commented on Aug 3, 2017

    @dchristian3188
    Contributor

    yes Ilya (@iSazonov) , please assign to me

  4. lzybkr commented on Aug 3, 2017

    @lzybkr
    Contributor

    I wonder if this is really necessary.
    It's only useful for double/float ranges and I don't think those are used very often.

  5. iSazonov commented on Aug 4, 2017

    @iSazonov
    CollaboratorAuthor

    double/float ranges - it is really limitation in ValidRangeAttribute - why we allow it for [int] but block for double/float? - we're provoking customers to use workarounds.

    With enumerations the enhancement can be usefull too. Ex., if we want only exclude minimal and maximal values: 1,3,5,7 -> ValidateRange(1,7, ExcludeMin+ExcludeMax) - we accept only 3 and 5. If later we add 2: 1,2,3,5,7 -> ValidateRange(1,7, ExcludeMin+ExcludeMax) - we accept now 2, 3 and 5 without change the attribute.

  6. lzybkr commented on Aug 4, 2017

    @lzybkr
    Contributor

    It's really not that useful for doubles because equality is not precise.

    I feel like this complicates a simple attribute for little benefit. Enums are usually sequential and it's easier to understand an inclusive range.

    As a parallel, the .. operator is always closed and I've never seen a request to support open intervals.

  7. iSazonov commented on Aug 6, 2017

    @iSazonov
    CollaboratorAuthor

    I've never seen a request to support open intervals

    It's not a bug to open immediately a support case. So a script writer just uses a bypass.

  8. lzybkr commented on Aug 7, 2017

    @lzybkr
    Contributor

    Features and new apis should be added for the right reasons. It's not enough that someone might need to write some code - here is a very brief list of things I think about when considering new features:

    • Does the feature introduce or remove complexity for the user?
    • Does the feature introduce or remove complexity in the implementation?
    • If the feature introduces complexity - will there be a net benefit? Will it help enough people to justify the feature?
    • What do we lose in introduce the feature?

    In my mind, this feature does not help enough people to justify the time spent reviewing the design and implementation and ensuring it gets tested and documented correctly.

    PowerShell has enough users - if nobody has complained about this, you're probably right that they worked around it, but it also tells me it doesn't come up often enough to warrant even one complaint.

  9. iSazonov commented on Aug 8, 2017

    @iSazonov
    CollaboratorAuthor

    Thank you for your deep explanation. It would be good to have in our documentation next to breaking change requirements.

    1. Does the feature introduce or remove complexity for the user? - No and no.
    2. Does the feature introduce or remove complexity in the implementation? - It is short and simple code.
    3. If the feature introduces complexity - will there be a net benefit? Will it help enough people to justify the feature? It is simple. The net benefit is that it closes the only and final omission to get a complete solution. We can't appreciate how many people want this, because now they're using workarounds.
    4. The main difficulty may be to distinguish int anf float parameter types. This can actually create complexity.

    A separate question we left in the past PR is that we should remove second code path and implement general ValidateElement method.

  10. lzybkr commented on Aug 8, 2017

    @lzybkr
    Contributor

    I disagree on 1. - it might remove complexity for the rare case, but in the common case, there are additional options that must be considered - so instead of one decision, now I must make two or three.

    Often I see unnecessary complexity and I think this happens due to feature creep - adding something seemed reasonable at the time, but the accretion of features results in a mess over the long term.

  11. iSazonov commented on Aug 9, 2017

    @iSazonov
    CollaboratorAuthor

    It's also very subjective. It also gives rise to complexity if it falls short of our expectations. You like Positive/Negative. I would preffer classic math terms:
    (a, b)
    (a, b]
    [a, b)
    [a, b]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions