Coffeehouse Post

Single Post Permalink

View Thread: How are you using Tuple in code?
  • User profile image

    @spivonious: That's part of the benefit of tuple assignment. Concsumption isn't helped, as you have to know the what the items in the tuple are when writing the code, but reading the code has been brought back into parity (or, arguably, made even better).

    int index, string name = FindMostExpensiveProduct();

    Given that, I know FindMostExpensiveProduct() just returned me an index and a name. In your example:

    Product p = FindMostExpensiveProduct();

    I'd assume I was given back a product, which would include a lot more than just an index and a name. This discussion would be easier if I'd picked a better example, as this particular API is extremely dumb, whether you use a Tuple or not.

    Honestly, though, Tuple still suffers in an OO language. Most of the time where you'd care to use a Tuple an anonymous type or a domain specific type would work out better. I just know that in languages that support tuple assignment I've never had problems with using tuple types, while in C# I've never written anything but throw away code that used one of the Tuple types.