Hacker News new | ask | show | jobs
by grasleya 3290 days ago
I can buy using generics sparingly (especially in the form of complex template metaprogramming). But never using it at all? Can you imagine convincing the C++ community to give up Boost because its use of templates is too complex?

They also seem to admit that if they were to do it over again and start from scratch they'd use exceptions:

> Things would probably be different if we had to do it all over again from scratch.

2 comments

If exceptions are so great, why Rust and Swift aren't using them?

It seems that thinking on exceptions in low-level languages is firmly in the "no way" camp.

Contrary to popular thinking, exceptions are not free.

For example, when Chrome disabled rtti and C++ exceptions in Chrome codebase, it resulted in saving 6MB (20%) of code. See https://bugs.chromium.org/p/chromium/issues/detail?id=19094

This is when exceptions where not actually used in the code. The bloat is merely from enabling C++ compiler flags to generate rtti and exception support code.

> It seems that thinking on exceptions in low-level languages is firmly in the "no way" camp.

Except Go isn't particularly close to the metal anyway. The only way Go is low level is in the same way Java is low level: it's very limited in terms of the programmer's ability to create abstractions.

> If exceptions are so great, why Rust and Swift aren't using them?

Technically speaking, Rust does have exceptions with its unwinding feature. The panic! macro throws an exception, and catch_panic allows you to catch it. It is implemented exactly the same way as C++ exceptions, with the accompanying code bloat and performance pessimization, and you have to think about exception safety exactly the same way when writing unsafe code.

Rust has unwinding, which indeed opens a whole can of worms, but to say that it has exceptions is to miss the point. Rust has nothing anywhere near close to first-class resumable exceptions as surfaced in, say, Java. Not only is the `catch_unwind` function (it's not called `catch_panic`, btw) deliberately difficult to use (specifically to deter people from using it as a general error handling mechanism), the language deliberately defines an alternate compilation mode where unwinding does not exist and hence any attempt to "catch" it will fail. As a result, I have never once seen Rust code APIs that use `catch_unwind` as a mechanism for error handling; the purpose of that function is to prevent unwinding from crossing FFI boundaries.
> If exceptions are so great, why Rust and Swift aren't using them?

Because they made a mistake by not including them?

More seriously, you are approaching the argument the wrong way. You don't judge a feature by how popular it is but by analyzing objectively whether the presence or absence of that feature leads to higher quality code

> It seems that thinking on exceptions in low-level languages is firmly in the "no way" camp.

Actually most of them have them.

Just out of my mind, Mesa/Cedar, Ada, Modula-2, Modula-2+, Modula-3, D, Object Pascal.

Why would anyone try to convince Boost users to give up boost? On the other hand, designing new language, it is reasonable to consider ways of reducing code cost and complexity by avoiding such features. Large fraction of C++ developers won't understand how half of boost libraries works at all and that is type of complexity Go tries to avoid. There are tradeoffs, that is undeniable, but it is a valid approach to address this exact issue.