CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835
    Okay, before this gets too heated, why not settle it with a poll?

    See my grand 'goto' poll thread.

  2. #17
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Originally posted by j0nas
    First, the semantics for goto:s are very clear. Secondly, it's a lot easier to follow a simple goto statement than 6 or 8 levels of indented code.
    This I definitly disagree with. Goto has less semantics than for, while and return. Gotos can be used to do every loop construct, return statement, breaking out of loops and ifs, etc. Basically, the essence of goto is that it can mean anything. If it means something in particular to you, fine, but don't be surprised if it means something completely different to somebody else.

    In my programs, I never have 8 levels of indentation, and I think it's not hard avoiding this without resorting to gotos.
    I understood that your "goto is evil"-statement wasn't directly quoted from Dijkstra's work. You have probably heard it in some stupid CS course. Probably when learning Pascal...
    No, I was in a conference he was holding in Eindhoven when somebody asked about the paper and his goto comment. He sort of joked that gotos were the worst thing anybody could have invented. But he still stood by his idea that goto was not a good idea.

    By the way, Pascal (at least TPP) also includes goto, so I wonder why it's cited as a 'goto-hater' language.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  3. #18
    Join Date
    Feb 2004
    Posts
    138
    I have a question, please help me...
    Are goto in structured programming languages and Jump in Assembly the same ?
    If I use goto in my application, and I debug to see its Assembly machine code, does it look like Jump ???
    I ask this because in Assembly as I just learnt, the while/for loop is just represented by Jump and if we want to go to somewhere, we just keep jumping in and then if the condition is not satisfied, we jump out...That s why I wonder...

    I dont know how to debug to see program machine code, i dont know, true ! Would you please do that and answer my questions ? Can you also teach me how to debug my program to see its assemply code (I am dumb, so, please tell me from scratch if you think you like to do that for me as a favor)

    Thanks so very much....

  4. #19
    Join Date
    Feb 2004
    Posts
    138
    Originally posted by John E
    Okay, before this gets too heated, why not settle it with a poll?

    See my grand 'goto' poll thread.
    Please donot misunderstand, I ask in this thread because my questions have no relations to your poll, but I did vote for REGULARLY USE GOTO(though I actually ALWAYS use it) because I want to finish my program as soon as possible....No matter how the end will be...
    Last edited by Charleston; February 16th, 2004 at 01:42 AM.

  5. #20
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835
    Originally posted by Charleston
    If I use goto in my application, and I debug to see its Assembly machine code, does it look like Jump ???
    I'm not an expert in Assembler but I'd assume that a goto instruction would be implemented via a 'jmp' in the majority of cases.
    Originally posted by Charleston
    Are goto in structured programming languages and Jump in Assembly the same ?
    No, not really. 'jmp' can be used with other high level instructions, apart from 'goto'. For example, loops can use 'jmp' as you've already noticed. In fact, even functions are sometimes called using the 'jmp' statement, as opposed to 'call'.

  6. #21
    Join Date
    Nov 2003
    Posts
    1,405
    Originally posted by Charleston
    Are goto in structured programming languages and Jump in Assembly the same ?
    If I use goto in my application, and I debug to see its Assembly machine code, does it look like Jump ???
    Structured programming is language independent. The idea is that you impose on yourself to only use certain control structures with special properties. In assembly language you certainly will need to use jumps to implement those control structures, for example the if-then-else. In a high level language you wont because the if-then-else is part of the language. The conclussion is that high level languages support structured programming better than assembly. In assembly language you'll have to see to it yourself that you follow the principles of structured programming

    So it's not jumping in itself that's considered bad. It's the undiciplined, unrestriced jumping all over the place that makes the program complex and thereby error-prone.
    I dont know how to debug to see program machine code, i dont know, true ! Would you please do that and answer my questions ? Can you also teach me how to debug my program to see its assemply code (I am dumb, so, please tell me from scratch if you think you like to do that for me as a favor)
    This is not a language question. It's a compiler/debugger specific question. Ask this question at a compiler oriented forum.

  7. #22
    Join Date
    Feb 2004
    Posts
    138

    Smile

    Thanks John and uj alot..

    _uj, I will follow your advice... True,

  8. #23
    Join Date
    Feb 2004
    Posts
    81
    As far as the language is concerned, right use of gotos is OK but when it comes to code readibility and maintenance, gotos are worst programming structure to use. In my opinion gotos are only usefull for machine generated code. In all other situations, their use should be avoided.
    Last edited by ferox; February 16th, 2004 at 04:43 AM.
    while(true)
    cout<<"C++ is divine\n";

    Feroz Zahid

  9. #24
    Join Date
    Aug 2002
    Posts
    78
    Originally posted by j0nas
    There's nothing wrong with using GOTOs--if used with care. I’m getting fed up on why always academic people complain about it.
    It seems to be half Ivory Tower talking, cut off from the real world, and half '60's assembly programmer leftover talking about their old problems.

    In some languages, like pre-Visual Basic (no block structure or true function definitions) GOTO's were the only way to go, and it was hard to maintain things correctly. You formed your if-then-else by using GOTO as jump points.

    It's quite reasonable for complex code to do something like this:

    Code:
    (Open file)
    
    (Work with file)
    Many such tests as
    if (some problem)
        goto CLOSE_FILE_AND_EXIT;
    
    blah blah blah
    
    if (some problem #73)
        goto CLOSE_FILE_AND_EXIT;
    
    blah blah blah
    
    CLOSE_FILE_AND_EXIT:
    if (file is open)
         (close file);


    If you can't do this, then you have to embedd clunky closes and returns everywhere, or have some method of setting a variable to bail out of code after the error is detected. This can get VERY ugly in non-trivial, real world cases.



    C++ should have implemented LISP's "unwind-protect" operator for just such a situation. It allows you to specify a chunk of code to execute if anything called within the unwind-protect bails out for any reason (error thrown, return, etc.) In fact, C++'s try/throw/catch refuse seems to ape this poorly.


    Actually, LISP should have been the language of the Internet, not Java, but that's another religious battle for another day...

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured