Giter Site home page Giter Site logo

Comments (4)

danielwertheim avatar danielwertheim commented on August 20, 2024

Good Q, but I do think it was convenience to not have to invoke the ensure with (int)myLong

What's funnier though (just noticed) is the array version... it does not use LongLength for that overload.

from ensure.that.

ndrwrbgs avatar ndrwrbgs commented on August 20, 2024

Woah, I didn't even know LongLength was a thing. I guess we really do have lots of memory these days! I hope not many people are using this, sad LOH allocations 😞.

What would you like to see here?

  • Obviously we can update the array version to LongLength (given the next few items)
  • Should an IEnumerable version be exposed? (with comment & [InstantHandle] annotation to signal that it will actually enumerate it - unless )
    • I'd personally recommend not doing this because it's unlikely IMO that a user actually wants to enumerate such a sequence, especially more than once
    • Array seems to be the only exposed way of getting a long count in O(1) time in the current BCL, unless I am missing something
  • Should we continue to expose a long version?
    • I'd tentatively say yes after further thinking, but wanteto make sure there is a discussion/thought here. See example below.
// Example supporting the long version
void Example()
{
    var collection = new[] { 1, 2 };
    
    Console.WriteLine("How many items do you demand to have in the collection?");
    long input = long.Parse(Console.ReadLine());
    
    // Here we have 1 of 3 behaviors
    // Option 1: we throw ArgumentOutOfRangeException
    // Option 2 (they have to cast): if they are unchecked{} - they get off values like wrapping around if the input is in the > int.MaxValue
    // Option 3 (they have to cast): if they are checked{} - they get an OverflowException
    Ensure.That(collection).SizeIs(input);
}

from ensure.that.

ndrwrbgs avatar ndrwrbgs commented on August 20, 2024

So my suggestion would be to correct the Array version, leave the long version, and omit adding an IEnumerable version (e.g. make sure all exposed versions right now won't accept IEnumerable but only ICollection/IList)

from ensure.that.

danielwertheim avatar danielwertheim commented on August 20, 2024

Good morning. I agree to the last comment. IEnumerable overloads should not be added even if attributes can help with discoverability. Keep the long for convenience and correct array.

from ensure.that.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.