News for hackers. Stuff that matters.
Re:T* makes for a poor optional<T&> by kentonv on Monday December 13, 2021 @05:28PM (#29545515)
Throwing an exception is somewhat better but still not what I really want, usually. I want the compiler to make me write an if()-like statement checking if the value is non-null before I can dereference it.
Re:T* makes for a poor optional<T&> by Pxtl on Monday December 13, 2021 @07:00PM (#29546393)
Try/catch is if-like if you do it right.... But it's also not mandatory. Hence the argument for Java's checked exceptions... which didn't pan out in the end.
Re:T* makes for a poor optional<T&> by kentonv on Monday December 13, 2021 @09:42PM (#29547563)
Throwing exceptions in C++ is also incredibly slow, you generally don't want to do it in any path that you expect will actually be exercised in normal operation.

Checked exceptions were a nice idea in theory that definitely didn't work well at all in practice. IMO exceptions should be reserved for "panic" situations, as a friendlier alternative to crashing. (But I also feel they should be used liberally in such situations...)

Re:T* makes for a poor optional<T&> by Pxtl on Monday December 13, 2021 @09:47PM (#29547607)
I cut my teeth on Python's "forgiveness not permission" model and find that exceptions are usually the cleanest model since so few languages have pleasant syntax for alternate return-types, and returning a status code and using out parameters for the actual result is miserable.
Re:T* makes for a poor optional<T&> by masklinn on Tuesday December 14, 2021 @12:28AM (#29548556)
Sure but python was built on a model of signalling anything via exceptions, C++ was not, and it sacrifices the exceptional case for the benefit of the nom-exceptional one.
Re:T* makes for a poor optional<T&> by hoseja on Tuesday December 14, 2021 @08:26AM (#29551226)
Using exceptions for control flow etc. etc.