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. One of the very few times I find myself liking Ruby/Rails syntax

One of the very few times I find myself liking Ruby/Rails syntax

Scheduled Pinned Locked Moved The Lounge
rubyhelpquestioncsharpasp-net
15 Posts 7 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.
  • D Offline
    D Offline
    Dan Neely
    wrote on last edited by
    #1

    I'm replacing a ruby on rails site with C#/mvc. For the most part it's a complete rewrite because of problems with the site being scrapped. There're occasional parts where some logic is worth a directish port though. One is scoring standardized tests. I've got a test responses table full of columns like:

    Section1Question1Answer CHAR(1),
    Section1Question2Answer CHAR(1),
    ...
    Section1Question5Answer CHAR(1),
    Section2Question1Answer CHAR(1),
    Section2Question2Answer CHAR(1),
    ...
    Section13Question5Answer CHAR(1),

    The ruby code is then able to access the data like:

    for section in 1..SECTION_COUNT
    for question in 1..QUESTION_COUNT
    test_to_score["Section{section}Question{question}Answer"] #do stuff
    end
    end

    :cool: In C# I'm stuck with accessing them 1 at a time

    TestToScore.Section1Question1Answer //do stuff
    TestToScore.Section1Question2Answer //do stuff
    //... repeat 63 more times.
    

    X| I'm not doing enough processing for load/unloading temp arrays to be worthwhile, and every time I've thought to myself that reflection would be a good way to solve a problem I've ended up regretting it. :sigh: Redoing the DB to store a single answer/row instead of a test attempt/row would just change where the pain points are; and since the test will always be M sections of N questions each keeping the entire response together is a lot simpler.

    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

    T M R Z 5 Replies Last reply
    0
    • D Dan Neely

      I'm replacing a ruby on rails site with C#/mvc. For the most part it's a complete rewrite because of problems with the site being scrapped. There're occasional parts where some logic is worth a directish port though. One is scoring standardized tests. I've got a test responses table full of columns like:

      Section1Question1Answer CHAR(1),
      Section1Question2Answer CHAR(1),
      ...
      Section1Question5Answer CHAR(1),
      Section2Question1Answer CHAR(1),
      Section2Question2Answer CHAR(1),
      ...
      Section13Question5Answer CHAR(1),

      The ruby code is then able to access the data like:

      for section in 1..SECTION_COUNT
      for question in 1..QUESTION_COUNT
      test_to_score["Section{section}Question{question}Answer"] #do stuff
      end
      end

      :cool: In C# I'm stuck with accessing them 1 at a time

      TestToScore.Section1Question1Answer //do stuff
      TestToScore.Section1Question2Answer //do stuff
      //... repeat 63 more times.
      

      X| I'm not doing enough processing for load/unloading temp arrays to be worthwhile, and every time I've thought to myself that reflection would be a good way to solve a problem I've ended up regretting it. :sigh: Redoing the DB to store a single answer/row instead of a test attempt/row would just change where the pain points are; and since the test will always be M sections of N questions each keeping the entire response together is a lot simpler.

      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

      T Offline
      T Offline
      TheGreatAndPowerfulOz
      wrote on last edited by
      #2

      Reflection. Or put a reference to the fields, or whatever, into an array... and iterate.

      #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

      D T 2 Replies Last reply
      0
      • T TheGreatAndPowerfulOz

        Reflection. Or put a reference to the fields, or whatever, into an array... and iterate.

        #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #3

        Did you read what I wrote to the end? Every time I've done reflection it ends up becoming a footgun at some point in the future; and for what amounts to a single pass over the scores loading/unloading into arrays is just as verbose as accessing everything once directly.

        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

        Sander RosselS T 2 Replies Last reply
        0
        • T TheGreatAndPowerfulOz

          Reflection. Or put a reference to the fields, or whatever, into an array... and iterate.

          #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

          T Offline
          T Offline
          Tim Deveaux
          wrote on last edited by
          #4

          Or start with an array? Section1Answers VARCHAR(N) Then just parse/count and iter. Less of a mess in the DB?

          T 1 Reply Last reply
          0
          • D Dan Neely

            Did you read what I wrote to the end? Every time I've done reflection it ends up becoming a footgun at some point in the future; and for what amounts to a single pass over the scores loading/unloading into arrays is just as verbose as accessing everything once directly.

            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

            Sander RosselS Offline
            Sander RosselS Offline
            Sander Rossel
            wrote on last edited by
            #5

            My first was "reflection" as well, but then I read what you wrote at the end :laugh: I don't think reflection could hurt here though. It's just a small piece with a clear function. It wouldn't be much different than how Ruby solves it, which is calling the member using a literal string. It could go wrong if your naming convention changes or if someone added QuestionXSectionYAnswer (switching Question and Section), but that goes for the Ruby code as well.

            Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

            D 1 Reply Last reply
            0
            • D Dan Neely

              Did you read what I wrote to the end? Every time I've done reflection it ends up becoming a footgun at some point in the future; and for what amounts to a single pass over the scores loading/unloading into arrays is just as verbose as accessing everything once directly.

              Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

              T Offline
              T Offline
              TheGreatAndPowerfulOz
              wrote on last edited by
              #6

              ah I did read to the end but skimmed over that part. :-O My bad. :-\ :^) Yeah, maybe I should just shut-up. :D

              #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

              1 Reply Last reply
              0
              • T Tim Deveaux

                Or start with an array? Section1Answers VARCHAR(N) Then just parse/count and iter. Less of a mess in the DB?

                T Offline
                T Offline
                TheGreatAndPowerfulOz
                wrote on last edited by
                #7

                Maybe. Not sure what he's trying to accomplish. Maybe a table with question and answer columns?

                #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                1 Reply Last reply
                0
                • Sander RosselS Sander Rossel

                  My first was "reflection" as well, but then I read what you wrote at the end :laugh: I don't think reflection could hurt here though. It's just a small piece with a clear function. It wouldn't be much different than how Ruby solves it, which is calling the member using a literal string. It could go wrong if your naming convention changes or if someone added QuestionXSectionYAnswer (switching Question and Section), but that goes for the Ruby code as well.

                  Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                  D Offline
                  D Offline
                  Dan Neely
                  wrote on last edited by
                  #8

                  Sander Rossel wrote:

                  It wouldn't be much different than how Ruby solves it, which is calling the member using a literal string.

                  I know the feature in ruby works because its hashes all the way down (until you get to the pipe were the designers smoke it anyway); but the hackiness there is a core language feature not a gun that shoots bullets in multiple directions with every trigger pull only more dangerous.

                  Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                  Sander RosselS 1 Reply Last reply
                  0
                  • D Dan Neely

                    Sander Rossel wrote:

                    It wouldn't be much different than how Ruby solves it, which is calling the member using a literal string.

                    I know the feature in ruby works because its hashes all the way down (until you get to the pipe were the designers smoke it anyway); but the hackiness there is a core language feature not a gun that shoots bullets in multiple directions with every trigger pull only more dangerous.

                    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                    Sander RosselS Offline
                    Sander RosselS Offline
                    Sander Rossel
                    wrote on last edited by
                    #9

                    I see your point, but I'd still recommend reflection. Although typing out this stuff once isn't such a big deal either. writing a reflection solution probably costs you as much time as writing it out. The only reason to use reflection is because it's more fun to write :D

                    Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                    D 1 Reply Last reply
                    0
                    • Sander RosselS Sander Rossel

                      I see your point, but I'd still recommend reflection. Although typing out this stuff once isn't such a big deal either. writing a reflection solution probably costs you as much time as writing it out. The only reason to use reflection is because it's more fun to write :D

                      Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #10

                      I generated the 1 off code. Used a mix of typing and excel copydown to generate the numbers and then regexed the code I wanted out.

                      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                      1 Reply Last reply
                      0
                      • D Dan Neely

                        I'm replacing a ruby on rails site with C#/mvc. For the most part it's a complete rewrite because of problems with the site being scrapped. There're occasional parts where some logic is worth a directish port though. One is scoring standardized tests. I've got a test responses table full of columns like:

                        Section1Question1Answer CHAR(1),
                        Section1Question2Answer CHAR(1),
                        ...
                        Section1Question5Answer CHAR(1),
                        Section2Question1Answer CHAR(1),
                        Section2Question2Answer CHAR(1),
                        ...
                        Section13Question5Answer CHAR(1),

                        The ruby code is then able to access the data like:

                        for section in 1..SECTION_COUNT
                        for question in 1..QUESTION_COUNT
                        test_to_score["Section{section}Question{question}Answer"] #do stuff
                        end
                        end

                        :cool: In C# I'm stuck with accessing them 1 at a time

                        TestToScore.Section1Question1Answer //do stuff
                        TestToScore.Section1Question2Answer //do stuff
                        //... repeat 63 more times.
                        

                        X| I'm not doing enough processing for load/unloading temp arrays to be worthwhile, and every time I've thought to myself that reflection would be a good way to solve a problem I've ended up regretting it. :sigh: Redoing the DB to store a single answer/row instead of a test attempt/row would just change where the pain points are; and since the test will always be M sections of N questions each keeping the entire response together is a lot simpler.

                        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

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

                        Quote:

                        Section1Question1Answer CHAR(1),

                        X| Why can't you do a table with:

                        SectionNumber int
                        QuestionNumber int
                        Answer char(1)

                        ?

                        Latest Articles:
                        16 Days: A TypeScript application from concept to implementation Database Transaction Management across AJAX Calls

                        D 1 Reply Last reply
                        0
                        • D Dan Neely

                          I'm replacing a ruby on rails site with C#/mvc. For the most part it's a complete rewrite because of problems with the site being scrapped. There're occasional parts where some logic is worth a directish port though. One is scoring standardized tests. I've got a test responses table full of columns like:

                          Section1Question1Answer CHAR(1),
                          Section1Question2Answer CHAR(1),
                          ...
                          Section1Question5Answer CHAR(1),
                          Section2Question1Answer CHAR(1),
                          Section2Question2Answer CHAR(1),
                          ...
                          Section13Question5Answer CHAR(1),

                          The ruby code is then able to access the data like:

                          for section in 1..SECTION_COUNT
                          for question in 1..QUESTION_COUNT
                          test_to_score["Section{section}Question{question}Answer"] #do stuff
                          end
                          end

                          :cool: In C# I'm stuck with accessing them 1 at a time

                          TestToScore.Section1Question1Answer //do stuff
                          TestToScore.Section1Question2Answer //do stuff
                          //... repeat 63 more times.
                          

                          X| I'm not doing enough processing for load/unloading temp arrays to be worthwhile, and every time I've thought to myself that reflection would be a good way to solve a problem I've ended up regretting it. :sigh: Redoing the DB to store a single answer/row instead of a test attempt/row would just change where the pain points are; and since the test will always be M sections of N questions each keeping the entire response together is a lot simpler.

                          Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

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

                          Or you could go old school - DataTable! table.Columns[$"Section{section}Question{question}Answer"]

                          Latest Articles:
                          16 Days: A TypeScript application from concept to implementation Database Transaction Management across AJAX Calls

                          1 Reply Last reply
                          0
                          • D Dan Neely

                            I'm replacing a ruby on rails site with C#/mvc. For the most part it's a complete rewrite because of problems with the site being scrapped. There're occasional parts where some logic is worth a directish port though. One is scoring standardized tests. I've got a test responses table full of columns like:

                            Section1Question1Answer CHAR(1),
                            Section1Question2Answer CHAR(1),
                            ...
                            Section1Question5Answer CHAR(1),
                            Section2Question1Answer CHAR(1),
                            Section2Question2Answer CHAR(1),
                            ...
                            Section13Question5Answer CHAR(1),

                            The ruby code is then able to access the data like:

                            for section in 1..SECTION_COUNT
                            for question in 1..QUESTION_COUNT
                            test_to_score["Section{section}Question{question}Answer"] #do stuff
                            end
                            end

                            :cool: In C# I'm stuck with accessing them 1 at a time

                            TestToScore.Section1Question1Answer //do stuff
                            TestToScore.Section1Question2Answer //do stuff
                            //... repeat 63 more times.
                            

                            X| I'm not doing enough processing for load/unloading temp arrays to be worthwhile, and every time I've thought to myself that reflection would be a good way to solve a problem I've ended up regretting it. :sigh: Redoing the DB to store a single answer/row instead of a test attempt/row would just change where the pain points are; and since the test will always be M sections of N questions each keeping the entire response together is a lot simpler.

                            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                            R Offline
                            R Offline
                            Rage
                            wrote on last edited by
                            #13

                            If this thread does not end up in a lecture about the billionth other possibilities how you could have done it better in C#, this is not a coding forum anymore. :rolleyes: I love this kind of threads: Q: "- Hey guys, I am using X to do Y, and I would need to know how I could do Z" A1:"- Why are you using X to do Y ? W is much better". A2:"- Wow, I would never use X that way. Plus Y is not recommended by [book you have never heard of, but obviously should have]. Maybe you should consider switching technologies" ... A187273:"- No wonder that we have flat-earthers bitching about global warming criticizing vegans that do not believe in the moon landing if you do Y by using X". :-D

                            Do not escape reality : improve reality !

                            1 Reply Last reply
                            0
                            • D Dan Neely

                              I'm replacing a ruby on rails site with C#/mvc. For the most part it's a complete rewrite because of problems with the site being scrapped. There're occasional parts where some logic is worth a directish port though. One is scoring standardized tests. I've got a test responses table full of columns like:

                              Section1Question1Answer CHAR(1),
                              Section1Question2Answer CHAR(1),
                              ...
                              Section1Question5Answer CHAR(1),
                              Section2Question1Answer CHAR(1),
                              Section2Question2Answer CHAR(1),
                              ...
                              Section13Question5Answer CHAR(1),

                              The ruby code is then able to access the data like:

                              for section in 1..SECTION_COUNT
                              for question in 1..QUESTION_COUNT
                              test_to_score["Section{section}Question{question}Answer"] #do stuff
                              end
                              end

                              :cool: In C# I'm stuck with accessing them 1 at a time

                              TestToScore.Section1Question1Answer //do stuff
                              TestToScore.Section1Question2Answer //do stuff
                              //... repeat 63 more times.
                              

                              X| I'm not doing enough processing for load/unloading temp arrays to be worthwhile, and every time I've thought to myself that reflection would be a good way to solve a problem I've ended up regretting it. :sigh: Redoing the DB to store a single answer/row instead of a test attempt/row would just change where the pain points are; and since the test will always be M sections of N questions each keeping the entire response together is a lot simpler.

                              Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                              Z Offline
                              Z Offline
                              ZurdoDev
                              wrote on last edited by
                              #14

                              Do not discount Reflection solely based on the fact that you weren't able to make good use of it previously. It has amazing powers but should not be your first choice, usually.

                              Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                              1 Reply Last reply
                              0
                              • M Marc Clifton

                                Quote:

                                Section1Question1Answer CHAR(1),

                                X| Why can't you do a table with:

                                SectionNumber int
                                QuestionNumber int
                                Answer char(1)

                                ?

                                Latest Articles:
                                16 Days: A TypeScript application from concept to implementation Database Transaction Management across AJAX Calls

                                D Offline
                                D Offline
                                Dan Neely
                                wrote on last edited by
                                #15

                                Way too much refactoring for the potential benefit; even before data migration and fighting with a CI system that chokes on anything it thinks might be a lossy DB change (a separate issue entirely).

                                Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                                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