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. Thought about programming

Thought about programming

Scheduled Pinned Locked Moved The Lounge
questiondiscussiontutorial
61 Posts 18 Posters 6 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.
  • J Jamie Nordmeyer

    This is not a question about how to do something, per say, but is a question of opinion. Still, if anyone feels this post is ill placed, let me know, and I'll move it. :) I noticed a language on SourceForget the other day called Nice, that had an interesting feature called Tuples. Essentially, it allowed you to do this:

    (int, int) FooBar()
    {
    return 5, 10;
    }

    My question is what do you think about this in a language. Most of our languages have thus far only supported a single return value, where as Nice allows an arbitrary number of values to be returned. Thoughts? Jamie Nordmeyer Portland, Oregon, USA

    S Offline
    S Offline
    Shog9 0
    wrote on last edited by
    #5

    Eh, what's wrong with:

    struct blah_t { int i; int j; };
    blah_t FooBar()
    {
    blah_t ret = {5,10};
    return ret;
    }

    or for that matter,

    void FooBar(int& i, int &j)
    {
    i = 5; j = 10;
    }

    Granted, Nice sounds concise, but it seems unnecessary given how often such a thing is necessary.

    ---

    Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

    F C C C J 5 Replies Last reply
    0
    • J Jamie Nordmeyer

      This is not a question about how to do something, per say, but is a question of opinion. Still, if anyone feels this post is ill placed, let me know, and I'll move it. :) I noticed a language on SourceForget the other day called Nice, that had an interesting feature called Tuples. Essentially, it allowed you to do this:

      (int, int) FooBar()
      {
      return 5, 10;
      }

      My question is what do you think about this in a language. Most of our languages have thus far only supported a single return value, where as Nice allows an arbitrary number of values to be returned. Thoughts? Jamie Nordmeyer Portland, Oregon, USA

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #6

      You can do this in C# this way:

      int[] FooBar()
      {
      return new int[] { 5, 10 };
      }

      or this way:

      int FooBar(out int retval2)
      {
      retval2 = 10;
      return 5;
      }

      I see dumb people

      1 Reply Last reply
      0
      • S Shog9 0

        Eh, what's wrong with:

        struct blah_t { int i; int j; };
        blah_t FooBar()
        {
        blah_t ret = {5,10};
        return ret;
        }

        or for that matter,

        void FooBar(int& i, int &j)
        {
        i = 5; j = 10;
        }

        Granted, Nice sounds concise, but it seems unnecessary given how often such a thing is necessary.

        ---

        Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

        F Offline
        F Offline
        Fazlul Kabir
        wrote on last edited by
        #7

        Shog9 wrote: Granted, Nice sounds concise, but it seems unnecessary given how often such a thing is necessary. That was my thought too. // Fazlul >

        1 Reply Last reply
        0
        • S Shog9 0

          Eh, what's wrong with:

          struct blah_t { int i; int j; };
          blah_t FooBar()
          {
          blah_t ret = {5,10};
          return ret;
          }

          or for that matter,

          void FooBar(int& i, int &j)
          {
          i = 5; j = 10;
          }

          Granted, Nice sounds concise, but it seems unnecessary given how often such a thing is necessary.

          ---

          Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #8

          Shog9 wrote: Eh, what's wrong with... both are forcing you to work around limitations of the language. what you really want to do is "return 2 values". it's similar to the way you can do "OO" in plain C by clever use of function pointers and structures to simulate objects. but, it's nothing like C++, where OO is built-in. -c


          There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

          Smaller Animals Software

          S J 2 Replies Last reply
          0
          • C Chris Losinger

            Shog9 wrote: Eh, what's wrong with... both are forcing you to work around limitations of the language. what you really want to do is "return 2 values". it's similar to the way you can do "OO" in plain C by clever use of function pointers and structures to simulate objects. but, it's nothing like C++, where OO is built-in. -c


            There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

            Smaller Animals Software

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #9

            Chris Losinger wrote: both are forcing you to work around limitations of the language. Well, yeah, and C# lets you do properties with get and set methods automatically called at appropriate times. But how much of this is a big advantage? Can you provide an example where code clarity is increased significantly by being able to return two values?

            ---

            Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

            C F 2 Replies Last reply
            0
            • S Shog9 0

              Eh, what's wrong with:

              struct blah_t { int i; int j; };
              blah_t FooBar()
              {
              blah_t ret = {5,10};
              return ret;
              }

              or for that matter,

              void FooBar(int& i, int &j)
              {
              i = 5; j = 10;
              }

              Granted, Nice sounds concise, but it seems unnecessary given how often such a thing is necessary.

              ---

              Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

              C Offline
              C Offline
              ColinDavies
              wrote on last edited by
              #10

              _(int, int) FooBar(){ return 5, 10;}_ is not the same as Shog9 wrote: _void FooBar(int& i, int &j){ i = 5; j = 10;}_ Regardz Colin J Davies

              Sonork ID 100.9197:Colin

              You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

              S 1 Reply Last reply
              0
              • C ColinDavies

                _(int, int) FooBar(){ return 5, 10;}_ is not the same as Shog9 wrote: _void FooBar(int& i, int &j){ i = 5; j = 10;}_ Regardz Colin J Davies

                Sonork ID 100.9197:Colin

                You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

                S Offline
                S Offline
                Shog9 0
                wrote on last edited by
                #11

                Colin Davies wrote: not the same No, but one could replace the other without too much trouble. If performance was an issue, the first method - or inlining - could be used.

                ---

                Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

                1 Reply Last reply
                0
                • J Jamie Nordmeyer

                  This is not a question about how to do something, per say, but is a question of opinion. Still, if anyone feels this post is ill placed, let me know, and I'll move it. :) I noticed a language on SourceForget the other day called Nice, that had an interesting feature called Tuples. Essentially, it allowed you to do this:

                  (int, int) FooBar()
                  {
                  return 5, 10;
                  }

                  My question is what do you think about this in a language. Most of our languages have thus far only supported a single return value, where as Nice allows an arbitrary number of values to be returned. Thoughts? Jamie Nordmeyer Portland, Oregon, USA

                  C Offline
                  C Offline
                  ColinDavies
                  wrote on last edited by
                  #12

                  Jamie Nordmeyer wrote: My question is what do you think about this in a language. I think it's a darn useful feature. Some might think "How often would I use it?" But if it was added to C++ I'm sure I'd find more and more uses for it. The best way to find out how useful something is, isn't to add it, but to remove it. :-) Maybe, I should use the Boost version. :-) Regardz Colin J Davies

                  Sonork ID 100.9197:Colin

                  You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

                  S J 2 Replies Last reply
                  0
                  • S Shog9 0

                    Chris Losinger wrote: both are forcing you to work around limitations of the language. Well, yeah, and C# lets you do properties with get and set methods automatically called at appropriate times. But how much of this is a big advantage? Can you provide an example where code clarity is increased significantly by being able to return two values?

                    ---

                    Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

                    C Offline
                    C Offline
                    Chris Losinger
                    wrote on last edited by
                    #13

                    int Foo(thing &a, thing &b, thing &c, thing inputThing)
                    {
                    ...
                    return 0;
                    }

                    in C++ anyway, it's not obvious if a, b and c are output, or if they are simply passed by reference to avoid unnecessary overhead. yes, adding "const" to them would clarify status as input-only, but const-correctness is something i don't see a lot of. if C++ allowed something like:

                    int,thing[] Foo(thing inputThing)
                    {

                    return 0, {a, b, c};
                    }

                    it would be obvious that a, b and c are outputs. C# definitely improves on the clarity aspect with the "out", "ref", etc. keywords, but it still isn't ideal. -c


                    There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                    Smaller Animals Software

                    S 1 Reply Last reply
                    0
                    • C ColinDavies

                      Jamie Nordmeyer wrote: My question is what do you think about this in a language. I think it's a darn useful feature. Some might think "How often would I use it?" But if it was added to C++ I'm sure I'd find more and more uses for it. The best way to find out how useful something is, isn't to add it, but to remove it. :-) Maybe, I should use the Boost version. :-) Regardz Colin J Davies

                      Sonork ID 100.9197:Colin

                      You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining. Said by Roger Wright about me.

                      S Offline
                      S Offline
                      Shog9 0
                      wrote on last edited by
                      #14

                      Colin Davies wrote: The best way to find out how useful something is, isn't to add it, but to remove it. True, that. :) One of the things i miss most in VB are C's +=, *=, &= etc. operators... Never something i would have wanted prior to using C, but sure conspicuous when absent now...!

                      ---

                      Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

                      N 1 Reply Last reply
                      0
                      • J Jamie Nordmeyer

                        This is not a question about how to do something, per say, but is a question of opinion. Still, if anyone feels this post is ill placed, let me know, and I'll move it. :) I noticed a language on SourceForget the other day called Nice, that had an interesting feature called Tuples. Essentially, it allowed you to do this:

                        (int, int) FooBar()
                        {
                        return 5, 10;
                        }

                        My question is what do you think about this in a language. Most of our languages have thus far only supported a single return value, where as Nice allows an arbitrary number of values to be returned. Thoughts? Jamie Nordmeyer Portland, Oregon, USA

                        N Offline
                        N Offline
                        Neville Franks
                        wrote on last edited by
                        #15

                        Isn't this what STL pair is all about. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program

                        C 1 Reply Last reply
                        0
                        • C Chris Losinger

                          int Foo(thing &a, thing &b, thing &c, thing inputThing)
                          {
                          ...
                          return 0;
                          }

                          in C++ anyway, it's not obvious if a, b and c are output, or if they are simply passed by reference to avoid unnecessary overhead. yes, adding "const" to them would clarify status as input-only, but const-correctness is something i don't see a lot of. if C++ allowed something like:

                          int,thing[] Foo(thing inputThing)
                          {

                          return 0, {a, b, c};
                          }

                          it would be obvious that a, b and c are outputs. C# definitely improves on the clarity aspect with the "out", "ref", etc. keywords, but it still isn't ideal. -c


                          There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                          Smaller Animals Software

                          S Offline
                          S Offline
                          Shog9 0
                          wrote on last edited by
                          #16

                          Chris Losinger wrote: const-correctness is something i don't see a lot of. Sad but true. Well, as Colin suggested, this may be one of those things that would prove to be useful once possible. "How to return multiple values" certainly seems to be a common question for those learning to program, so perhaps it's intuitiveness would make it worthwhile...

                          ---

                          Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

                          1 Reply Last reply
                          0
                          • J Jamie Nordmeyer

                            Interesting. I'll have to read that more fully when I get the time. Thanks. :) Jamie Nordmeyer Portland, Oregon, USA

                            N Offline
                            N Offline
                            Nemanja Trifunovic
                            wrote on last edited by
                            #17

                            An example from the site: tuple add_multiply_divide(int a, int b) { return make_tuple(a+b, a*b, double(a)/double(b)); }

                            1 Reply Last reply
                            0
                            • N Neville Franks

                              Isn't this what STL pair is all about. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program

                              C Offline
                              C Offline
                              Chris Losinger
                              wrote on last edited by
                              #18

                              pair will get you 2. how do you do 3, 10 or 50? -c


                              There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                              Smaller Animals Software

                              N T P 3 Replies Last reply
                              0
                              • J Jamie Nordmeyer

                                This is not a question about how to do something, per say, but is a question of opinion. Still, if anyone feels this post is ill placed, let me know, and I'll move it. :) I noticed a language on SourceForget the other day called Nice, that had an interesting feature called Tuples. Essentially, it allowed you to do this:

                                (int, int) FooBar()
                                {
                                return 5, 10;
                                }

                                My question is what do you think about this in a language. Most of our languages have thus far only supported a single return value, where as Nice allows an arbitrary number of values to be returned. Thoughts? Jamie Nordmeyer Portland, Oregon, USA

                                T Offline
                                T Offline
                                Tim Smith
                                wrote on last edited by
                                #19

                                Yup, sounds good. Only would need it once in a blue moon. I would rather have the compiler vendors spending time working on a better compiler than the standards group sitting around trying to justify their existence. IMHO, C/C++ has really come to the end of their extensible lifetime. It really needs to be rebuilt from the ground up and not have new features just hacked onto it. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                                C J 2 Replies Last reply
                                0
                                • C Chris Losinger

                                  pair will get you 2. how do you do 3, 10 or 50? -c


                                  There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                                  Smaller Animals Software

                                  N Offline
                                  N Offline
                                  Neville Franks
                                  wrote on last edited by
                                  #20

                                  Chris Losinger wrote: pair will get you 2. how do you do 3, 10 or 50? I thought he only wanted 2. Someone else mentioned boost tupples. In my vast experience a pair is the most common requirement here by far.:) Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program

                                  J 1 Reply Last reply
                                  0
                                  • C Chris Losinger

                                    pair will get you 2. how do you do 3, 10 or 50? -c


                                    There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'. --Holgate, from Plastic

                                    Smaller Animals Software

                                    T Offline
                                    T Offline
                                    Tim Smith
                                    wrote on last edited by
                                    #21

                                    std::vector :omg::rolleyes::laugh: Tim Smith I'm going to patent thought. I have yet to see any prior art.

                                    C J 2 Replies Last reply
                                    0
                                    • T Tim Smith

                                      Yup, sounds good. Only would need it once in a blue moon. I would rather have the compiler vendors spending time working on a better compiler than the standards group sitting around trying to justify their existence. IMHO, C/C++ has really come to the end of their extensible lifetime. It really needs to be rebuilt from the ground up and not have new features just hacked onto it. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                                      C Offline
                                      C Offline
                                      CodeGuy
                                      wrote on last edited by
                                      #22

                                      Tim Smith wrote: IMHO, C/C++ has really come to the end of their extensible lifetime. It really needs to be rebuilt from the ground up and not have new features just hacked onto it. Hear, hear. Brandon

                                      T 1 Reply Last reply
                                      0
                                      • C CodeGuy

                                        Tim Smith wrote: IMHO, C/C++ has really come to the end of their extensible lifetime. It really needs to be rebuilt from the ground up and not have new features just hacked onto it. Hear, hear. Brandon

                                        T Offline
                                        T Offline
                                        Tim Smith
                                        wrote on last edited by
                                        #23

                                        LOL... Sometimes it is more scary where people agree with me. :eek: Tim Smith I'm going to patent thought. I have yet to see any prior art.

                                        1 Reply Last reply
                                        0
                                        • S Shog9 0

                                          Chris Losinger wrote: both are forcing you to work around limitations of the language. Well, yeah, and C# lets you do properties with get and set methods automatically called at appropriate times. But how much of this is a big advantage? Can you provide an example where code clarity is increased significantly by being able to return two values?

                                          ---

                                          Shog9 Life seems pretty easy when it's from my easy chair And you're burnin up inside and no one cares...

                                          F Offline
                                          F Offline
                                          Fazlul Kabir
                                          wrote on last edited by
                                          #24

                                          Shog9 wrote: C# lets you do properties with get and set methods automatically called at appropriate times. But how much of this is a big advantage? I think "properties" let us write code in a more "human readable" fashion. Compare the two sets of statements below: myForm.BackColor = red; Color clr = myForm.BackColor; and myForm.setBackColor(red); Color clr = myForm.getBackColor(); But I agree, these choices are merely based on convenience, that's all.

                                          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