5 ms·
I like the joke, but I consider the reflexive anti-goto attitude harmful. Javascript would be a better language with a native goto statement. I think people f
by tc 17y ago
I like the joke, but I consider the reflexive anti-goto attitude harmful. Javascript would be a better language with a native goto statement. I think people forget the context of Dijkstra's paper. Scope-local gotos are qualitatively different than type of function-less code that Dijkstra was referring to at the time. The clearest way to express certain algorithms really does involve a (local) goto. And goto makes it much easier to implement higher-level language constructs in Javascript through preprocessing.
Without goto and TCO (goto by another name), you're left to transform your code to be run under a trampoline, which really makes the resulting JS unreadable.
- edw519 17y ago!reflexive, I promise you. Based not on Dijkstra's paper, but my own horror stories.
- tc 17y agoI know, I know; I've read bad code too. But I've also read plenty of bad code in languages that don't have goto. Copy-and-paste coding and reckless abuse of globals are worse and more prevalent than goto abuse in my experience. Besides, I object to bondage and discipline in a programming language. If people don't have guns, then they'll use....
- benmathes 17y ago...a baseball bat, which while possible of inflicting terminal injuries isn't quite as good at it, lowering the number of deaths. The analogy still holds :-) edit: I mean to say literally that GOTOs certainly are useful, but are far easier to create spaghetti code with than something much safer like functions. It's a cost/benefit analysis.
- eru 17y agoI can code perfectly fine (and mind-blowing) spaghetti code with call/cc, too.
- Bjoern 17y agoActually I can only second that. Goto's are useful. For instance in the Linux Kernel it is used instead of exceptions in the function scope. Unfortunately great power (goto) comes with great responsibility (don't produce spagetti). Most $programmers don't get that right.
- gruseom 17y agoSure, but then we're down to arguing whether a language should be designed to constrain bad programmers or empower good ones. And quite apart from the general arguments one can make (for example, that bad programmers will make a mess no matter what), it's clear that Javascript has become a major platform for modern applications. To constrain the growth of the entire class of web apps in order to allegedly limit the spaghetti produced by $programmer is a poor tradeoff, I'd say.
- eru 17y agoInteresting jargon. Is a $programmer a PHP (etc) programmer?
- crux_ 17y agoWhat JS really, really, really, really needs isn't TCO (well that too), but rather call/cc. Looking over a fairly large project here, a majority of the code is written in CPS because of callbacks to the server or delays for user interaction. (So far, I've avoided the need to trampoline, since my call stack isn't getting too deep yet before it unwinds on it its own. But, then again, I haven't done any cross-browser testing at all yet.)
- 10ren 17y ago> The clearest way to express certain algorithms really does involve a (local) goto. Java doesn't have goto, but it has labeled break and continue statements. Great for exiting nested loops. Exceptions are another kind of structured goto. Of all the criticisms of Java, I've never heard the lack of goto bemoaned. One thing I love about the Java designers is their humility: they thought the above was enough to cover all the cases where a goto was really convenient, but still made goto a reserved word. Just in case.