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. Handing in my Coder Card

Handing in my Coder Card

Scheduled Pinned Locked Moved The Lounge
csharpcom
18 Posts 13 Posters 5 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 Jason Hooper

    goto[^] I've only used goto once before as a professional and ended up removing it a few minutes later when I figured out a different way. Sometimes though for simplicity it just makes sense. I think I'll leave it! Anyone who thinks this code should not be checked in, speak now or forever hold your concurrency locks.

    Jason

    L Offline
    L Offline
    lewax00
    wrote on last edited by
    #5

    I feel like wrapping the rest of the code (up to "end") in an else block should cover that, why complicate it with uncommon syntax?

    J 1 Reply Last reply
    0
    • J Jason Hooper

      goto[^] I've only used goto once before as a professional and ended up removing it a few minutes later when I figured out a different way. Sometimes though for simplicity it just makes sense. I think I'll leave it! Anyone who thinks this code should not be checked in, speak now or forever hold your concurrency locks.

      Jason

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

      Sometimes things like that can be handled by placing the code in a method.

      If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
      You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun

      1 Reply Last reply
      0
      • L lewax00

        I feel like wrapping the rest of the code (up to "end") in an else block should cover that, why complicate it with uncommon syntax?

        J Offline
        J Offline
        Jason Hooper
        wrote on last edited by
        #7

        In any decision where I have two blocks of code that are functionally equivalent but one is more nested than the other, I will pick the less nested version. Fewer braces overall in the code.

        Jason

        L 1 Reply Last reply
        0
        • S Slacker007

          I'm sure the goto bit needs to be debugged. Just saying.

          "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
          "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

          V Offline
          V Offline
          Vasily Tserekh
          wrote on last edited by
          #8

          int ASMcontarpalabras(char * texto, int text_size,char * palabra, int pal_size)
          {
          asm
          {
          mov [ebp-4],0 // suma total
          mov [ebp-8],'v' // dice si es inicio de palabra (v o f)
          mov esi,[ebp+8] // texto
          mov edx,[ebp+12] // tamaño del texto
          mov edi,[ebp+16] // palabra
          mov ecx,[ebp+20] // tamaño de la palabra
          mov ebx,-1 // contador del texto
          xor eax,eax // toma las letras del texto y la palabras en al y ah
          mov [esi+edx],' ' // pone al final del texto y la palabra un
          mov [edi+ecx],' ' // caracter en blanco
          inc edx

          main_ciclo: inc ebx
          cmp ebx,edx
          je salir
          mov al,esi[ebx] // mueve a al un caracter del texto
          cmp al,32 // chequea si es un espacio
          je continuar2
          cmp [ebp-8],'f' // chequea si es inicio de palabra
          je continuar1 // si no salta a continuar1
          mov ah,[edi] //mueve a ah la primera letra
          cmp al,ah
          je comparar
          jmp continuar1

          //*************
          comparar: push ecx
          push ebx
          mov ecx,2
          inc ebx // para comparar con la segunda letra

           ciclo:  mov al,esi\[ebx\]   //texto
                   mov ah,edi\[ecx-1\] //palabra
                   inc ebx
                   inc ecx
                   cmp al,32         //chequea si se acabo la palabra en el texto
                   je check1:
                   cmp ah,32         //chequea si se acabo la palabra
                   je  salir\_dif
                   cmp al,ah
                   je ciclo
                   jmp salir\_dif
          
           check1: cmp ah,32          //chequea si las palabras son iguales
                   je check2
                   jmp salir\_dif
          
           check2: sub ebx,ecx        //chequea si tienen igual longitud
                   cmp ebx,0
                   jl salir\_igual
                   xor ecx,ecx
                   mov cl,esi\[ebx\]
                   cmp cl,32
                   je salir\_igual
                   jmp salir\_dif
          

          salir_igual: inc [ebp-4] //encontro una palabra
          pop ebx
          cmp ebx,edx
          je salir_fin // sale si es igual
          pop ecx
          jmp main_ciclo

          salir_dif: pop ebx // ...si es diferente
          pop ecx
          jmp main_ciclo

          salir_fin: pop ecx // ...si se acabo el texto
          pop ebx

          T L 2 Replies Last reply
          0
          • V Vasily Tserekh

            int ASMcontarpalabras(char * texto, int text_size,char * palabra, int pal_size)
            {
            asm
            {
            mov [ebp-4],0 // suma total
            mov [ebp-8],'v' // dice si es inicio de palabra (v o f)
            mov esi,[ebp+8] // texto
            mov edx,[ebp+12] // tamaño del texto
            mov edi,[ebp+16] // palabra
            mov ecx,[ebp+20] // tamaño de la palabra
            mov ebx,-1 // contador del texto
            xor eax,eax // toma las letras del texto y la palabras en al y ah
            mov [esi+edx],' ' // pone al final del texto y la palabra un
            mov [edi+ecx],' ' // caracter en blanco
            inc edx

            main_ciclo: inc ebx
            cmp ebx,edx
            je salir
            mov al,esi[ebx] // mueve a al un caracter del texto
            cmp al,32 // chequea si es un espacio
            je continuar2
            cmp [ebp-8],'f' // chequea si es inicio de palabra
            je continuar1 // si no salta a continuar1
            mov ah,[edi] //mueve a ah la primera letra
            cmp al,ah
            je comparar
            jmp continuar1

            //*************
            comparar: push ecx
            push ebx
            mov ecx,2
            inc ebx // para comparar con la segunda letra

             ciclo:  mov al,esi\[ebx\]   //texto
                     mov ah,edi\[ecx-1\] //palabra
                     inc ebx
                     inc ecx
                     cmp al,32         //chequea si se acabo la palabra en el texto
                     je check1:
                     cmp ah,32         //chequea si se acabo la palabra
                     je  salir\_dif
                     cmp al,ah
                     je ciclo
                     jmp salir\_dif
            
             check1: cmp ah,32          //chequea si las palabras son iguales
                     je check2
                     jmp salir\_dif
            
             check2: sub ebx,ecx        //chequea si tienen igual longitud
                     cmp ebx,0
                     jl salir\_igual
                     xor ecx,ecx
                     mov cl,esi\[ebx\]
                     cmp cl,32
                     je salir\_igual
                     jmp salir\_dif
            

            salir_igual: inc [ebp-4] //encontro una palabra
            pop ebx
            cmp ebx,edx
            je salir_fin // sale si es igual
            pop ecx
            jmp main_ciclo

            salir_dif: pop ebx // ...si es diferente
            pop ecx
            jmp main_ciclo

            salir_fin: pop ecx // ...si se acabo el texto
            pop ebx

            T Offline
            T Offline
            Tom Clement
            wrote on last edited by
            #9

            I'm pretty confident that the use of "goto" in assembler is de rigueur. :)

            Tom Clement Serena Software, Inc. www.serena.com articles[^]

            1 Reply Last reply
            0
            • J Jason Hooper

              goto[^] I've only used goto once before as a professional and ended up removing it a few minutes later when I figured out a different way. Sometimes though for simplicity it just makes sense. I think I'll leave it! Anyone who thinks this code should not be checked in, speak now or forever hold your concurrency locks.

              Jason

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #10

              I use return while having those ifs in a separate validation method. Goto is really not professional.

              1 Reply Last reply
              0
              • V Vasily Tserekh

                int ASMcontarpalabras(char * texto, int text_size,char * palabra, int pal_size)
                {
                asm
                {
                mov [ebp-4],0 // suma total
                mov [ebp-8],'v' // dice si es inicio de palabra (v o f)
                mov esi,[ebp+8] // texto
                mov edx,[ebp+12] // tamaño del texto
                mov edi,[ebp+16] // palabra
                mov ecx,[ebp+20] // tamaño de la palabra
                mov ebx,-1 // contador del texto
                xor eax,eax // toma las letras del texto y la palabras en al y ah
                mov [esi+edx],' ' // pone al final del texto y la palabra un
                mov [edi+ecx],' ' // caracter en blanco
                inc edx

                main_ciclo: inc ebx
                cmp ebx,edx
                je salir
                mov al,esi[ebx] // mueve a al un caracter del texto
                cmp al,32 // chequea si es un espacio
                je continuar2
                cmp [ebp-8],'f' // chequea si es inicio de palabra
                je continuar1 // si no salta a continuar1
                mov ah,[edi] //mueve a ah la primera letra
                cmp al,ah
                je comparar
                jmp continuar1

                //*************
                comparar: push ecx
                push ebx
                mov ecx,2
                inc ebx // para comparar con la segunda letra

                 ciclo:  mov al,esi\[ebx\]   //texto
                         mov ah,edi\[ecx-1\] //palabra
                         inc ebx
                         inc ecx
                         cmp al,32         //chequea si se acabo la palabra en el texto
                         je check1:
                         cmp ah,32         //chequea si se acabo la palabra
                         je  salir\_dif
                         cmp al,ah
                         je ciclo
                         jmp salir\_dif
                
                 check1: cmp ah,32          //chequea si las palabras son iguales
                         je check2
                         jmp salir\_dif
                
                 check2: sub ebx,ecx        //chequea si tienen igual longitud
                         cmp ebx,0
                         jl salir\_igual
                         xor ecx,ecx
                         mov cl,esi\[ebx\]
                         cmp cl,32
                         je salir\_igual
                         jmp salir\_dif
                

                salir_igual: inc [ebp-4] //encontro una palabra
                pop ebx
                cmp ebx,edx
                je salir_fin // sale si es igual
                pop ecx
                jmp main_ciclo

                salir_dif: pop ebx // ...si es diferente
                pop ecx
                jmp main_ciclo

                salir_fin: pop ecx // ...si se acabo el texto
                pop ebx

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #11

                Protip: on codeproject je is not coloured, but jz is.

                D 1 Reply Last reply
                0
                • J Jason Hooper

                  goto[^] I've only used goto once before as a professional and ended up removing it a few minutes later when I figured out a different way. Sometimes though for simplicity it just makes sense. I think I'll leave it! Anyone who thinks this code should not be checked in, speak now or forever hold your concurrency locks.

                  Jason

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #12

                  I think your Coder Card is a forgery. :-D

                  1 Reply Last reply
                  0
                  • J Jason Hooper

                    In any decision where I have two blocks of code that are functionally equivalent but one is more nested than the other, I will pick the less nested version. Fewer braces overall in the code.

                    Jason

                    L Offline
                    L Offline
                    lewax00
                    wrote on last edited by
                    #13

                    In general I'd agree, but if the alternative is duplicate code or a goto then I can't see the justification. Ignoring the argument of the appropriateness of goto, it is less readable even if its only because its so rarely used.

                    1 Reply Last reply
                    0
                    • J Jason Hooper

                      goto[^] I've only used goto once before as a professional and ended up removing it a few minutes later when I figured out a different way. Sometimes though for simplicity it just makes sense. I think I'll leave it! Anyone who thinks this code should not be checked in, speak now or forever hold your concurrency locks.

                      Jason

                      RaviBeeR Offline
                      RaviBeeR Offline
                      RaviBee
                      wrote on last edited by
                      #14

                      goto the end of a block is perfectly admissible.  break, continue and return do exactly this. /ravi

                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                      1 Reply Last reply
                      0
                      • J Jason Hooper

                        goto[^] I've only used goto once before as a professional and ended up removing it a few minutes later when I figured out a different way. Sometimes though for simplicity it just makes sense. I think I'll leave it! Anyone who thinks this code should not be checked in, speak now or forever hold your concurrency locks.

                        Jason

                        M Offline
                        M Offline
                        Mycroft Holmes
                        wrote on last edited by
                        #15

                        1991 was the last time I used GOTO, and I was not a professional then X|

                        Never underestimate the power of human stupidity RAH

                        1 Reply Last reply
                        0
                        • J Jason Hooper

                          goto[^] I've only used goto once before as a professional and ended up removing it a few minutes later when I figured out a different way. Sometimes though for simplicity it just makes sense. I think I'll leave it! Anyone who thinks this code should not be checked in, speak now or forever hold your concurrency locks.

                          Jason

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

                          Jason Hooper wrote:

                          used goto ... as a professional

                          I have, but in scripts (e.g. DCL and BAT files), not in proper programming languages. Except for VAX BASIC, but maybe that stretches the definition of "proper programming language". :~

                          1 Reply Last reply
                          0
                          • L Lost User

                            Protip: on codeproject je is not coloured, but jz is.

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

                            Protip; bugs should be reported[^] bug forum instead of on the lounge.

                            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging 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

                            L 1 Reply Last reply
                            0
                            • D Dan Neely

                              Protip; bugs should be reported[^] bug forum instead of on the lounge.

                              Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging 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

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #18

                              Fair enough. Of course it was me who supplied the list in the first place, so it's really my fault :laugh: There was a limit on how many instructions could be coloured, and I figured, well, they're really the same instruction anyway.

                              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