People who know about (unstructured) goto have a better understanding of the way computers actually work. You have to outgrow goto, but it's not wrong to know goto.
Gotos should always be used when cleaning up code that acquires resources but doesn't free them right away. I would fail anyone in a code review who tried to do the following with nested ifs. Nesting would makes the code unmaintainable.
if (get resource A == fail) goto end
if (get resource B == fail) goto free A
if (get resource C == fail) goto free B
do something useful, set initialization to true, return
free B: free resource B
free A: free resource A
end:
Gotos should always be used when cleaning up code that acquires resources but doesn't free them right away. I would fail anyone in a code review who tried to do the following with nested ifs. Nesting would makes the code unmaintainable.
As an amateur and not professional programmer, why is that?
I would have used nested ifs, which would follow the same process and cleanup your example code did, but I don't see how it is any more or less maintainable. I'm pretty sure it's basically the same number of lines of code, excepting the fact I like to put my closing brackets on their own line, so adding 2-3
Is that what you mean by unmaintainable?
I'm also a bit confused by that 'return' after the do something useful. Is all of your psudocode in its own
As an amateur and not professional programmer, why is that?
I would have used nested ifs, which would follow the same process and cleanup your example code did, but I don't see how it is any more or less maintainable.
Heavily nested code contributes to Cyclomatic Complexity [wikipedia.org], which makes it difficult for programmers (even the ones that wrote it) to understand what is happening and thus contributes to errors.
While you are right about heavily nested code, the same apply to heavily "gotoed" code. Indeed it's a good attitude to measure the cyclomatic complexity. If you do that you'd notice that:
both codes (assuming they are in the same enclosing function) have the exact same CC. Objectively the goto version induces a higher burden on the developer because he or she has to name every labe
I think it was just a bad example. You could do it with nested ifs fine:
if (get resource A == success){
if (get resource B == success){
if (get resource C == success){
do something useful, set initialization to true
free resource C
}
free resource B
}
free resource A
}
Apologies if that's wrong, I rarely consider myself good at this stuff, but I understand the original complaint about nested ifs versus gotos. Because in most code using 3rd party
Both the JVM runtime machine and CLI have JMP and branch instructions. All assembler and pseudo-assembler language, which basically emulate a sort of CPU instruction set, are going to have those kinds of opcodes. The languages that compile to bytecode need to have such primitives. It's the way computers work. Error handlers, no matter how pretty they look in an uncompiled code, are really going to do jumps and branches to some memory location or routine, however obscured that may be.
If you write that kind of shitty code I assume you are a young and inexperienced developer. Because what you blindly wrote, and yet you managed to get it wrong, is the root of unmaintainable code that I call "GOTO FAIL". Haven't you heard of structured programming and functions ?
if (get_resource(A) == success) {
function_dealing_with_B_then_C();
free_resource(A); }
Resource A is valid within the scope of the brackets.
Are you recommending breaking it into four functions and passing a ton of arguments among them?
The first to allocate A, call the second, and free A The second to allocate B, call the third, and free B The third to allocate C, call the fourth, and free C The fourth to actually do any work
Many modern languages automatically produce the necessary "free resource" code and the necessary jumps as a side effect of the "get resource" code, so this is a poor example.
One place I have kept needing gotos is this sort of structure, except "f()" requires access to every single local variable in the surrounding code, and is also very very long (often about 90% of the code in the enclosing function):
I think it still can be unsafe if you have a larger code base with multiple developers contributing. Goto across modules impacts more than just your module. If goto is managed correctly and simply then it's very easy for developers to implement. You don't want to hear "why does the module have intermittent bugs" because of a couple of misplaced gotos. What you really want is a simple but effective policy that frees developers to use goto with minimal constraints or decision-criteria.
Sometimes goto is the simplest and cleanest solution.
Old BSD TCP/IP stacks had gotos in them. I saw them while implementing IPv6 in AIX back in the late '90s. I haven't looked at any BSD TCP/IP code for a long time, so maybe someone deep six'd them
And tcp_input.c had the best comment I have seen ever:
And behind the scenes, however you create error handlers in a modern programming language, underneath the hood there's going to need to be a JMP somewhere to jump to the exception routine. That modern languages make this seamless and largely invisible doesn't make the underlying concept go away.
Good grief. BASIC was inspired by COBOL and Fortran, both of which had GOTO statements. Not to mention here that assembly was a very common language at the time, and JMP and variants were all over the place. As ALGOL's descendants began to take over, all the old unstructured languages, including BASIC, began to adopt structured paradigms. But really, considering it was developed at a time when punch cards were a primary input method, it allowed non-programmers an easy on-ramp to coding, and if done well (us
Dartmouth Timesharing System was not a way for computers to share resources. You logged into it with a terminal. Your programs were running that that machine. It was a timesharing (sharing time - cycles - on a mainframe.)
That would simply print a bunch of zeroes. If you don't put the sentence to be printed between quotes it will be treated as a numerical variable. Kill yourself.
I actually prefer VBA or something like JMP or MATLIB. Yes, there are complex algorithms but most of the time you aren't implementing them. It's usually making a chart or querying a database and VBA is simpler and still retains enough nuance to get most code written, even if it's imprecise.
I'm an embedded C programmer but I loved Microsoft's visual basic for applications. It was such a handy tool for making simple user interfaces. Ugly but very functional and easy to maintain.
I don't particularly appreciate people looking down on BASIC. It isn't even worth the time to reply to remarks from people who probably don't know any language very well. BASIC an ideal language in so many ways.
In the 8 bit days, BASIC was the operating system. It would be pretty nightmarish to have a multitasking kernel that allowed programs to just go mucking around at any memory location they wanted. Not that most early multitasking operating systems prevented it, memory management was pretty limited in at least consumer grade operating systems, and such systems basically relied on the honor system. Preemptive kernels had to put more work into memory management, and pretty much all modern operating systems with
It's all fun and games when the highway department puts up that fancy new "1964 BASIC" highway marker, until some joker sneaks in late one night and puts up a "1965 GOTO 1964" marker a mile further down the road.
Most of us geeks started programming with some form of BASIC no matter how unfashionable it is to reveal. My sister started teaching me Basic on one of our Dad's many CP/M machines (he used to sell them - probably an SD System or a Kaypro or something, I can't remember) when I was 5 years old. Eventually I moved on to assembly and C and C++ etc. etc. but BASIC was where I started. I acknowledge it and I appreciate it for what it was. My Dad stuck with Basic and Visual Basic and provided an amazing childhood for
After the Old Man of the Mountain collapsed in 2003, NH lost its state icon, depicted on stamps and on the state quarter. So why not a rebranding for the coin?
10 REM NEW HAMPSHIRE 20 REM The BASIC State 30 LET ThisCoin = DOLLAR(1.0 / 4, 2)
Perhaps the article should be about Bill Gates coining the term "Software Piracy" because he was taking to long to release BASIC to the ALTAIR after so many had already paid for it? (today that amount of time raises legal issues)
>Why is Microsoft's name attached to this article?
Because Microsoft's BASIC is what most people in the world used. Long before Visual Basic, there were millions of users of Microsoft BASIC; more than any other software company's.
Did you ever use a Commodore machine (from the Commodore PET all the way to the 128 and some versions of the Amiga)? Then you used the BASIC [wikipedia.org] licensed from Microsoft. Or maybe you wrote some BASIC program on an Apple from the II+ onward? You used a BASIC [wikipedia.org] licensed from Microsoft. TRS-80, from 1977 onward [wikipedia.org]? Microsoft BASIC. Even Atari, who had their own BASIC sold Microsoft's BASIC as an upgrade. Heck, if you had an Altair 8800 [wikipedia.org], there was a BASIC from Microsoft available.
Wow, even Apple BASIC was licensed from MS too. I never knew that!:/
The story I'd heard was that, in the mid 80s, the Apple II was still selling decently well when its BASIC license was about to expire. So, Microsoft said, "hey Apple, about this whole Windows Look and Feel lawsuit"... which quickly went away...
The story I'd heard was that, in the mid 80s, the Apple II was still selling decently well when its BASIC license was about to expire. So, Microsoft said, "hey Apple, about this whole Windows Look and Feel lawsuit"... which quickly went away...
The story should maybe clarify how Microsoft managed in 1985 to convince Apple to get a BASIC license in 1977.
While Silicon Valley is over rated this NH thing is embarrassing. I say that as someone who lives here (NH that is). We have an amazing free software tech scene and 10s of thousands of techies moving here because of the Free State Project. This gimmick is embarrassing to those of us who put freedom first.
The Free State Project is far, far less popular that BASIC ever was. You're lucky if there are tens of techies moving here. We don't need newcomers coming to the state and then whining about it. Stay home, fix your own damn state.
Would you rather do this (BASIC): 10 PRINT "Hello, World"
or this (Java): public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello, World");
} }
Is this progress? Is it any wonder people find coding difficult to learn nowadays? I suspect coding is more daunting for beginners now than it was in the 1980s because of "advancements" like this.
BASIC is procedural, simplified assembly in a sense. Very linear, very close to the metal.
JAVA is an objective abstraction in comparison. Very non-linear, very far from the metal.
To say that one is better than the other is to discount the flaws and overvalue the features of either.
Anyone comparing programming languages and looking to name one "the best" has a poor understanding of the idea of "use the right tool for the right job" and are in effect arguing that the bike shed should be painted red.
NOWPRINT. NOWPRINT. Clemclone, back to the shadows again.
- The Firesign Theater
Fuck off. (Score:0)
The more I hear about "geekiness", the more I just want to fucking kill somebody. Fuck off.
Re: Fuck off. (Score:-1)
Agree. Libarts majors are not geeks. Basic is for n1ggers.
Low IQ & Conservative Beliefs (Score:0)
Low IQ & Conservative Beliefs Linked to Prejudice [livescience.com]
Thinking themselves wise, they became fools (Score:0)
For this reason, God sends them a powerful delusion(operation of wandering)(planet) so that they will believe the lie.
Mystery Red of the Great American Eclipse [gateway.serph.network]
It has blood on it! [hardbin.com]
ABCNews: Eclipse makes pendulum wander [archive.org]
Sound of Silence [hardbin.com] Losing my religion [hardbin.com]
Sun researchers find strange eclipse reading [hardbin.com]
COLLAGE GRAD? (Score:0)
https://apple.slashdot.org/comments.pl?sid=14094832&cid=58707462 = COLLAGE GRAD?
Re:COLLAGE GRAD? (Score:4, Funny)
A collage graduate is a person who took a bunch of fascinatingly miscellaneous courses but could never settle on a major.
Re: (Score:2)
Let me guess - then glued them together as art.
Most won't know what it means (Score:0)
So a geek will understand it, but the rest won't and that does nothing to expand interest in code.
Lisp (Score:1)
They named one for Lisp, but people kept getting lost in cul-de-sacs.
Re: (Score:2)
They named a toll road Comcast, and it keeps invoicing you even though you haven't driven on it for months.
Really? (Score:1)
Re: (Score:0)
People who know about (unstructured) goto have a better understanding of the way computers actually work. You have to outgrow goto, but it's not wrong to know goto.
Re: Really? (Score:0)
People learn basic, then they learn goto, then they decide for themselves if goto is a good practice, then they use goto
Really-Linus Torvalds (Score:0)
Linus would like a word with you.
https://koblents.com/Ches/Links/Month-Mar-2013/20-Using-Goto-in-Linux-Kernel-Code/
Re: (Score:2)
if (get resource A == fail) goto end
if (get resource B == fail) goto free A
if (get resource C == fail) goto free B
do something useful, set initialization to true, return
free B: free resource B
free A: free resource A
end:
I did learn something tod
Re: (Score:2)
Gotos should always be used when cleaning up code that acquires resources but doesn't free them right away. I would fail anyone in a code review who tried to do the following with nested ifs. Nesting would makes the code unmaintainable.
As an amateur and not professional programmer, why is that?
I would have used nested ifs, which would follow the same process and cleanup your example code did, but I don't see how it is any more or less maintainable.
I'm pretty sure it's basically the same number of lines of code, excepting the fact I like to put my closing brackets on their own line, so adding 2-3
Is that what you mean by unmaintainable?
I'm also a bit confused by that 'return' after the do something useful.
Is all of your psudocode in its own
Re: (Score:2)
He is an idiot, that is all.
Never mind him, if you want to work in the business, you easy find interview partners that are not so moronic.
Re: (Score:2)
As an amateur and not professional programmer, why is that?
I would have used nested ifs, which would follow the same process and cleanup your example code did, but I don't see how it is any more or less maintainable.
Heavily nested code contributes to Cyclomatic Complexity [wikipedia.org], which makes it difficult for programmers (even the ones that wrote it) to understand what is happening and thus contributes to errors.
Cyclomatic Complexity (Score:2)
While you are right about heavily nested code, the same apply to heavily "gotoed" code. Indeed it's a good attitude to measure the cyclomatic complexity. If you do that you'd notice that:
if (condition) /* path #1 */ /* path #2 */
{
}
else
{
}
and:
if (condition) goto 1 /* path #2 */
goto next
1: /* path #1 */
next: /* ... */
both codes (assuming they are in the same enclosing function) have the exact same CC. Objectively the goto version induces a higher burden on the developer because he or she has to name every labe
Re: (Score:2)
1) That's an overly simplistic example.
2) That's not how I would use gotos.
3) Your mileage may vary.
Re: (Score:1)
I think it was just a bad example. You could do it with nested ifs fine:
if (get resource A == success){
if (get resource B == success){
if (get resource C == success){
do something useful, set initialization to true
free resource C
}
free resource B
}
free resource A
}
Apologies if that's wrong, I rarely consider myself good at this stuff, but I understand the original complaint about nested ifs versus gotos. Because in most code using 3rd party
Re: (Score:2)
Yes, and if you asked me such a stupid question I would fail you and not show up for the job.
That nonsense is neither necessary in C++ or Java. And I doubt in C#/.Net either.
In what funky century do you live, not in the current one, that is for sure.
Re:Really-Linus Torvalds (Score:4, Insightful)
Both the JVM runtime machine and CLI have JMP and branch instructions. All assembler and pseudo-assembler language, which basically emulate a sort of CPU instruction set, are going to have those kinds of opcodes. The languages that compile to bytecode need to have such primitives. It's the way computers work. Error handlers, no matter how pretty they look in an uncompiled code, are really going to do jumps and branches to some memory location or routine, however obscured that may be.
Re: Really-Linus Torvalds (Score:0)
Oh dear. You know, thereâ(TM)s a reason exception handling was invented
Re: (Score:1)
If you write that kind of shitty code I assume you are a young and inexperienced developer. Because what you blindly wrote, and yet you managed to get it wrong, is the root of unmaintainable code that I call "GOTO FAIL". Haven't you heard of structured programming and functions ?
if (get_resource(A) == success)
{
function_dealing_with_B_then_C();
free_resource(A);
}
Resource A is valid within the scope of the brackets.
BTW Linus and the kernel developers cr
Re: (Score:2)
Are you recommending breaking it into four functions and passing a ton of arguments among them?
The first to allocate A, call the second, and free A
The second to allocate B, call the third, and free B
The third to allocate C, call the fourth, and free C
The fourth to actually do any work
Re: (Score:2)
Many modern languages automatically produce the necessary "free resource" code and the necessary jumps as a side effect of the "get resource" code, so this is a poor example.
One place I have kept needing gotos is this sort of structure, except "f()" requires access to every single local variable in the surrounding code, and is also very very long (often about 90% of the code in the enclosing function):
if (test1) { // s
x();
Re:Really? (Score:4, Insightful)
That's because you're a n00b who's misheard the grownups talking.
Sometimes goto is the simplest and cleanest solution. I've seen clunky horrible crap trying to emulate it in languages that don't have it.
Re: Really? (Score:0)
I think it still can be unsafe if you have a larger code base with multiple developers contributing. Goto across modules impacts more than just your module. If goto is managed correctly and simply then it's very easy for developers to implement. You don't want to hear "why does the module have intermittent bugs" because of a couple of misplaced gotos. What you really want is a simple but effective policy that frees developers to use goto with minimal constraints or decision-criteria.
Re: (Score:2)
Put the goalposts back where you found them.
Re: (Score:2)
Sometimes goto is the simplest and cleanest solution.
Old BSD TCP/IP stacks had gotos in them. I saw them while implementing IPv6 in AIX back in the late '90s. I haven't looked at any BSD TCP/IP code for a long time, so maybe someone deep six'd them
And tcp_input.c had the best comment I have seen ever:
Re: Really? (Score:0)
Error handling in nested loops. It's the cleanest way to have a single handler.
Re: (Score:3)
And behind the scenes, however you create error handlers in a modern programming language, underneath the hood there's going to need to be a JMP somewhere to jump to the exception routine. That modern languages make this seamless and largely invisible doesn't make the underlying concept go away.
Re: (Score:2)
Speaking of goto the sign has a lot of waffle when really it should have just read
10 PRINT "FARTS"
20 GOTO 10
Re: Really? (Score:0)
Clearly, you're not smart enough to use an assembler or machine language. JMP follows almost every comparison.
Re: (Score:2)
Good grief. BASIC was inspired by COBOL and Fortran, both of which had GOTO statements. Not to mention here that assembly was a very common language at the time, and JMP and variants were all over the place. As ALGOL's descendants began to take over, all the old unstructured languages, including BASIC, began to adopt structured paradigms. But really, considering it was developed at a time when punch cards were a primary input method, it allowed non-programmers an easy on-ramp to coding, and if done well (us
DTS was timesharing (Score:0)
Dartmouth Timesharing System was not a way for computers to share resources. You logged into it with a terminal. Your programs were running that that machine. It was a timesharing (sharing time - cycles - on a mainframe.)
10 Months (Score:0)
Anyone else find a snicker at *10* months?
10 print anonymous coward is cool
20 go to 10
Re: 10 Months (Score:0)
That would simply print a bunch of zeroes. If you don't put the sentence to be printed between quotes it will be treated as a numerical variable. Kill yourself.
Re: 10 Months (Score:0)
Considering I haven't touched any programming language in 30 years, forgive me for missing something.
I simply found the 10 value, involved with the subject matter a bit humourous.
Short of that, you can kindly go dine on a bag of dicks.
Suck X It.
Everybody who has ever typed a GOTO command can f (Score:0)
Everybody who has ever typed a GOTO command can feel proud...
I still use GOTOs, you insensitive clod. I program in VBA. And I feel deeply ashamed.
Re: Everybody who has ever typed a GOTO command c (Score:0)
I actually prefer VBA or something like JMP or MATLIB. Yes, there are complex algorithms but most of the time you aren't implementing them. It's usually making a chart or querying a database and VBA is simpler and still retains enough nuance to get most code written, even if it's imprecise.
Basic still has a place (Score:2)
Re: Basic still has a place (Score:0)
I don't particularly appreciate people looking down on BASIC. It isn't even worth the time to reply to remarks from people who probably don't know any language very well. BASIC an ideal language in so many ways.
Re: Basic still has a place (Score:0)
I could peek at memory locations and poke data straight into them with BASIC on my TRS-80. Object orientation ruined the language IMHO.
Re: (Score:2)
In the 8 bit days, BASIC was the operating system. It would be pretty nightmarish to have a multitasking kernel that allowed programs to just go mucking around at any memory location they wanted. Not that most early multitasking operating systems prevented it, memory management was pretty limited in at least consumer grade operating systems, and such systems basically relied on the honor system. Preemptive kernels had to put more work into memory management, and pretty much all modern operating systems with
It's all fun and games... (Score:0)
It's all fun and games when the highway department puts up that fancy new "1964 BASIC" highway marker, until some joker sneaks in late one night and puts up a "1965 GOTO 1964" marker a mile further down the road.
They should update the highway signs too (Score:2, Informative)
GOTO Manchester - 5 mi.
GOTO Concord - 24 mi.
And now ... (Score:2)
Geeks don't like BASIC (Score:1)
They recognize it for the utter crap it is. Pseudos and wannabes will feel honored by this action though.
Re: (Score:1)
Most of us geeks started programming with some form of BASIC no matter how unfashionable it is to reveal.
My sister started teaching me Basic on one of our Dad's many CP/M machines (he used to sell them - probably an SD System or a Kaypro or something, I can't remember) when I was 5 years old.
Eventually I moved on to assembly and C and C++ etc. etc. but BASIC was where I started.
I acknowledge it and I appreciate it for what it was.
My Dad stuck with Basic and Visual Basic and provided an amazing childhood for
Re: (Score:1)
It was a legitimate tool to introduce a student to assembler concepts.
Should never have been allowed to be used for anything else, of course.
It's no longer the Granite State (Score:2)
After the Old Man of the Mountain collapsed in 2003, NH lost its state icon, depicted on stamps and on the state quarter. So why not a rebranding for the coin?
10 REM NEW HAMPSHIRE
20 REM The BASIC State
30 LET ThisCoin = DOLLAR(1.0 / 4, 2)
I have one question. (Score:2)
Why is Microsoft's name attached to this article?
Perhaps the article should be about Bill Gates coining the term "Software Piracy" because he was taking to long to release BASIC to the ALTAIR after so many had already paid for it? (today that amount of time raises legal issues)
Microsoft did NOT create BASIC!
Re: (Score:0)
Microsoft did NOT create BASIC!
Well, they sort of did:
Become
A
Shit,
Instant
Cash!
Re:I have one question. (Score:5, Informative)
>Why is Microsoft's name attached to this article?
Because Microsoft's BASIC is what most people in the world used. Long before Visual Basic, there were millions of users of Microsoft BASIC; more than any other software company's.
Did you ever use a Commodore machine (from the Commodore PET all the way to the 128 and some versions of the Amiga)? Then you used the BASIC [wikipedia.org] licensed from Microsoft. Or maybe you wrote some BASIC program on an Apple from the II+ onward? You used a BASIC [wikipedia.org] licensed from Microsoft. TRS-80, from 1977 onward [wikipedia.org]? Microsoft BASIC. Even Atari, who had their own BASIC sold Microsoft's BASIC as an upgrade. Heck, if you had an Altair 8800 [wikipedia.org], there was a BASIC from Microsoft available.
Re: (Score:0)
and the IMSAI 8080.(duh) Good points!
Re: (Score:2)
Microsoft ${basic software idea} is what most people of the world use. Giving Microsoft any credit for any of it is still problematic at best.
Re: (Score:0)
I used gw-basic on my first computer -- don't even remember the OS. Later I used qbasic (with MS-DOS 4, I believe)
Re: (Score:2)
Wow, even Apple BASIC was licensed from MS too. I never knew that! :/
Re: (Score:2)
The story I'd heard was that, in the mid 80s, the Apple II was still selling decently well when its BASIC license was about to expire. So, Microsoft said, "hey Apple, about this whole Windows Look and Feel lawsuit" ... which quickly went away...
Re: (Score:0)
The story I'd heard was that, in the mid 80s, the Apple II was still selling decently well when its BASIC license was about to expire. So, Microsoft said, "hey Apple, about this whole Windows Look and Feel lawsuit" ... which quickly went away...
The story should maybe clarify how Microsoft managed in 1985 to convince Apple to get a BASIC license in 1977.
Re: (Score:0)
Not to mention the case wasn't settled out of court, it was decided in 1994, and not in Apple's favor.
Sounds like a bit of mythmaking to me!
Stupid, the basic thing, not NH (Score:0)
While Silicon Valley is over rated this NH thing is embarrassing. I say that as someone who lives here (NH that is). We have an amazing free software tech scene and 10s of thousands of techies moving here because of the Free State Project. This gimmick is embarrassing to those of us who put freedom first.
Re: (Score:2)
The Free State Project is far, far less popular that BASIC ever was. You're lucky if there are tens of techies moving here. We don't need newcomers coming to the state and then whining about it. Stay home, fix your own damn state.
Marker #256? (Score:0)
How appropriate that this computer related maker is number 256.
How 8 bit is that?
BASIC vs. "advanced" languages (Score:2, Insightful)
Would you rather do this (BASIC):
10 PRINT "Hello, World"
or this (Java):
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello, World");
}
}
Is this progress? Is it any wonder people find coding difficult to learn nowadays? I suspect coding is more daunting for beginners now than it was in the 1980s because of "advancements" like this.
Re: BASIC vs. "advanced" languages (Score:0)
BASIC is procedural, simplified assembly in a sense. Very linear, very close to the metal.
JAVA is an objective abstraction in comparison. Very non-linear, very far from the metal.
To say that one is better than the other is to discount the flaws and overvalue the features of either.
Anyone comparing programming languages and looking to name one "the best" has a poor understanding of the idea of "use the right tool for the right job" and are in effect arguing that the bike shed should be painted red.