1. with entry and goto statement
- Posted by mexzony Dec 31, 2010
- 1741 views
did not quite get the explanation of the entry statement.
public function find_all ( object x, sequence source , integer from ) sequence ret = {} while from > 0 with entry do ret &= from from += 1 entry from = find_from (x, source , from ) end while return ret end function
also why no example for the goto statement.for beginners like me reading a lot of english can be boring.i mean a practical example in the explanation well explained is kind of better.i did expect it in some explanations cos to be honest sometimes the things explained can be confusing.i have to practically take a sheet of paper and try to practise on my own to get the concept.nevertheless i have to say its a very good manual cos so far i get almost all the explanations.this is just my view anyway.you know taking it from a more practical approach.i really wanna learn this language and do something with it.thanks guys
2. Re: with entry and goto statement
- Posted by petelomax Dec 31, 2010
- 1730 views
also why no example for the goto statement.
There shouldn't be an example. As a beginner, you should consider the goto statement as pure evil, something you use once-in-a-decade, when you really have no other choice. If you have a block of code that you need to invoke from several places, put it in a subroutine.
Regards, Pete
3. Re: with entry and goto statement
- Posted by Vinoba Dec 31, 2010
- 1714 views
also why no example for the goto statement.
There shouldn't be an example. As a beginner, you should consider the goto statement as pure evil, something you use once-in-a-decade, when you really have no other choice. If you have a block of code that you need to invoke from several places, put it in a subroutine.
Regards, Pete
I know it is the current fashion amongst all developers to bash the GOTO statement. It is undesirable to do so.
Let me be precise. There is unjustified abhorrence of GOTO and many other features which are direct descendants of CPU behavior (as seen in Assembler). Jump Relative, Jump Conditional and Jump Absolute are the cornerstone of writing in Assembler. Their cousins, Call Relative, Call Absolute and Call Conditional are seen in the GOSUB statement.
It is a matter of great surprise that we accept all the implied GOTOs within IF-THEN-ELSE and even Exits from this and DO-WHILE loops and frown upon GPTOs created by the program writer.
Funnily when we write an Application for the end user we give the End User ALL the facility of GOTO and GOSUB, by allowing him to branch out to any part of application and return or not return at the user's own choosing! It seems that Application users are very comfortable working with these facilities which the compiler writer is denying to the sophisticated Application developer.
4. Re: with entry and goto statement
- Posted by jeremy (admin) Dec 31, 2010
- 1703 views
I know it is the current fashion amongst all developers to bash the GOTO statement. It is undesirable to do so.
Let me be precise. There is unjustified abhorrence of GOTO and many other features which are direct descendants of CPU behavior (as seen in Assembler). Jump Relative, Jump Conditional and Jump Absolute are the cornerstone of writing in Assembler. Their cousins, Call Relative, Call Absolute and Call Conditional are seen in the GOSUB statement.
It is a matter of great surprise that we accept all the implied GOTOs within IF-THEN-ELSE and even Exits from this and DO-WHILE loops and frown upon GPTOs created by the program writer.
Funnily when we write an Application for the end user we give the End User ALL the facility of GOTO and GOSUB, by allowing him to branch out to any part of application and return or not return at the user's own choosing! It seems that Application users are very comfortable working with these facilities which the compiler writer is denying to the sophisticated Application developer.
I'm with you 100%. GOTO is a very valid and powerful tool that should be used much more than it currently is. It can greatly simplify code make it more clean, easier to maintain and easier to understand. However, as programmers in todays age we have been "programmed" to think it's a terrible evil. This is not true.
When reading the history of GOTO, the first paper published against it was when languages used almost ALL goto's for EVERY loop construct. No way I would program like that today. We have, now, nice loops such as for, while and loop. We have if blocks instead of a single if X goto Y statment, etc... GOTO certainly should not be used for every jump that exists but goto is far from evil. It's beautiful!
What I see as worse than goto is returning from a function in 5 different places on error conditions or deeply nesting if statments checking for these error conditions so you can have only one exit point and not have to use goto. This is evil. Goto can be used and should be used in such situations. Code will, again, be much more readable, concise, understandable and maintainable.
People should not be afraid of goto. People should not replace if, while, loop, for with a goto. People should not have a hundred exit points from their functions. People should not break their functions into illogical blocks to avoid a goto. The Euphoria standard library uses goto in a few well placed situations. All of your translated applications use goto. There are many valid uses. I just posted a message about Best Practices, I think some valid examples of goto should be placed there to help everyone decide when to and when not to use goto. But to say it's evil is incorrect in my book. Now, global? That's another story global is evil (in most situations ) but even it has a place ;-D
Jeremy
5. Re: with entry and goto statement
- Posted by jeremy (admin) Dec 31, 2010
- 1684 views
did not quite get the explanation of the entry statement.
public function find_all ( object x, sequence source , integer from ) sequence ret = {} while from > 0 with entry do ret &= from from += 1 entry from = find_from (x, source , from ) end while return ret end function
With entry causes the while loop to skip its initial check (in this case from > 0) and jump directly to the entry statement on its first execution only. So, in this case the loop first executes from = find_from(x, source, from) before doing any condition check and before doing the ret &= from and from += 1 lines. This loop could be rewritten (for demo purposes) as:
from = find_from(x, source, from) while from > 0 do ret &= from from += 1 from = find_from(x, source, from) end while
See how the with entry in this case eliminated the duplicate "initialization" code? In this case the "initialization" code and the "increment" code are the same, so a with entry makes sense as to remove the duplication.
Does that clear it up any?
Jeremy
6. Re: with entry and goto statement
- Posted by jeremy (admin) Dec 31, 2010
- 1628 views
I just stumbled across this thread from Linus Torvalds:
From: Linus Torvalds Subject: Re: any chance of 2.6.0-test*? Date: Sun, 12 Jan 2003 12:22:26 -0800 (PST) On Sun, 12 Jan 2003, Rob Wilkens wrote: > > However, I have always been taught, and have always believed that > "goto"s are inherently evil. They are the creators of spaghetti code No, you've been brainwashed by CS people who thought that Niklaus Wirth actually knew what he was talking about. He didn't. He doesn't have a frigging clue. > (you start reading through the code to understand it (months or years > after its written), and suddenly you jump to somewhere totally > unrelated, and then jump somewhere else backwards, and it all gets ugly > quickly). This makes later debugging of code total hell. Any if-statement is a goto. As are all structured loops. And sometimes structure is good. When it's good, you should use it. And sometimes structure is _bad_, and gets into the way, and using a "goto" is just much clearer. For example, it is quite common to have conditionals THAT DO NOT NEST. In which case you have two possibilities - use goto, and be happy, since it doesn't enforce nesting This makes the code _more_ readable, since the code just does what the algorithm says it should do. - duplicate the code, and rewrite it in a nesting form so that you can use the structured jumps. This often makes the code much LESS readable, harder to maintain, and bigger. The Pascal language is a prime example of the latter problem. Because it doesn't have a "break" statement, loops in (traditional) Pascal end up often looking like total shit, because you have to add totally arbitrary logic to say "I'm done now". Linus
7. Re: with entry and goto statement
- Posted by JoKeR Dec 31, 2010
- 1660 views
I learned to program in the '70s using Pascal and learned all about the evils of the GOTO statement.
While I can understand that people don't like to use "I'm done" type tests, I'm still not completely comfortable with break commands because they sometimes seem ambiguous. Off the top of my head I'm going to try some bogus code to try to point to some possible confusion with break statements.
while condition1 do if condition2 then break for 1 to 100 do if condition3 then break while condition4 do if condition5 then break end while if condition6 then break end for if condition7 then break end while
Do all of these break to the end of the innermost loop construct it is within? This would mean that breaking on condition3 or condition6 would jump to the end of the for loop and breaking on either condition2 or condition7 would jump to the end of the outer while loop.
What if I want to break to the end of the outer while loop on condition5? Are there loop labels for identifying which loop construct is being broken out of? For instance, could I label the outer while loop as OuterW and then break to OuterW from anywhere within the while's code regardless of what other looping I might be doing within the while loop?
I've used Euphoria just for fun (see my JoKoSoKo game) and haven't yet tried it with the newly released version (though I do have it working with a beta version, so I assume that it should not need much if any mods to work with the public release). Maybe these concerns are addressed and I just haven't looked at the manual enough to recognize it.
I appreciate all of the hard work done by the people supporting Euphoria and look forward to continuing to use it. I'm thinking of trying to rewrite my game using wxWindows (I think that's what I've seen referred to) instead of Win32Lib so that I could have it available for both Windows and Linux.
8. Re: with entry and goto statement
- Posted by jeremy (admin) Dec 31, 2010
- 1619 views
... break and loops ...
<snip>
Euphoria is amongst the best (dare I say) with this. I think by break, you mean exit. exit alone always exits from the containing loop. You can, however, have labels:
while 1 label "for-ever" do for i = 1 to length(families) label "each-family" do sequence children = families[i][CHILDREN] for j = 1 to length(children) label "each-child" do if equal(children[j][NAME], "John Doe") then exit -- exits the containing loop, 'each-child' elsif equal(children[j][NAME], "Jane Doe") then exit "each-family" -- exits from the 'each-family' loop elsif equal(children[j][NAME], "Jeff Doe") then exit "for-ever" -- exit all three loops end if end for end for end while
Now, as you say, poorly written, break, exit, continue and retry can all make some terrible code. They are powerful when used correctly and a virtual disaster when poorly written.
Jeremy
9. Re: with entry and goto statement
- Posted by JoKeR Dec 31, 2010
- 1643 views
Thanks for the explanation, Jeremy. That really is a sensible way for such a construct to work.
10. Re: with entry and goto statement
- Posted by jaygade Dec 31, 2010
- 1658 views
I know it is the current fashion amongst all developers to bash the GOTO statement. It is undesirable to do so.
Let me be precise. There is unjustified abhorrence of GOTO and many other features which are direct descendants of CPU behavior (as seen in Assembler). Jump Relative, Jump Conditional and Jump Absolute are the cornerstone of writing in Assembler. Their cousins, Call Relative, Call Absolute and Call Conditional are seen in the GOSUB statement.
Because we aren't programming in machine language or assembler. We're programming at a higher level with better abstractions, abstractions which should hopefully be clearer.
It is a matter of great surprise that we accept all the implied GOTOs within IF-THEN-ELSE and even Exits from this and DO-WHILE loops and frown upon GPTOs created by the program writer.
Which is the abstraction. You know exactly where the program will branch and you do not end up with spaghetti code.
Back when I first started programming in BASIC, GOTO and GOSUB were all there was. There wasn't even an "ELSE" clause. And we had to use line numbers instead of labels, which are themselves an abstraction.
Funnily when we write an Application for the end user we give the End User ALL the facility of GOTO and GOSUB, by allowing him to branch out to any part of application and return or not return at the user's own choosing! It seems that Application users are very comfortable working with these facilities which the compiler writer is denying to the sophisticated Application developer.
Okay. And? That's like apples and oranges. Or apples and bowling balls, rather.
11. Re: with entry and goto statement
- Posted by petelomax Dec 31, 2010
- 1595 views
and you do not end up with spaghetti code.
Yeah, that's the point - *a single* goto can be quite elegant, but 37 overlapping and interweaving gotos cannot.
We must disuade newbie programmers from adopting goto as a weapon of choice.
Pete
12. Re: with entry and goto statement
- Posted by jeremy (admin) Jan 01, 2011
- 1564 views
We must disuade newbie programmers from adopting goto as a weapon of choice.
Indeed, but not to the point of those who came before us and made a whole crop of programmers who are so afraid of goto they cease to use a language or a library that has or uses a goto statement. goto is a very valid, powerful and elegant solution in quite a few cases once you understand its proper use.
Jeremy
13. Re: with entry and goto statement
- Posted by Vinoba Jan 01, 2011
- 1570 views
[/quote]Okay. And? That's like apples and oranges. Or apples and bowling balls, rather. [/quote]
Yes. We toss a lot of balls and bunch of grapes all over a Microsoft window and desktop, give the novice application user about 50-100 actions. He can choose any, come back or never come back, give him all kinds of options to go on a world trip and leave home (site) sometimes forgetting where his journey started. We call this a good application program and good software that can "do a lot things". Yet we shudder at a reasonably good application programmer using about 20 GOTOs in his work. Why? because the writer of Basic, or similar language could not give the application programmer a guarantee to be able to look after him.
Why so? Because we use C language. I just compiled one program (in another (higher) language - not euphoria). It did not compile under One C compiler. It compiled well in another but would not run, and compiled in a third and it runs so far.
Happy New year to everybody.
14. Re: with entry and goto statement
- Posted by jaygade Jan 01, 2011
- 1569 views
Users are not the same as programmers. Programs perform a specific task. Users are much more freeform in their actions.
I just don't see the comparison.
15. Re: with entry and goto statement
- Posted by irv Jan 01, 2011
- 1535 views
I think there is only one "goto" in a well-written user interface, and that is to goto the exit (file-quit). Everything else is more like a procedure or function. If that were not so, the program would be unusable.
16. Re: with entry and goto statement
- Posted by Vinoba Jan 01, 2011
- 1503 views
Users are not the same as programmers. Programs perform a specific task. Users are much more freeform in their actions.
I just don't see the comparison.
Contradictions in your statements abound. If one accepts that programmers have MORE knowledge of the tools they are using than End Users, and then accept your argument that users need a lot of freedom in their actions, which we often successfully endeavor to give then it is fair conclusion to accept that we, the programmers, have even better ability to do our "GOTOs" than the end user has.
How can we, the application programmers, give a thousand GOTOs to our end users in a program WHICH THEY DID NOT CREATE THEMSELVES, when we ourselves don't have the ability to navigate though a program of our own creation? If they have the ability to navigate through an unknown program, we, with better abilities than them, should have the ability to navigate though a program of our own creation.
Anyway, this discussion is not leading us anywhere. So Happy New year to you and your family. Happy programming with version 4.0.
17. Re: with entry and goto statement
- Posted by useless Jan 01, 2011
- 1523 views
I think there is only one "goto" in a well-written user interface, and that is to goto the exit (file-quit). Everything else is more like a procedure or function. If that were not so, the program would be unusable.
LOL
useless
18. Re: with entry and goto statement
- Posted by jaygade Jan 01, 2011
- 1429 views
How can we, the application programmers, give a thousand GOTOs to our end users in a program WHICH THEY DID NOT CREATE THEMSELVES, when we ourselves don't have the ability to navigate though a program of our own creation? If they have the ability to navigate through an unknown program, we, with better abilities than them, should have the ability to navigate though a program of our own creation.
Because we do not. Every action by the user, either at the command line or even at the gui, is more akin to a function or procedure call than to a lowly goto. It is only a goto at the lowest, least abstract level.
19. Re: with entry and goto statement
- Posted by irv Jan 02, 2011
- 1520 views
How can we, the application programmers, give a thousand GOTOs to our end users in a program WHICH THEY DID NOT CREATE THEMSELVES, when we ourselves don't have the ability to navigate though a program of our own creation? If they have the ability to navigate through an unknown program, we, with better abilities than them, should have the ability to navigate though a program of our own creation.
It this is true, there would have to be a corresponding "come-from".
Without a "come-from", just about every program would be dead in the water the first time the user did anything.
Take for example notepad.exe. Without a come-from, the first time you pressed a key, and the character was displayed on the screen, you'd be at a dead end, unable to enter more characters.
20. Re: with entry and goto statement
- Posted by bill Jan 08, 2011
- 1344 views
name them
That is Jeremy, specify the places in a program where goto is necessary. I think it is where you need a bail out clause. Is this what you are referring to? Or do you have a another use?