Re:Ask HN: How do you define a junior developer?
by koenigdavidmj on Thursday September 22, 2016 @01:04PM
(#12558293)
Without goto, you get to maintain several copies of your cleanup code, all different:
Now here's an example where you only need to maintain one copy of your cleanup code:
Avoiding goto gets impossible the second you start doing socket twiddling, or message generation. Yes, languages with context managers (Python's with blocks), RAII (C++ or Rust), or defer (Go) make this easier, but some of us are stuck writing C sometimes.
[ Parent
| on HN ]
Re:Ask HN: How do you define a junior developer?
by tzs on Thursday September 22, 2016 @01:32PM
(#12558539)
Of course in this case you can avoid both the repetition and the goto at the cost of more nesting:
rv = -1;
a = open(...);
if (a) {
b = open(...);
if (b) {
c = open(...);
if (c) {
rv = something(a,b,c);
close(c);
}
close(b);
}
close(a);
}
return rv;
I wonder if there is some sort of program organization analog of Heisenberg's uncertainty principle, where the product of some measure of repetition, some measure of non-structured jumping, and some measure of nesting must be greater than a certain value?