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. Programming's Foul Language

Programming's Foul Language

Scheduled Pinned Locked Moved The Lounge
tutorialquestion
111 Posts 61 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.
  • F Fabio Franco

    I agree with that, despite knowing that at Assembly level, that's exactly what your code will do.

    J Offline
    J Offline
    jeron1
    wrote on last edited by
    #87

    Fabio Franco wrote:

    knowing that at Assembly level, that's exactly what your code will do.

    True, I have programmed in both languages and for some reason it seems natural (maybe because there's no choice?) in assembler and completely out of place in C++.

    F 1 Reply Last reply
    0
    • J jeron1

      goto X|

      O Offline
      O Offline
      Owen37
      wrote on last edited by
      #88

      goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).

      J D T E 4 Replies Last reply
      0
      • O Owen37

        goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).

        J Offline
        J Offline
        jeron1
        wrote on last edited by
        #89

        Owen37 wrote:

        if used extremely sparingly - so sparingly that I haven't used it in over 10 years!)

        I guess I'm not saying that they can NEVER be useful, it's just that whenever I've seen it used abused, it had no business in the code and it's always at least a red flag.

        Owen37 wrote:

        (getting ready for all the thumbs-down).

        Not from me. :)

        O 1 Reply Last reply
        0
        • D Dan Neely

          .... right up until something changes in the library and it can throw a new exception at which point the library author has to either break every single app that consumes it, cast the new exception into a different type defeating the purpose of typed exceptions in the first place, or just have every method throw exception from the start defeating the purpose of checked exceptions from the start. X|

          The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.

          V Offline
          V Offline
          Vikram A Punathambekar
          wrote on last edited by
          #90

          Valid point, but if your library is very volatile, you can wrap all exceptions that happen in your method into a YourCustomException and throw the wrapper instance.

          Cheers, Vikram. (Proud to have finally cracked a CCC!)

          D 1 Reply Last reply
          0
          • O Owen37

            goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).

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

            How is using goto better than a switch statement in a while(true) loop?

            The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.

            O 1 Reply Last reply
            0
            • D Dan Neely

              How is using goto better than a switch statement in a while(true) loop?

              The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.

              O Offline
              O Offline
              Owen37
              wrote on last edited by
              #92

              Well, like I said, I haven't used goto in over 10 years. Almost always switch or while or some other construct is better. However, the one time I used it was in a very large state-machine (decoding a satellite signal) where switch just did not work.

              1 Reply Last reply
              0
              • J jeron1

                Owen37 wrote:

                if used extremely sparingly - so sparingly that I haven't used it in over 10 years!)

                I guess I'm not saying that they can NEVER be useful, it's just that whenever I've seen it used abused, it had no business in the code and it's always at least a red flag.

                Owen37 wrote:

                (getting ready for all the thumbs-down).

                Not from me. :)

                O Offline
                O Offline
                Owen37
                wrote on last edited by
                #93

                jeron1 wrote:

                I guess I'm not saying that they can NEVER be useful, it's just that whenever I've seen it used abused, it had no business in the code and it's always at least a red flag.

                Oh yeah! ALWAYS a RED FLAG! Even when I did have to use it (in the large state-machine) I felt dirty and wanted to run home and take a shower every time I looked at it. After numerous code reviews (some by the VP of development), it held up as the most efficient way to handle the data stream. And, it's in the comments/documentation for the code.

                1 Reply Last reply
                0
                • C csharphacker

                  You do realize you can mark up which exceptions are thrown in XML comments? I forget if that junk shows up in the intellisense though...

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

                  Yes, it does.

                  1 Reply Last reply
                  0
                  • O Owen37

                    goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).

                    T Offline
                    T Offline
                    TNCaver
                    wrote on last edited by
                    #95

                    One defense for the goto I've heard is from people whose programming policies require that functions have a single exit point. Aiming for a single Exit Sub/Function/Return point without goto can easily make for some complex and hard to maintain control paths, often with multiple levels of nested if/then blocks.

                    V 1 Reply Last reply
                    0
                    • B Brady Kelly

                      Prolific maybe, but between them and partial classes, I get quite extended.

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

                      Oh, yeah, I forgot about partial when I wrote that, but then I use partial even when I don't need it. I actually feel that classes should be partial by default and that there should be no keyword for it. Trying to compile an actual partial class with C# 1.0 will break even if there is no keyword, so I don't see the need. And I think the word I really wanted was "profligate"; I'm not sure which word works best in the context.

                      B D 2 Replies Last reply
                      0
                      • P PIEBALDconsult

                        Oh, yeah, I forgot about partial when I wrote that, but then I use partial even when I don't need it. I actually feel that classes should be partial by default and that there should be no keyword for it. Trying to compile an actual partial class with C# 1.0 will break even if there is no keyword, so I don't see the need. And I think the word I really wanted was "profligate"; I'm not sure which word works best in the context.

                        B Offline
                        B Offline
                        Brady Kelly
                        wrote on last edited by
                        #97

                        I like to know when I'm partial to something.

                        P 1 Reply Last reply
                        0
                        • B Brady Kelly

                          I like to know when I'm partial to something.

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

                          I'm not partial to needless keywords and syntax changes.

                          1 Reply Last reply
                          0
                          • J jeron1

                            Fabio Franco wrote:

                            knowing that at Assembly level, that's exactly what your code will do.

                            True, I have programmed in both languages and for some reason it seems natural (maybe because there's no choice?) in assembler and completely out of place in C++.

                            F Offline
                            F Offline
                            Fabio Franco
                            wrote on last edited by
                            #99

                            jeron1 wrote:

                            it seems natural (maybe because there's no choice?)

                            Yep, there is no choice. The program counter (PC) points which statement will execute next. The processor looks that up in the memory and if nothing is done, it will simply execute the next item in the stack. So in order to perform conditional tasks (if) or loops (for/while) the processor understands the MOV command which is exactly what the "goto" command does. All your ifs, whiles and fors become nothing when compiled to native machine language. They all become "goto's". Thank God nowadays we are not required to go assembly in most cases, things can get ugly. Cheers Fábio

                            1 Reply Last reply
                            0
                            • V Vikram A Punathambekar

                              Valid point, but if your library is very volatile, you can wrap all exceptions that happen in your method into a YourCustomException and throw the wrapper instance.

                              Cheers, Vikram. (Proud to have finally cracked a CCC!)

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

                              throws Exception, throws MyCustomExceptionWhichWrapsEverything, and lack of a throws statement; are equally useless at providing meaningful information to the consumer.

                              The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.

                              V 1 Reply Last reply
                              0
                              • P PIEBALDconsult

                                Oh, yeah, I forgot about partial when I wrote that, but then I use partial even when I don't need it. I actually feel that classes should be partial by default and that there should be no keyword for it. Trying to compile an actual partial class with C# 1.0 will break even if there is no keyword, so I don't see the need. And I think the word I really wanted was "profligate"; I'm not sure which word works best in the context.

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

                                Unless you're suggesting replacing it with a new keyword eg singlefile that does the opposite I'm strongly opposed because it means I don't have any mandatory information about if a class is fully contained in a single file or if it's got implementation spread among several. If you are suggesting singlefile instead of partial then I disagree because you're changing the implicit behavior of legacy code. The only change I'd make would be to add a warning if there was *not* a second instance of a partial class eg if you ooopsed and only renamed/renamespaced the class in one of the files instead of all of them.

                                The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.

                                P 1 Reply Last reply
                                0
                                • D Dan Neely

                                  Unless you're suggesting replacing it with a new keyword eg singlefile that does the opposite I'm strongly opposed because it means I don't have any mandatory information about if a class is fully contained in a single file or if it's got implementation spread among several. If you are suggesting singlefile instead of partial then I disagree because you're changing the implicit behavior of legacy code. The only change I'd make would be to add a warning if there was *not* a second instance of a partial class eg if you ooopsed and only renamed/renamespaced the class in one of the files instead of all of them.

                                  The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.

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

                                  dan neely wrote:

                                  a new keyword eg singlefile

                                  No.

                                  dan neely wrote:

                                  if a class is fully contained in a single file or if it's got implementation spread among several

                                  I don't need that information. And it doesn't tell you which other files anyway so I don't see the benefit. The main thing is, I may post some code here and someone may want to add something to it for their own purposes. If I include partial (even though my code doesn't need it), they don't have to touch my file. If I leave off partial, they have to add it even though they're using partial in an effort to not alter my file. Partial classes enable such easy additions to code, but the partial keyword hinders that ease. All classes should be partial without needing a new keyword.

                                  D 1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    dan neely wrote:

                                    a new keyword eg singlefile

                                    No.

                                    dan neely wrote:

                                    if a class is fully contained in a single file or if it's got implementation spread among several

                                    I don't need that information. And it doesn't tell you which other files anyway so I don't see the benefit. The main thing is, I may post some code here and someone may want to add something to it for their own purposes. If I include partial (even though my code doesn't need it), they don't have to touch my file. If I leave off partial, they have to add it even though they're using partial in an effort to not alter my file. Partial classes enable such easy additions to code, but the partial keyword hinders that ease. All classes should be partial without needing a new keyword.

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

                                    PIEBALDconsult wrote:

                                    I don't need that information. And it doesn't tell you which other files anyway so I don't see the benefit.

                                    I disagree about it's utility; and while I'll admit that's annoying and an obvious place for intellisence improvement, but having to search for partial class MyClass with a partial class to find the rest of it is less of a hassle than having to search for class MyClass with every class to find out if it's partial or not.

                                    PIEBALDconsult wrote:

                                    The main thing is, I may post some code here and someone may want to add something to it for their own purposes. If I include partial (even though my code doesn't need it), they don't have to touch my file.

                                    Within my codebase; if anything I see this as a feature since the changelog for my class will indicate that it's no longer contained in a single file. If anything I think the weakness is that adding a 3rd+ partial class file doesn't do anything to obviously indicate that the class has changed in the repositories history. So far it's never been an issue for me since I've only used partial to isolate my code from code autogenerated by a tool/designer of some sort.

                                    The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.

                                    1 Reply Last reply
                                    0
                                    • O Owen37

                                      goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).

                                      E Offline
                                      E Offline
                                      Edwin Smith
                                      wrote on last edited by
                                      #104

                                      Since I barely knew Dartmouth Basic when I started designing state machines for hardware controllers i didn't know there was anything like "goto" or "gosub". In all of the microcontrollers I've ever coded all we had were JMP, CALL, and sometimes SKIP for controlling program flow. Goto and Gosub were all higher level code which had to be interpreted or compiled into code the CPU could understand. I've also made state machines with NO ALU at all and one in particular out of PLD's that had NO compiler at all. I had to design the program flow by burning fuses in the PLD. No memory, no eproms, no disks, no keyboard and no display. Also, mine is bigger than yours. :-) Edwin

                                      O 1 Reply Last reply
                                      0
                                      • C Corporal Agarn

                                        Microsoft

                                        G Offline
                                        G Offline
                                        gstolarov
                                        wrote on last edited by
                                        #105

                                        You really picked the wrong forum for that :-)

                                        1 Reply Last reply
                                        0
                                        • E Edwin Smith

                                          Since I barely knew Dartmouth Basic when I started designing state machines for hardware controllers i didn't know there was anything like "goto" or "gosub". In all of the microcontrollers I've ever coded all we had were JMP, CALL, and sometimes SKIP for controlling program flow. Goto and Gosub were all higher level code which had to be interpreted or compiled into code the CPU could understand. I've also made state machines with NO ALU at all and one in particular out of PLD's that had NO compiler at all. I had to design the program flow by burning fuses in the PLD. No memory, no eproms, no disks, no keyboard and no display. Also, mine is bigger than yours. :-) Edwin

                                          O Offline
                                          O Offline
                                          Owen37
                                          wrote on last edited by
                                          #106

                                          DROOOOOoooooollllll,,,,,,, ;P

                                          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