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. Other Discussions
  3. The Weird and The Wonderful
  4. That may have been a mistake...

That may have been a mistake...

Scheduled Pinned Locked Moved The Weird and The Wonderful
visual-studiotestingbeta-testingtutorialquestion
23 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.
  • P PIEBALDconsult

    I suspect that a Web service, backed by a database, might be worth a try...

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #8

    OOO! Now there is an idea for the "Extra Credit" version - can I steal it? :laugh:

    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    1 Reply Last reply
    0
    • J Jeroen De Dauw

      To bad you don't get paid per line right? :D

      Jeroen De Dauw
      Blog ; Wiki

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #9

      I don't get paid on Saturdays anyway :(

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        As some of you may know, I created a Tip/Trick recently about converting numbers to the word equivalent (523 to "Five hundred and twenty three"). With my tongue firmly rammed into my cheek, I suggested that a switch statement would be a good way to do it. Well, it's Saturday, and I thought to myself "A switch has got to be faster than the proper way - I wonder how much faster?" So I thought I'd check. I wrote and tested a proper version and used it to generate the Big Switch code I'd need, writing it to a text file "BigSwitch.cs". Then I could include this and do a side-by-side comparison. Initial testing of the "proper" way to do it suggested that one million iterations should test all code paths and eliminate cached jitter in the results. So, I made my mistake. I double clicked on the "BigSwitch.cs" file I had created. VS2008 started to load it. I'm still not sure if it would have suceeded; I killed the process after 30 minutes. Note to self: Do not attempt to load 82.7 Mb code fragments into VS again... :-O

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #10

        Maybe your app should have emitted IL code rather than C# code. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        OriginalGriffO 1 Reply Last reply
        0
        • L Luc Pattyn

          Maybe your app should have emitted IL code rather than C# code. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #11

          Luc Pattyn wrote:

          hould have emitted IL code

          :laugh: :thumbsup: Good idea - but it would have defeated the purpose of the timing tests. I would have written the IL code as assembler: numeric index into jump table, or string pointer table maybe. I was more interested in how the compiler would handle the problem than I was in how I would handle it! PiebaldConsult came up with an idea for a web service backed by a database, so I mocked up the database version (with a SqlCE DB) that works up to 1,000,000 - a total of a 92MB DB - it seems pretty fast and the code is pretty small. Do you think I should post it as a new Tip / Trick: "Numbers to words : the Extra Credit version"? :laugh:

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          L 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Luc Pattyn wrote:

            hould have emitted IL code

            :laugh: :thumbsup: Good idea - but it would have defeated the purpose of the timing tests. I would have written the IL code as assembler: numeric index into jump table, or string pointer table maybe. I was more interested in how the compiler would handle the problem than I was in how I would handle it! PiebaldConsult came up with an idea for a web service backed by a database, so I mocked up the database version (with a SqlCE DB) that works up to 1,000,000 - a total of a 92MB DB - it seems pretty fast and the code is pretty small. Do you think I should post it as a new Tip / Trick: "Numbers to words : the Extra Credit version"? :laugh:

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #12

            OriginalGriff wrote:

            it would have defeated the purpose

            rather than write code, you should have read this then: Something You May Not Know About the Switch Statement in C/C++[^]. And if you are convinced C# may behave differently, it would deserve a real article.

            OriginalGriff wrote:

            Do you think I should post it as a new Tip / Trick

            Absolutely, a tip or article. And please include an SQL file with the data, so others can set up their own DB.

            OriginalGriff wrote:

            Five hundred and twenty three

            There seems to be one more issue that needs getting settled: should or shouldn't you use a hyphen in those inverted decimal-and-unit combinations? And if both are acceptable, how to let the user choose? :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            OriginalGriffO P 2 Replies Last reply
            0
            • L Luc Pattyn

              OriginalGriff wrote:

              it would have defeated the purpose

              rather than write code, you should have read this then: Something You May Not Know About the Switch Statement in C/C++[^]. And if you are convinced C# may behave differently, it would deserve a real article.

              OriginalGriff wrote:

              Do you think I should post it as a new Tip / Trick

              Absolutely, a tip or article. And please include an SQL file with the data, so others can set up their own DB.

              OriginalGriff wrote:

              Five hundred and twenty three

              There seems to be one more issue that needs getting settled: should or shouldn't you use a hyphen in those inverted decimal-and-unit combinations? And if both are acceptable, how to let the user choose? :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #13

              Luc Pattyn wrote:

              should or shouldn't you use a hyphen in those inverted decimal-and-unit combinations?

              Thank you for pointing out this problem; you are indeed quite correct and there should be a hyphen between the tens digit and the units digit for all values between 21 and 99, excepting (of course) those integrally divisible by ten. This also applies to such numbers when considered as part of a larger number: "one thousand and sixty-seven" or "three hundred and fourty-eight thousand". In addition, there may be a comma between the magnitude indicator and the lesser value ("one thousand, three hundred and sixty-seven") although this is not compulsory (unless there is a decimal point in the number, in which case it should appear at each three digit position to the right of the decimal). I had completely forgotten this point, and have modified the Tip / Trick accordingly. In my defence, it has been many years since I last wrote a cheque and thus any numbers as words! Even then, to exceed one thousand on a personal cheque was not an everyday occurrence... :laugh: I have corrected this, and provided credit as is only appropriate.:thumbsup:

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              L 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                Luc Pattyn wrote:

                should or shouldn't you use a hyphen in those inverted decimal-and-unit combinations?

                Thank you for pointing out this problem; you are indeed quite correct and there should be a hyphen between the tens digit and the units digit for all values between 21 and 99, excepting (of course) those integrally divisible by ten. This also applies to such numbers when considered as part of a larger number: "one thousand and sixty-seven" or "three hundred and fourty-eight thousand". In addition, there may be a comma between the magnitude indicator and the lesser value ("one thousand, three hundred and sixty-seven") although this is not compulsory (unless there is a decimal point in the number, in which case it should appear at each three digit position to the right of the decimal). I had completely forgotten this point, and have modified the Tip / Trick accordingly. In my defence, it has been many years since I last wrote a cheque and thus any numbers as words! Even then, to exceed one thousand on a personal cheque was not an everyday occurrence... :laugh: I have corrected this, and provided credit as is only appropriate.:thumbsup:

                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #14

                Thanks for the clarification, and of course the credit. I didn't know at all about the thousands separators turning into comma's (and I hope you really mean "," and not "comma"). How about the ultimate edition, dealing with floating-point numbers? (could be double, float, decimal) :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                OriginalGriffO 1 Reply Last reply
                0
                • L Luc Pattyn

                  OriginalGriff wrote:

                  it would have defeated the purpose

                  rather than write code, you should have read this then: Something You May Not Know About the Switch Statement in C/C++[^]. And if you are convinced C# may behave differently, it would deserve a real article.

                  OriginalGriff wrote:

                  Do you think I should post it as a new Tip / Trick

                  Absolutely, a tip or article. And please include an SQL file with the data, so others can set up their own DB.

                  OriginalGriff wrote:

                  Five hundred and twenty three

                  There seems to be one more issue that needs getting settled: should or shouldn't you use a hyphen in those inverted decimal-and-unit combinations? And if both are acceptable, how to let the user choose? :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  P Online
                  P Online
                  PIEBALDconsult
                  wrote on last edited by
                  #15

                  The beauty of the database solution is that you can easily add globalization -- a new language/culture is simply another column in the table. :cool:

                  L 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    The beauty of the database solution is that you can easily add globalization -- a new language/culture is simply another column in the table. :cool:

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #16

                    Yep. And you can outsource it, all it takes is a linguist, not a programmer. Maybe there is a business opportunity here. Or there could soon be a new homework assignment: given a numbers-to-words database in language A, translate it automatically to language B. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                    P 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Yep. And you can outsource it, all it takes is a linguist, not a programmer. Maybe there is a business opportunity here. Or there could soon be a new homework assignment: given a numbers-to-words database in language A, translate it automatically to language B. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                      P Online
                      P Online
                      PIEBALDconsult
                      wrote on last edited by
                      #17

                      Oh, good, so journalism majors can find work. P.S. http://search.dilbert.com/search?w=journalism+major[^]

                      1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        As some of you may know, I created a Tip/Trick recently about converting numbers to the word equivalent (523 to "Five hundred and twenty three"). With my tongue firmly rammed into my cheek, I suggested that a switch statement would be a good way to do it. Well, it's Saturday, and I thought to myself "A switch has got to be faster than the proper way - I wonder how much faster?" So I thought I'd check. I wrote and tested a proper version and used it to generate the Big Switch code I'd need, writing it to a text file "BigSwitch.cs". Then I could include this and do a side-by-side comparison. Initial testing of the "proper" way to do it suggested that one million iterations should test all code paths and eliminate cached jitter in the results. So, I made my mistake. I double clicked on the "BigSwitch.cs" file I had created. VS2008 started to load it. I'm still not sure if it would have suceeded; I killed the process after 30 minutes. Note to self: Do not attempt to load 82.7 Mb code fragments into VS again... :-O

                        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                        R Offline
                        R Offline
                        Robert Rohde
                        wrote on last edited by
                        #18

                        Hi, I know you are not totally serious but what is the correct way and why should it not be faster than a large switch? I think the created IL code behaves similar to a very large if-then-elseif construct. Thus the switch-solution will get slower if you increase the range of supported numbers. btw: I would create a "real algorithm" to produce the strings and pair it with a dictionary as a cache. Robert

                        OriginalGriffO D 2 Replies Last reply
                        0
                        • R Robert Rohde

                          Hi, I know you are not totally serious but what is the correct way and why should it not be faster than a large switch? I think the created IL code behaves similar to a very large if-then-elseif construct. Thus the switch-solution will get slower if you increase the range of supported numbers. btw: I would create a "real algorithm" to produce the strings and pair it with a dictionary as a cache. Robert

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #19

                          There are many ways to do a switch: For example, you could set up a table of delegates (each delegate referring to a method which executes the case block). To implement the switch for a numeric value, you need only use the parameter as an index into the table. No comparisons are required, so executions speed is excellent and the time taken to get to the code for the case block is the same for each case. To implement this with an if-then-else requires a comparison for each case in turn - this is understandably slower, and the execution time differs for each case. There are other ways - the above is only suitable for densely populated cases - but I hope that makes some sense!

                          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          1 Reply Last reply
                          0
                          • L Luc Pattyn

                            Thanks for the clarification, and of course the credit. I didn't know at all about the thousands separators turning into comma's (and I hope you really mean "," and not "comma"). How about the ultimate edition, dealing with floating-point numbers? (could be double, float, decimal) :)

                            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                            OriginalGriffO Offline
                            OriginalGriffO Offline
                            OriginalGriff
                            wrote on last edited by
                            #20

                            Luc Pattyn wrote:

                            How about the ultimate edition, dealing with floating-point numbers?

                            I think that is the "Pro Ultimate Gold Team Edition for Workgroups Turbo CRXVI-DiD" due for simultaneous release with the "Hades Low Temperature Food Storage Conditions" application. The release date of the later is, unfortunately, beyond my control - but is estimated to be when Microsoft release a bug-free version of Visual Studio.

                            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                            1 Reply Last reply
                            0
                            • R Robert Rohde

                              Hi, I know you are not totally serious but what is the correct way and why should it not be faster than a large switch? I think the created IL code behaves similar to a very large if-then-elseif construct. Thus the switch-solution will get slower if you increase the range of supported numbers. btw: I would create a "real algorithm" to produce the strings and pair it with a dictionary as a cache. Robert

                              D Offline
                              D Offline
                              Daniel Grunwald
                              wrote on last edited by
                              #21

                              Robert Rohde wrote:

                              I think the created IL code behaves similar to a very large if-then-elseif construct. Thus the switch-solution will get slower if you increase the range of supported numbers.

                              Wrong. IL has a special instruction for switch which the JIT translates into a jump table. Switches of consecutive integer values (so that a table without large holes is possible) don't get slower if you add cases. Switches of strings are implemented using a Dictionary<string, int> and the IL switch instruction on the resulting int.

                              1 Reply Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                As some of you may know, I created a Tip/Trick recently about converting numbers to the word equivalent (523 to "Five hundred and twenty three"). With my tongue firmly rammed into my cheek, I suggested that a switch statement would be a good way to do it. Well, it's Saturday, and I thought to myself "A switch has got to be faster than the proper way - I wonder how much faster?" So I thought I'd check. I wrote and tested a proper version and used it to generate the Big Switch code I'd need, writing it to a text file "BigSwitch.cs". Then I could include this and do a side-by-side comparison. Initial testing of the "proper" way to do it suggested that one million iterations should test all code paths and eliminate cached jitter in the results. So, I made my mistake. I double clicked on the "BigSwitch.cs" file I had created. VS2008 started to load it. I'm still not sure if it would have suceeded; I killed the process after 30 minutes. Note to self: Do not attempt to load 82.7 Mb code fragments into VS again... :-O

                                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                                P Offline
                                P Offline
                                Peter_in_2780
                                wrote on last edited by
                                #22

                                Since you are now the "expert", how about a similar answer for this one[^]? ;P :laugh: ;P

                                Software rusts. Simon Stephenson, ca 1994.

                                OriginalGriffO 1 Reply Last reply
                                0
                                • P Peter_in_2780

                                  Since you are now the "expert", how about a similar answer for this one[^]? ;P :laugh: ;P

                                  Software rusts. Simon Stephenson, ca 1994.

                                  OriginalGriffO Offline
                                  OriginalGriffO Offline
                                  OriginalGriff
                                  wrote on last edited by
                                  #23

                                  Done - Conversion to Roman dates using a database[^] Thank you for the idea! :laugh:

                                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                  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