| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
July 15, 2012 Creator of ZeroMQ and AMQP comments on error handling | ||||
|---|---|---|---|---|
| ||||
Hey everyone, Apologies for sending this to the D mailing list but I just read a very interesting article on error handling and was interested in your opinion. I just read an article by Martin Sústrik, one of the creators of AMQP and ZeroMQ, on using C++ for writing infrastructure/system software. At first glance most of his objects seem to apply to D. What do you all think? Why should I have written ZeroMQ in C, not C++ - http://www.250bpm.com/blog:4 Thanks, -Jose | ||||
July 15, 2012 Re: Creator of ZeroMQ and AMQP comments on error handling | ||||
|---|---|---|---|---|
| ||||
Posted in reply to José Armando García Sancio | > What do you all think?
All his arguments about C++ exceptions hold for plain return values, too.
| |||
July 15, 2012 Re: Creator of ZeroMQ and AMQP comments on error handling | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | On Sun, Jul 15, 2012 at 3:00 PM, Tobias Pankrath <tobias@pankrath.net> wrote:
>> What do you all think?
>
>
> All his arguments about C++ exceptions hold for plain return values, too.
>
Yes but he would said that is not the point of his article. I think his point is that if you decide not to use exception in C++, for the reason he and others have mentioned, then C++'s classes/structs become nothing more than C structs with an uglier/more verbose syntax.
I am wondering if you can extend his argument to D. Implementing RIIA becomes more verbose. The scope keyword is useless. Thoughts?
Thanks,
-Jose
| |||
July 15, 2012 Re: Creator of ZeroMQ and AMQP comments on error handling | ||||
|---|---|---|---|---|
| ||||
On Sunday, July 15, 2012 15:26:53 José Armando García Sancio wrote: > On Sun, Jul 15, 2012 at 3:00 PM, Tobias Pankrath <tobias@pankrath.net> wrote: > >> What do you all think? > > > > All his arguments about C++ exceptions hold for plain return values, too. > > Yes but he would said that is not the point of his article. I think his point is that if you decide not to use exception in C++, for the reason he and others have mentioned, then C++'s classes/structs become nothing more than C structs with an uglier/more verbose syntax. > > I am wondering if you can extend his argument to D. Implementing RIIA becomes more verbose. The scope keyword is useless. Thoughts? C++ and D are designed to use exceptions. It's virtually impossible to completely escape them. However, because D has nothrow, you can at least guarantee that your code doesn't throw them (though you still have to worry about Errors)., even if it gets ugly in some cases like constructors, forcing you to do nonsense like two-part initialization, and C++ doesn't have that. D also has stuff like scope and std.exception.collectException which can help cleanup exception-handling code quite a bit. So, D's better off than C++ is, even if the situation is similar. But I tend to disagree with anyone who argues that error codes are better. Exceptions force you to actually deal with the errors that occur, whereas error codes can easily be skipped. At least some of that complication is intrinsic to the problem, and using error codes instead of exceptions just means that you're probably not handling a lot of the errors correctly. - Jonathan M Davis | ||||
July 16, 2012 Re: Creator of ZeroMQ and AMQP comments on error handling | ||||
|---|---|---|---|---|
| ||||
Posted in reply to José Armando García Sancio | On Sunday, 15 July 2012 at 22:27:02 UTC, José Armando García Sancio wrote:
> On Sun, Jul 15, 2012 at 3:00 PM, Tobias Pankrath <tobias@pankrath.net> wrote:
>>> What do you all think?
>>
>>
>> All his arguments about C++ exceptions hold for plain return values, too.
>>
>
> Yes but he would said that is not the point of his article. I think
> his point is that if you decide not to use exception in C++, for the
> reason he and others have mentioned, then C++'s classes/structs become
> nothing more than C structs with an uglier/more verbose syntax.
>
> I am wondering if you can extend his argument to D. Implementing RIIA
> becomes more verbose. The scope keyword is useless. Thoughts?
>
> Thanks,
> -Jose
He is completely wrong.
C++ is a multiparadigm language, you can do much more than just plain OO. It is a safer language than C, while offering higher level abstractions to several programming paradigms. D as a better C++ follows these principles as well.
To this day I still don't understand why some developers prefer the pain of C to safer and more productive languages for systems programming.
--
Paulo
| |||
July 16, 2012 Re: Creator of ZeroMQ and AMQP comments on error handling | ||||
|---|---|---|---|---|
| ||||
Posted in reply to José Armando García Sancio | On Sunday, 15 July 2012 at 22:27:02 UTC, José Armando García Sancio wrote:
> On Sun, Jul 15, 2012 at 3:00 PM, Tobias Pankrath <tobias@pankrath.net> wrote:
>>> What do you all think?
>>
>>
>> All his arguments about C++ exceptions hold for plain return values, too.
>>
>
> Yes but he would said that is not the point of his article.
I read the article like this:
Exceptions are bad because they spawn "undefined behaviour", thus I don't want to use exceptions. However if I try that in a language that is designed to use exceptions, i'll run into problems.
And my thoughts about this are: The problems he seems to have with exceptions are more or less the same with error codes. So I'd say the premise of this article is wrong and the conclusion useless. But what if exception where really much worse than error codes and you want to avoid them in C++?
Yeah .. you get the same problems than in C, i.e. split initialization. So whatever happens you not worse of than in C.
And "what if developer puts code in here that my throw although he must not?" is more or less equivalent then: "What if the developer ignores all error codes ..?"
You need to play by the rules and you can't force people to do this (Java proofed this). What you need to do is to make following rules easier than breaking.
| |||
July 16, 2012 Re: Creator of ZeroMQ and AMQP comments on error handling | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Sunday, 15 July 2012 at 23:17:15 UTC, Jonathan M Davis wrote:
> C++ and D are designed to use exceptions. It's virtually impossible to
> completely escape them.
In many C++ projects, exceptions are disabled at compile time. There are only very few parts of STL which are off-limits then.
Sure, if you are using external code, it can still throw exceptions, but you have the same problem when using that piece of code from an exception-less language.
David
(this post is mainly an experiment if posting from Links works)
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply