DEV Community

Discussion on: Comparing error handling in Java, Go and Rust.

Collapse
 
rkfg profile image
rkfg

Same in C++, it's called RAII and it's a great idiom. I like that it works well with exceptions so you can just throw and be sure the destructors will be called. And it can be used with whatever thing that needs cleanup, you can call anything a "resource", be it a database connection, reference counter or a text box scroll position (yes, I used RAII once to save/restore the scroll position). In Java it's not that flexible though, you have to explicitly markup the "RAII scope" using try-with-resources but that's understandable because GC contradicts with explicit lifetimes. In C++ it works in absolutely any scope.

Collapse
 
legolord208 profile image
jD91mZM2

Ey, that's cool! I never really used C++, but it looks a lot like Rust :D

Collapse
 
rkfg profile image
rkfg

They're getting closer though Rust has the borrow checker and lacks a modern IDE. For C++ I use Eclipse CDT, it's almost perfect. Overall, C++14 (as 17 is not yet supported everywhere) is pretty good, it has almost everything you'd expect from a modern lanugage like lambdas, type inference (including function parameters type in declaration!), memory effective "move semantics", automatic memory management with smart pointers, null safety and so on. I get segfaults even less often than I get NPEs in Java! Some bits and pieces like coroutines and advanced date-time operations are covered by Boost. Unlike many other languages, with C++ you'll get C libs support for free and that's a lot of useful code. Give it a shot, it's worth it.

Thread Thread
 
legolord208 profile image
jD91mZM2

There is an IntelliJ Rust plugin AFAIK, and I use vim either way.