5 ms·
> There are a lot of poor programs misusing goto, so they just removed the operator: good for juniors, but too limited for professionals. It's a bit condescend
by speedgoose 6y ago
> There are a lot of poor programs misusing goto, so they just removed the operator: good for juniors, but too limited for professionals.
It's a bit condescending. I think the article would have been better without that kind of comment.
- virgilp 6y agoYeah, I caught that too; it's more than a bit condescending and is also completely false. Complexity makes all people trip up, not just "juniors".
- deleted 6y ago[deleted]
- tornato7 6y agoEspecially because a "professional" programmer should be able to get along just fine without goto. Goto is bad practice in many languages where it does exist, too, like Go.
- deleted 6y ago[deleted]
- berkut 6y agoHow do you break out of nested loops without an extra variable set/check to break on in the outer one otherwise? goto is nasty, but in my experience writing HPC code, it does have some uses that can't be solved as efficiently (i.e. without extra branching) otherwise in some situations.
- tomjakubowski 6y agoRust has special syntax to name loops, and to refer to them by name when breaking. 'foo: loop { 'bar: loop { break 'foo } }
- berkut 6y agoCool - in which case, at least based on my experience, that would negate the need for goto in the main situation I end up using them in C/C++. The only other time I've seen it be used fairly regularly is cleanup / return handling, where there are other ways of doing that (RAII structures, if you don't mind creating them), but sometimes using goto for that is just simpler / more obvious than having extra structs/classes to handle that.
- FreeFull 6y agoI also suspect that goto is missing not because of potential misuse, but because it's actually difficult to implement given all of Rust's other semantics.
- steveklabnik 6y agoFor some previous interesting discussion of this: https://news.ycombinator.com/item?id=9827276 https://news.ycombinator.com/item?id=9827276 https://mail.mozilla.org/pipermail/rust-dev/2014-March/009142.html https://mail.mozilla.org/pipermail/rust-dev/2014-March/00914...
- deleted 6y ago[deleted]
- dehrmann 6y agoThe only times I've really wanted goto were around exception handling. Java (not sure if it started there or was borrowed) actually has a construct that can do this without the issues with goto: block: { ... if (err){ break block; } ... if (err){ break block; } .... }
- svrb 6y agoRust has this innovative feature called "functions" which enables you to break from any block by just giving it a name and using "return". It can even return a value! (/s obviously, but also not /s obviously. The serious point here may be that Java or whatever got in the way of defining functions by requiring them to be "methods" stuck in a "class" rather than, you know, just functions.)
- pirocks 6y agoA static function in Java is essentially just a function. Also I have no idea what functions being associated with classes has to do with breaking out of loops.
- gpderetta 6y agoencapsulate your nested loops in a function and return to exit multiple loops at the same time. Having nested lightweight functions allows minimal syntactical overhead compared to plain loops, although still not zero.
- krizhanovsky 6y agoI didn't mean anything condescending here actually. The point is that when people starting programming, it's good to put them into a restricted environment, so that they get used to use the right tools and in the right way. For example, it's quite easy to misuse goto in normal programs and make the programs unreadable. However, if a developer is already perfect with writing good code, but (s)he needs to do something special, like the state machine in the article, the restriction just makes the developer's life harder.
- ordu 6y agoI have a question about those state machine: did you tried to do it without goto with functions only? The idea is a straightforward one, just chuck all branches into functions and call functions instead of goto. Rust wouldn't be happy with that, if you try to make branches into local functions, because they would access "global" mutable variables on stack. Borrow checker might misunderstand your intentions and go mad. But we could think a way around it, how about state as a struct-like variable passed by a mutable reference into inline functions? Or maybe not functions, one might consider duplicating code. There is DRY principle, but there is WET principle[1] also. Both of them have their proponents, so at least they are not stupid. How WET shows itself in a highly-optimized programs? Did you try it? I have no link, and may be wrong, but I believe that John Carmack argued in a favor of WET, and I wouldn't say that Carmack doesn't bother with a program speed. I mean, I'm not convinced, that goto is the game changer, I see other ways around the issue, which in some ways are superior to the solution using goto. So I'm not so sure that your way to use goto is not a misuse. > if a developer is already perfect with writing good code, but (s)he needs to do something special, like the state machine in the article, the restriction just makes the developer's life harder. The trouble is there are no developers who a perfect. So it is not intrinsically bad thing to make live of a developer harder by introducing restrictions. If it forces developer to codify more of his assumptions about his program, then it is harder to be imperfect. [1] https://en.wikipedia.org/wiki/Don%27t_repeat_yourself https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
- krizhanovsky 6y agoThere were quite a long work, for couple of years, on the parser. The first article about the parser is https://natsys-lab.blogspot.com/2014/11/the-fast-finite-state-machine-for-http.html https://natsys-lab.blogspot.com/2014/11/the-fast-finite-stat... and next I updated it significantly in my talk at https://natsys-lab.blogspot.com/2014/11/the-fast-finite-state-machine-for-http.html https://natsys-lab.blogspot.com/2014/11/the-fast-finite-stat... (http://www.tempesta-tech.com/research/http_str.pdf http://www.tempesta-tech.com/research/http_str.pdf and https://www.youtube.com/watch?v=LQc4er8ng64&feature=youtu.be&t=25501 https://www.youtube.com/watch?v=LQc4er8ng64&feature=youtu.be... ). The talk also discusses code repetitions: compiler makes duplicate code anyway, even for straightforward `for` loop and nested `switch`, but in our case we had much more duplicate code. The thing is that we used hot/cold labels to minimize jumps over the code and improve instruction cache usage, so calling functions isn't good at all. We wanted one big function with is executed as linearly as possible to improve instruction cache prefetching.