I spent to some time to check and analyze the code.
The author uses it in a clear pattern, specifically, as a sibiling post mentions, in order to achieve error handling (additionally, with fall-through); the labels are indeed neatly placed at the end of the function, after the `ret` exit.
The problem is consistency - the upper half of that function performs error handling without goto, and the lower half with it.
I personally prefer all-or-none solutions, since I highly value consistency, but on the other hand, I do consider this solution acceptable, since it still has a tidy (enough) structure.
I've seen the goto error-handling approach used now in SDKs written by developers from companies like Microsoft, Nvidia, and Nordic Semiconductor. It really does seem to be the best way to do it. And it's simple. Mess something up... goto cleanup... Seems fine to me!
Can you think of a counterexample? I wouldn't be surprised if you could trick a compiler with a goto but optimizing control flow is very much the type of optimization that Knuth was referring to. Now that almost all compilers use SSA I'd be surprised if it was the case outside of fairly deep control flow
Error handling was already mentioned ITT. Goto use seems like a litmus test for bad programming. The presence of it doesn't prove bad programmings but lots of goto statements could be reasonably be expected to be replaced with safer switch statements. Extremely nested functions are another area that is best served with a goto. Breaking out of many functions has performance implications I believe.
If you’re criticizing goto in kernel source, you don’t know what you’re talking about. It’s incredible how many people just regurgitate this anti-goto meme without any experience writing system C code. There are various highly structured uses of goto used for systems programming in C, most prominently for error handling but also for things like retry logic.
I checked (just for you). All four gotos are reasonable forward gotos and not what the article "goto considered harmful" was referring to. As an aside, why did you write goto in all caps in your comment? While your comment was quite basic, it wasn't BASIC, so no such caps are required. Please don't shout.
The specifics of the speed gains are our secret sauce, I’m afraid! But at a high level, we reduced the time taken in every step of the pipeline between capture > encode > send > receive > decode > render that we could, while still remaining WebRTC compliant.
This process is typically referred to in the scientific literature as "enhanced" weathering but we think that "accelerated" weathering is easier for lay people to understand.
Drawdown is mostly focused on things we can change in our current activity to lower emissions and less about methods for Carbon Dioxide Removal (CDR). Their top solution for becoming carbon neutral is "Refrigerant Management"...
I like the concept of the project and know some people working in the org, but in my opinion, they do not give enhanced/accelerated weathering enough credit as a potential solution, even though it can scale all the way up to global CO2 level emission removal. Many of the other solutions they suggest are limited in potential, yet featured prominently... I am working to communicate this to them.
There are a number of people I know who have never touched Java and are being exposed to the eco-system through languages like Clojure and Scala and this kind of overview may be useful to them.
However, I agree that it's not worthy to be on the front-page of HN.
These are not Java-specific data structures. If you already know these concepts -- and I don't see how you could write code without inevitably bumping into them -- the Java implementations should be intuitive and trivial to learn. Not to mention clearly documented.
The only reason I feel this is out of place here is because the very first thing the author says is "if you google[...]" which I would hope most hackers do before they start asking questions of others.
As of Java 1.5, generics were added. Before generics you had to cast every object you read from a collection. If someone accidentally inserted an object of the wrong type — possible in the OP's example code — casts could fail at runtime.
With generics, you tell the compiler what types of objects are permitted in each collection. The compiler inserts casts for you automatically and tells you at compile time if you try to insert an object of the wrong type. This results in programs that are both safer and clearer. So please use generics when using the collections framework.
I'm now going to briefly run through the examples provided in OP's post and update them accordingly.
Note that I've used the interface form of List over a specialised type. This is so that any caller of a method which returns a collection can use the interface provided and they don't need to worry about the specific data structures you've used. This also means that you can update the underlying data structure without having to update any calling code. E.g. changing the above case from ArrayList to LinkedList.
It is worth noting that Hashtable was not originally part of the Collections framework. It was retrofitted to conform to the Map interface in 1.2. You should instead use HashMap, which is the non-synchronized (sic) version of Hashtable. Although you can just as easily use Hashtable, the below example is just me being a little OCD.
> It is worth noting that Hashtable was not originally part of the Collections framework.
An other class in that case being Vector, and that's the reason why they have a lot of duplication in their methods: they have the original ones, and they have the new ones coming from the Collections framework interface (this is also the source of having both Iterator[0] and Enumerable[1] in the JDK: Iterator is the Collections framework iterator interface, Enumerable is the pre-Collections one)
An other big difference, which you hinted at, is that Hashtable and Vector are both synchronized collections (method calls will take the collection lock and behave "atomically"), whereas Collections framework classes are not, instead the Collections framework has compositional wrappers[2] which provide this behavior independently of the underlying collection implementation.
finally, a little trick for more fluent Collections initialization: you can abuse anonymous subclasses and instance initializers to get something much less imperative:
Webbit looks much more like embedded Jetty and plain servlets than Sinatra. If you really want something like Sinatra in you Java project, wire in Scala and try Scalatra.