0

What recommended Dart style guide?

  1. Ending the exception messages with a period
  2. Not ending the exception messages with a period
  3. It's a matter of taste

In the Dart SDK I found that some messages (even inside the same error/exception class implementation) used the different styles (with and without a period sign at the end of text message).

Which style should I use?

P.S.

If I correctly understand (according to the implementation of the "dart:core" error classes in the Dart SDK) then I should follow the option #3 (It's a matter of taste).

Here is the link to the same question about C#. Do you end your exception messages with a period?

I ask this question (this is an answer to the Günter Zöchbauer comment) on the Stack Overflow but not on the Dart Issue Tracker because I think that my question and C# question (mentioned above) both are good questions.

They should help in practice write source code (at least error messages) better.

Community
  • 1
  • 1
mezoni
  • 10,684
  • 4
  • 32
  • 54
  • What's the actual question? Do you need guidance whether you should put a point at the end of a sentence or is this a complaint about the Dart style guide not including a rule for this mindblowing problem? In the 2nd case you could just create an issue at http://github.com/dart-lang/www.dartlang.org. – Günter Zöchbauer Feb 14 '15 at 10:44
  • @GünterZöchbauer: What is your problem Günter Zöchbauer? This is a perfect question and the perfect answer for C#: http://stackoverflow.com/questions/1136829/do-you-end-your-exception-messages-with-a-period. I answer to you. Creating issues on the Dart issues trackers are sometimes useless because Dart developers even does not have a time on the quality development. Where they will take free time to answer on actual questions? Should I correct my main question specilaly for you, the the your better undestanding? – mezoni Feb 14 '15 at 11:18

1 Answers1

3

There is no strict rule, mainly because nobody has reported it as a problem.

Personally I'd go for: If it's a sentence, use a full stop. If it's a non-sentence message, feel free to omit punctuation.

Errors are likely to go uncaught, so a readable error message makes it more clear to the programmer (and possibly to the end user) what went wrong. The programmer probably didn't expect anything to be thrown, and needs to be told what the program is doing wrong. Look at how it is printed in the terminal when the program crashes. If it reads better with a full stop, then by all means add it. That's usually the case for sentences.

Exceptions are expected to be caught and handled, so human readable text is only really needed in case you forget to catch it, and just "Uncaught: FooException" + stacktrace is probably fine for that. The programmer can see that an exception is thrown, so it's just a matter of seeing which function is documented as throwing that exception, and then handling the exceptional case.

lrn
  • 64,680
  • 7
  • 105
  • 121