karthikeya kumar wrote:Can I know why is "goto" keyword considered under unused keyword
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
karthikeya kumar wrote:Can I know why is "goto" keyword considered under unused keyword
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Les Morgan wrote:"goto" has been, for at least the last 25+ years been considered used in very sloppy programming.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Les Morgan wrote:"goto" has been, for at least the last 25+ years been considered used in very sloppy programming.
While I agree with you in general, several eminent experts - including Donald Knuth - do not.
There is also a fairly widely used algorithm that still uses it, because it makes the code optimally small and (according to the designers) easier to understand.
Winston
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
There are three kinds of actuaries: those who can count, and those who can't.
But aren't most such parsers created by automatic tools? Remember that code from automatic tools is exempt from all style conventions, so GOTO is probably permissible there. The Java® Language Specification (=JLS) saysWinston Gutkowski wrote:. . . There is also a fairly widely used algorithm that still uses it, . . .
The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.
This means that Bertrand Meyer was right to say in Object‑Oriented Sofware Construction that labelled break is a surrogate for goto.Kernighan and Ritchie, the C Programming Language, page 65 wrote:C provides the infinitely‑abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used got in this book.
Nevertheless, there are a fwe situations where goto may find a place. The most common is to abandon processing in some deeply nested structure, such as breaking out of two or more loops at once. The break statement cannot be used directly since it only exits from the innermost loop. ...
Piet Souris wrote:But the most frustrating is: a program that allows 100% spaghetti code is seen as 'industry standard' and no one is complaining. I mean excel (or more generally: spreadsheets).
...
at this very moment I'm staring at this monster:
...
Yet we must use excel.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Piet Souris wrote:
"goto" has been, for at least the last 25+ years been considered used in very sloppy programming.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:At the machine level, the only way to transfer control was to do some sort of branch (goto) operation.
When higher-level languages came along - stuff like FORTRAN and COBOL, they inherited that sort of mechanism.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Tim Holloway wrote:At the machine level, the only way to transfer control was to do some sort of branch (goto) operation.
When higher-level languages came along - stuff like FORTRAN and COBOL, they inherited that sort of mechanism.
However, even before that subroutines were always available, by pushing the return address onto a stack before jumping.
On balance, I agree with not allowing GOTOs; but the liberal in me still bristles at not being "trusted" to use them properly.
Winston
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Winston Gutkowski wrote:
Les Morgan wrote:"goto" has been, for at least the last 25+ years been considered used in very sloppy programming.
While I agree with you in general, several eminent experts - including Donald Knuth - do not.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:I also prefer to put labels on my loop break statements. Because I'm paranoid, not because I'm actually insane enough to want to break of of a multi-level loop
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:A break in a loop is a very common way to do things like find the index of the first/next item in a list/array that meets some sort of match criteria. You can't kludge the loop into premature termination by jamming the loop variable or you'll destroy the very information that you're looking for.
Tim Holloway wrote:IIRC, somewhere around Java 7 or Java 8, "for" statements did add a filtering criteria right in the loop statement itself.
Mike Simmons wrote:Can't help but take this as a challenge:
There are three kinds of actuaries: those who can count, and those who can't.
Tim Holloway wrote:A break in a loop is a very common way to do things like find the index of the first/next item in a list/array that meets some sort of match criteria.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Piet Souris wrote:But what about what we learned in our very first java lesson?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Ugh. I've never liked that style. Why not just:
?
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Piet Souris wrote:
Mike Simmons wrote:Can't help but take this as a challenge:
What does this method return when target is not found?
Les Morgan wrote:I've always liked to keep it to one exit point.]
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
What, so if you have a switch statement that could happily return a value from each case, you'll set that value to some internal variable and then break from each one just so you can have a single return statement?
Winston Gutkowski wrote:
I understand (most of) the reasons behind single returns, but I've never believed in slavish adherence to rules; and in the above case I reckon my code's clearer than yours;
I'm in a method that's looking for something; I've found it; so I return it...immediately...not in some other place because I'm not "allowed" to have more than one return statement.
But that's programming - and variety's the spice of life.
Winston
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Mike Simmons wrote:Ah, good point - it's 0; I meant it to be -1. OK...So, as before: it's possible, but not very clear.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Les Morgan wrote:BTW: if memory serves correct there was a Winston back over on the Sun sites before they became "Oracle", that still leaves a bad taste in my mouth to say, be you that same person?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:But "bad taste"? I hope I didn't offend you over there. If I did, it wasn't intentional.
Winston
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Winston Gutkowski wrote:
Am I missing something here?
Nop line 2 still is a candidate for NullPointerException. I know I know... nitpicking, you're not discussing that hereWinston Gutkowski wrote:And it'll return -1 whenever target isn't found - including when array has 0 elements.
Liutauras Vilda wrote:Nop line 2 still is a candidate for NullPointerException. I know I know... nitpicking, you're not discussing that here
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Les Morgan wrote:
I see names from the "old guys" that were there back in the day, just nice to run across bits of familiarity here and there.
Winston Gutkowski wrote:However, there are two ways (at least) to do that:
1. Check for null explicitly and throw an exception.
2. Use the object immediately (and, of course, document that your method throws NPE).
The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.
Winston Gutkowski wrote:
I'm proud to say, I have never used a label, or a break statement in a loop, in any Java program I've ever written.
Ajoy Bhatia wrote:
Why is goto kept as a reserved keyword? If the only reason is to "discourage its use", just do not have that as a Java keyword at all. The Java language spec would not mention anything about goto and no Java compiler would implement it. I think that would surely "discourage its use".
Ivan Jozsef Balazs wrote:You should not even think of using this four letter word.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Consider Paul's rocket mass heater. |