Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. A Blatant Programming Question

A Blatant Programming Question

Scheduled Pinned Locked Moved The Lounge
questioncsharpdata-structureshelptutorial
60 Posts 28 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Roger Wright

    Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)

    Will Rogers never met me.

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #18

    Well, my biased opinion: Tuples were added to .NET languages because they are an important feature of functional languages, and since Microsoft was adding F# to be IL compatible, they needed support for tuples. Tuples are a simple way of creating typed structures on the fly (type is inferred by the usage of their items), without having to actually create a class or struct. In F#, they are even simpler than records. So, given that, tuples are useful when you need to return more than one value from a function call. For example, a success/fail along with a success/default value. Or the real and imaginary components of a complex number. I don't find tuples necessarily that useful for passing data into a function, the exception being passing the tuple return of one function into another function. Tuples do not replace lists, arrays, or other collections. Does that help? Marc

    My Blog
    Computational Types in C# and F#

    L 1 Reply Last reply
    0
    • K Kenneth Haugland

      People that are too lazy to write classes? Or have a class that would contain many properties? Seem to be the general idea: C# 4 - Tuples[^]

      R Offline
      R Offline
      RugbyLeague
      wrote on last edited by
      #19

      Laziness - that's why I occasionally use them. I feel dirty afterwards.

      K 1 Reply Last reply
      0
      • R Roger Wright

        Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)

        Will Rogers never met me.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #20

        If you can't think of a reason, and a custom class or struct will suffice (and be more descriptive), then write a class or struct. I'll occasionally use a Tuple briefly to test something before I write a class. If you can use a class, you should use a class.

        L 1 Reply Last reply
        0
        • K Kenneth Haugland

          :laugh: Only the items could be anything, seems very much to resemble a list of different objects, witch you could send around without createing a class. I cant think of a use. WPF and binding seem to make them unnessecary, but what do I know... Im sure that someone will tell you that the planets existens depended on this class...

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #21

          Kenneth Haugland wrote:

          witch you could send around without createing a class.

          It would still require a class instance.

          1 Reply Last reply
          0
          • L leppie

            Anonymous classes handle most of these cases and cleaner in my opinion. Who knows what Item0 and Item1 and Item2 is?

            IronScheme
            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #22

            leppie wrote:

            Who knows what Item0 and Item1 and Item2 is?

            The Tuple is a generic type so that shouldn't be a problem.

            L 1 Reply Last reply
            0
            • R Roger Wright

              Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)

              Will Rogers never met me.

              B Offline
              B Offline
              BillWoodruff
              wrote on last edited by
              #23

              I never thought I'd see the day when I'd vote anything posted by one of my very favorite posters, Roger Wright, a "one," but in this case I feel there is a compelling reason to do so based on what I view as a concern for the quality of CP as-a-whole, and I have fully explained that here on "Bugs and suggs:" [^]. best, Bill p.s. go ahead and down-vote me all you like: if my entire reputation on CP is wiped out, and I go "underwater," well: let's just say, I have "gills," and "don't give a damn" at nearly 69 years of age: in my opinion if a person by the time of their sixties doesn't know what their values are, and is not willing to go out-on-a-limb, and stand up for them, well ... you fill in the rest of the sentence, please ...

              "One of the few good things about modern times: If you die horribly on television, you will not have died in vain. You will have entertained us." Kurt Vonnegut

              L R L 3 Replies Last reply
              0
              • L leppie

                Anonymous classes handle most of these cases and cleaner in my opinion. Who knows what Item0 and Item1 and Item2 is?

                IronScheme
                ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                P Offline
                P Offline
                Phil Martin
                wrote on last edited by
                #24

                Anonymous classes handle exactly two of those cases.

                L 1 Reply Last reply
                0
                • J jschell

                  leppie wrote:

                  Who knows what Item0 and Item1 and Item2 is?

                  The Tuple is a generic type so that shouldn't be a problem.

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #25

                  And now you have 2+ problems ;p

                  IronScheme
                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                  1 Reply Last reply
                  0
                  • P Phil Martin

                    Anonymous classes handle exactly two of those cases.

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #26

                    Within context, I will handle all of those. But yes, if exposing them non-functionally, only 2.

                    IronScheme
                    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                    1 Reply Last reply
                    0
                    • B BillWoodruff

                      I never thought I'd see the day when I'd vote anything posted by one of my very favorite posters, Roger Wright, a "one," but in this case I feel there is a compelling reason to do so based on what I view as a concern for the quality of CP as-a-whole, and I have fully explained that here on "Bugs and suggs:" [^]. best, Bill p.s. go ahead and down-vote me all you like: if my entire reputation on CP is wiped out, and I go "underwater," well: let's just say, I have "gills," and "don't give a damn" at nearly 69 years of age: in my opinion if a person by the time of their sixties doesn't know what their values are, and is not willing to go out-on-a-limb, and stand up for them, well ... you fill in the rest of the sentence, please ...

                      "One of the few good things about modern times: If you die horribly on television, you will not have died in vain. You will have entertained us." Kurt Vonnegut

                      L Offline
                      L Offline
                      leppie
                      wrote on last edited by
                      #27

                      Even if you were a mute deaf I would still upvote you ;p

                      IronScheme
                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                      1 Reply Last reply
                      0
                      • P PIEBALDconsult

                        If you can't think of a reason, and a custom class or struct will suffice (and be more descriptive), then write a class or struct. I'll occasionally use a Tuple briefly to test something before I write a class. If you can use a class, you should use a class.

                        L Offline
                        L Offline
                        leppie
                        wrote on last edited by
                        #28

                        People are so scared of writing something once...

                        IronScheme
                        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                        1 Reply Last reply
                        0
                        • M Marc Clifton

                          Well, my biased opinion: Tuples were added to .NET languages because they are an important feature of functional languages, and since Microsoft was adding F# to be IL compatible, they needed support for tuples. Tuples are a simple way of creating typed structures on the fly (type is inferred by the usage of their items), without having to actually create a class or struct. In F#, they are even simpler than records. So, given that, tuples are useful when you need to return more than one value from a function call. For example, a success/fail along with a success/default value. Or the real and imaginary components of a complex number. I don't find tuples necessarily that useful for passing data into a function, the exception being passing the tuple return of one function into another function. Tuples do not replace lists, arrays, or other collections. Does that help? Marc

                          My Blog
                          Computational Types in C# and F#

                          L Offline
                          L Offline
                          leppie
                          wrote on last edited by
                          #29

                          Marc Clifton wrote:

                          tuples are useful when you need to return more than one value from a function call

                          Yet this is still an ugly hack for returning multiple values. A proper language would be consuming the (remaining) values (on the stack) based on the continuation.

                          IronScheme
                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                          1 Reply Last reply
                          0
                          • E Espen Harlinn

                            Tuple types were added to facilitate language interoperability and to reduce duplication in the framework. As you noticed a tuple is a simple generic data structure that holds an ordered set of items. Tuples are supported natively in languages such as F# and IronPython.

                            Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Whenever methodologies become productized, objectivity is removed from the equation. -- Mike Myatt

                            L Offline
                            L Offline
                            leppie
                            wrote on last edited by
                            #30

                            Given the Python argument, I would prefer .NET support PHP then too ;p

                            IronScheme
                            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                            E 1 Reply Last reply
                            0
                            • L leppie

                              Given the Python argument, I would prefer .NET support PHP then too ;p

                              IronScheme
                              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                              E Offline
                              E Offline
                              Espen Harlinn
                              wrote on last edited by
                              #31

                              Here you go: Welcome to Phalanger[^]

                              Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Whenever methodologies become productized, objectivity is removed from the equation. -- Mike Myatt

                              L 1 Reply Last reply
                              0
                              • R RugbyLeague

                                Laziness - that's why I occasionally use them. I feel dirty afterwards.

                                K Offline
                                K Offline
                                Kenneth Haugland
                                wrote on last edited by
                                #32

                                Ah... Just call the garbage collecter afterword, and you would be fine. :laugh:

                                R 1 Reply Last reply
                                0
                                • L leppie

                                  Anonymous classes handle most of these cases and cleaner in my opinion. Who knows what Item0 and Item1 and Item2 is?

                                  IronScheme
                                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                  B Offline
                                  B Offline
                                  BillWoodruff
                                  wrote on last edited by
                                  #33

                                  Hi Leppie, I have written a request to you to please give an example of use of anonymous classes here on the "Tuple" thread on the C# forum:[^]. I'd really appreciate hearing more about that ! best, Bill

                                  "One of the few good things about modern times: If you die horribly on television, you will not have died in vain. You will have entertained us." Kurt Vonnegut

                                  1 Reply Last reply
                                  0
                                  • B BillWoodruff

                                    I never thought I'd see the day when I'd vote anything posted by one of my very favorite posters, Roger Wright, a "one," but in this case I feel there is a compelling reason to do so based on what I view as a concern for the quality of CP as-a-whole, and I have fully explained that here on "Bugs and suggs:" [^]. best, Bill p.s. go ahead and down-vote me all you like: if my entire reputation on CP is wiped out, and I go "underwater," well: let's just say, I have "gills," and "don't give a damn" at nearly 69 years of age: in my opinion if a person by the time of their sixties doesn't know what their values are, and is not willing to go out-on-a-limb, and stand up for them, well ... you fill in the rest of the sentence, please ...

                                    "One of the few good things about modern times: If you die horribly on television, you will not have died in vain. You will have entertained us." Kurt Vonnegut

                                    R Offline
                                    R Offline
                                    Roger Wright
                                    wrote on last edited by
                                    #34

                                    While I completely disagree with your opinion, I highly respect it and accordingly, voted you a "5" as well. :-D It was a technical question - which is perfectly valid in the Lounge - about a concept, not a programming help request. It has broad application to multiple languages, and is entirely proper in the Lounge. I found the responses illuminating, but in no way instructive, which was exactly what I was seeking - a general perspective.

                                    Will Rogers never met me.

                                    1 Reply Last reply
                                    0
                                    • E Espen Harlinn

                                      Here you go: Welcome to Phalanger[^]

                                      Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Whenever methodologies become productized, objectivity is removed from the equation. -- Mike Myatt

                                      L Offline
                                      L Offline
                                      leppie
                                      wrote on last edited by
                                      #35

                                      I meant being influenced by the semantics of PHP ;p

                                      IronScheme
                                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                      E 1 Reply Last reply
                                      0
                                      • L leppie

                                        I meant being influenced by the semantics of PHP ;p

                                        IronScheme
                                        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                        E Offline
                                        E Offline
                                        Espen Harlinn
                                        wrote on last edited by
                                        #36

                                        leppie wrote:

                                        influenced by the semantics of PHP

                                        Those being? Mind, I've got nothing against PHP, I just never use it ... ;)

                                        Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Whenever methodologies become productized, objectivity is removed from the equation. -- Mike Myatt

                                        L 1 Reply Last reply
                                        0
                                        • E Espen Harlinn

                                          leppie wrote:

                                          influenced by the semantics of PHP

                                          Those being? Mind, I've got nothing against PHP, I just never use it ... ;)

                                          Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Whenever methodologies become productized, objectivity is removed from the equation. -- Mike Myatt

                                          L Offline
                                          L Offline
                                          leppie
                                          wrote on last edited by
                                          #37

                                          Espen Harlinn wrote:

                                          Those being?

                                          Dont really know, but none or horrible comes to mind ;p

                                          IronScheme
                                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups