Live data from Hacker News

All Programming Languages are Wrong (2018)

users.rcn.com

71–79 of 79 posts

Re: All Programming Languages are Wrong (2018)

#71
post #26
post #16

Does anyone else consider these type of articles the clickbait of the programming world? They tend to all follow the formula of 1. Make over the top statement in title. 2. Vaguely address the over the top statement in content. For example the author hasn't shown us why "All" programming languages are "wrong". They haven't shown how they would fix them to make them "right". Their premises (e.g. "computation is almost…

"computation is almost free" actually triggered me. that's the java argument from 20 years ago, now we have go and rust. it implies electron is actually a sane approach to ui development. the author is very vague about why exactly numbers don't fit in the type system, and in which languages. first class types for numbers exist in some languages. is he advocating for default overflow checks, which bloat code size?

"computation is almost free" - don't say that around the accountant at my company responsible for paying our AWS bill!

Re: All Programming Languages are Wrong (2018)

#72
post #20

Earlier quoted context omitted.

I am probably in the minority here but I think Java was on the right track with checked exceptions.

I used to think so, but * Java also has unchecked exceptions, and, incredibly, there's still no consensus as to which exceptions should be used for what and when, though these days the most common approach is to simply stick only to RuntimeExceptions, which is terrible. * Functional error handling using Option, Either, Try etc are arguably much simpler, safer and more powerful than exceptions. Simpler because they do…

Checked exceptions really aren't much different from dedicated return type for errors. The Either type in Haskell and its Monad is really not doing anything fundamentally different: Bubbling up errors until the point where someone cares/needs to handle them (though I have to say I hate the whole Left / Right convention thing, just define a dedicated type with proper constructors for value vs. error already).

In fact I'd say checked exceptions are a richer formalism since they essentially provide something akin to intersection types for errors.

The fact that there are also RuntimeExceptions comes up a lot as an argument against Java/checked exceptions but that doesn't convince me. Haskell also has runtime errors that can happen (division by 0) that are outside the Either or Option/Maybe world. The problem is maybe rather that people are lazy and the trend became to decide that everything should be a RuntimeException because who needs all that noise and checked exception handling, right? I'm fairly certain that people who rejected checked exceptions would also reject the more functional approaches.

My argument is that no consensus around using checked exceptions correctly ever developed and so they never really had a chance to shine.

Having said that, sure I think having more usage of idioms we find in FP for error handling/propagation or early aborting is great. It's better than just raising runtime exceptions. However we are still in a world where no widely known language actually enforces (!) error handling in that fashion. It's all convention in the end.

And so my point was that if you want a language that tries to encourage error handling, with known failure modes communicates in the method signature then Java's checked exceptions sound pretty close.

Sure they are not perfect but the question is whether it's worth exploring better formalisms along the lines of first class errors with dedicates language support or piggybacking on the existing type system features and introduce conventions? The latter sort if works but I find it less ...exciting.

Re: All Programming Languages are Wrong (2018)

#73
post #69

Earlier quoted context omitted.

Always hated checked exceptions because there seems the basic assumption underlying them, that exceptions can usually be handled as near to the code throwing it as possible, while in every real world project I ever was involved in, 90% of the possible exceptions usually had to be handled "far away". So this means, you will have a whole bunch of re-throws, or exceptions wrapped in "higher design level" exceptions whic…

With functional error handling, every method just returns an object. If the caller doesn't want to do anything with it, it can just pass it on somewhere else. Only once you actually care about filtering, mapping, flatMapping, folding etc do you actually need to handle the different cases. It's just so much better and easier to understand than exceptions! Doesn't require any special syntax or mental gymnastics to unde…

I fail to see how this is different.

Say you have a function f1 returning an Either a b value then another method f2 which calls f1 but doesn't handle the error case will simply flatMap or bind or whatever the language of choice is calling it and return yet another Either a b value until at some point up the call hierarchy someone actually decides to unwrap and if necessary do something with the error case. The function signatures have the same problem as the parent comment mentioned.

flatMapping over an Either and returning the result is no different than adding "throws SomeException".

Then Option types (since they were mentioned as well somewhere) are a bit of a different story all together. They make sense for describing absence/presence if values/results and are definitely useful. However they don't compete with Exceptions in any real way since they don't really work for error handling beyond the most basic cases (i.e. where handling the error somewhere doesn't matter/need to happen).

Re: All Programming Languages are Wrong (2018)

#74
post #48

Earlier quoted context omitted.

I am probably in the minority here but I think Java was on the right track with checked exceptions.

Coming from C# to Java, checked exceptions are the worst. There are so many layers that can fail even in a simple API call - network, database, permissions, memory, etc.. We're not going to handle each of those cases differently, if we were going to we could always catch the specific exception type explicitly. But usually it's fail the API call, catch the base exception, and report the relevant failure message. Fail…

My point was that if one wants a language that is explicit about what error types a method can cause (see the top-level comment I replied to) then checked exceptions aren't far off and in fact on the same track.

The problem you describe may be an issue with checked exceptions but it would equally be one in any language with the aforementioned feature.

> We're not going to handle each of those cases differently, if we were going to we could always catch the specific exception type explicitly.

But you don't have to handle them differently. You can though and your method signatures will tell you what type of errors you might have to deal with. Some make sense to handle on the spot others don't.

You don't get that with runtime only exceptions. With those you really don't know and can get all kinds of errors and so you expect all and then just catch all and deal with it or blow up/abort whatever is going on (which let's be honest is what most web services do). Is that good? Yeah, sometimes. It certainly is easier to do that instead of thinking about possible failure modes when you know you'll only end up logging the error and give up anyway. I'm not trying to be cheeky, it really is overkill to make full use of checked exception in some cases.

Granted I haven't seen many great examples of checked exception usages so far but I wouldn't dismiss them because they don't mesh with what you're used to or with what's common in a given domain.

Re: All Programming Languages are Wrong (2018)

#75
post #35

Earlier quoted context omitted.

I am probably in the minority here but I think Java was on the right track with checked exceptions.

Something that Java typically gets the blame for, but was actually introduced in CLU, adopted by Modula-3 and C++ before Java was even born. And with my .NET hat, I hate having to dig into outdated documentation to discover what exceptions might come my way, so one ends up catching any kind of exception, just in case it might blow, in critical code paths.

AFAIK no C++ does not have checked exceptions like Java does. There's no static check enforcing that a caller needs to handle (or also declare throwing) an Exception declared to be thrown by the called method.

Re: All Programming Languages are Wrong (2018)

#76
post #27

The author has a good point, although he miscommunicates it: The common use-cases, such as servers, business logic, glue code, etc., don't usually require hyper-optimized performance. It only needs to be reasonable and predictable. They need a language that is easy to work with, and share with others, and there are few that really do that. But of course, there are. Go, Python, Julia and others I'm sure, all prioritiz…

Julia does not prioritize comfort over (runtime) performance. The entire language is based around developing clever ways to get zero runtime cost abstractions.

Re: All Programming Languages are Wrong (2018)

#77
post #70

Earlier quoted context omitted.

I think the problem with checked exceptions was that we got a woefully limited language for talking about them. Checked exceptions with generics (and inference?) might be a very different experience. For instance, Java's checked exceptions break higher-order functions. A map function should be able to say "I can throw anything my argument can throw". Some wrapper functions might say "anything my argument can throw, m…

With functional error handling, you don't need neither checked nor unchecked exceptions, everything just returns objects, and the language and syntax used for talking about them is the same as the language and syntax used for everything else (map, filter, flatMap, fold etc etc).

I was speaking to checked exceptions vs unchecked. "Exceptions at all" is a separate question.

If we're going to dig into it, first we need to call out the occasional need to interrupt running pure code (eg. "the user hit ctrl-c"). As it can happen at any point, I think it's uncontroversial to say that return values are inappropriate? These are Haskell's "asynchronous exceptions", I think they do their job fairly well, and I don't know of a compelling exception-free alternative (although I'd be very interested to learn).

So now we can restrict ourselves to "synchronous exceptions" - those raised because of the function we've called.

I agree that we don't need them. They bring to the table early termination and transparent error propagation. There are contexts where these are desirable - if you disagree on that point let me know and we can dig in. In sufficiently expressive languages, we can do it ourselves - so that's plenty to show we don't need them.

But we may want them.

When we do it ourselves, we usually lack a way of telling the compiler which paths to privilege, and we often find some overhead compared with native exceptions.

When exceptions are provided in the language, we get special syntax to distinguish them. You describe this as a drawback, but nonuniform syntax can help with legibility - if different things look different, I can more easily figure out what I'm looking at. Obviously there are tradeoffs here.

Putting exceptions in the language also provides a distinction to the compiler in type checking, allowing different rules to apply. For instance, Java methods throw some set of exceptions, which get unioned (&c) in ways you can't speak about sets of types otherwise. Simply applying the ordinary value-level rules would be problematic (I hit this in Haskell sometimes). Ideally you can broaden your type rules to support what you need for all of it in one system, but it's not always clear they combine well. Even if it all can be made to fit, I could easily see a situation where assumptions need to be made for inference to work, and the most ergonomic assumptions are different for most values vs. bags of errors.

Re: All Programming Languages are Wrong (2018)

#78
post #68

What a bunch of bs. There are so many places where computation is far from free and size matters (embedded, HPC for example). And the end of Moore law is just gonna emphasize the need for performance even more. This article just tells me that the author didn’t have to write any performance critical code in his life and he just extended his experience to everything

Yeah, what would David Moon of all people know about performance critical code. https://www.h2o.ai/blog/a-brief-conversation-with-david-moon...

It doesn’t really matter who wrote it. It’s a comment about the article , not the author himself and the article is approssimative at best. It makes a statement that’s not true in a lot of cases (“computation is almost free”), makes some statements that while agreeable are too high level in how they are expressed like “cost of communication is high” and then the piece ends without any explanation or examples on what he means exactly or what is wrong and how to solve it in enough details to actually be an informative article. It seems like an oversized rant a programmer would make after a bad day at work on Twitter.

Re: All Programming Languages are Wrong (2018)

#79
post #27

The author has a good point, although he miscommunicates it: The common use-cases, such as servers, business logic, glue code, etc., don't usually require hyper-optimized performance. It only needs to be reasonable and predictable. They need a language that is easy to work with, and share with others, and there are few that really do that. But of course, there are. Go, Python, Julia and others I'm sure, all prioritiz…

> But of course, there are Your statements are contradictory. > they might one day actually become faster faster compared to C/C++ ? Of course, Performance is improving day by day. What's the point?

It's not contradictory. I'm saying that the things he says are true, and there are many languages that follow that line of thought.

Yes, faster than C++. Better abstractions can, sometimes, give the compiler more flexibility to optimize.

Post reply on HN