Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: pkg/front_end/lib/src/fasta/diagnostics.md

Issue 2718023003: One shared guide for diagnostics. (Closed)
Patch Set: Fix copyright year. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/front_end/lib/src/base/errors.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!--
2 -- Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
3 -- for details. All rights reserved. Use of this source code is governed by a
4 -- BSD-style license that can be found in the LICENSE file.
5 -->
6
7 # Guide for Writing Diagnostics
8
9 ## The Rule of 3
10
11 A great message conveys the following three things:
12
13 1. What is wrong?
14 2. Why is it wrong?
15 3. How do I fix it?
16
17 ## Complete Sentences
18
19 The message should be a complete sentence starting with an uppercase letter, and ending with a period. The message shouldn't start with "error:", "warning:", an d so on.
20
21 ## Use Single Quotes in Messages
22
23 Reserved words and embedded identifiers should be in single quotes as we have fo und those are ignored by search engines whereas double quotes can have meaning i n search engines.
24
25 In practice, this means that messages written in Dart source code should be writ ten in double quotes, which makes it easier to use single quotes inside the mess age. For example:
26
27 "The class '#{className}' can't use 'super'."
28
29 Notice that the word "class" in the preceding message is not quoted as it refers to the concept *class*, not the reserved word. On the other hand, `'super'` ref ers to the reserved word. Do not quote `null` and numeric literals.
30
31 Also, remember that the output isn't Markdown, so be careful to not use Markdown syntax. In particular, do not use <code>\`</code> (backtick) for quoting.
32
33 ## Avoid Composing Messages Programmatically
34
35 Composing messages programmatically can make it hard to translate them.
36
37 ## Keep Message Short
38
39 Try to keep the error messages short, but informative.
40
41 ## Simple Words and Terminology
42
43 Use simple words and terminology.
44
45 Do not assume that
46
47 * English is the reader's native language,
48 * the reader has any formal computer science training, or
49 * the reader has an advanced degree in mathematics.
50
51 Similarly, do not use Latin abbreviations (prefer "that is" over "i.e.," and "fo r example" over "e.g."). Also avoid phrases such as "if and only if" and "iff"; that level of precision is unnecessary.
52
53 ## Prefer Contractions
54
55 Prefer contractions when they are in common use, for example, prefer "can't" ove r "cannot". Using "cannot", "must not", "shall not", and so on, is off-putting t o people new to programming.
56
57 ## Use Common Terminology
58
59 Use common terminology, for example, from the [Dart Language Specification](http s://www.dartlang.org/guides/language/spec). This increases the user's chance of finding a good explanation on the web. Do not invent your own terminology or obs cure terminology. For example, "rune" isn't a great way to describe a Unicode co de point (albeit, code points and code units can be confusing).
60
61 ## Don't Try to be Cute or Funny
62
63 It is extremely frustrating to work on a product that crashes with a tongue-in-c heek message, especially if you did not want to use this product to begin with.
64
65 ## Things Can Happen
66
67 Do not lie, that is, do not write error messages containing phrases like "can't happen". If the user ever saw this message, it would be a lie. Prefer messages like:
68
69 "Internal error: This function shouldn't be called when 'x' is null.".
70
71 ## Avoid Imperative Tone
72
73 Prefer to not use imperative tone. That is, the message should not sound accusin g or like it is ordering the user around. The computer should describe the probl em, not criticize for violating the specification. Often, it's as simple as addi ng the word "try". For example:
74
75 "Try changing the return type." // Preferred.
76
77 Versus:
78
79 "Change the return type." // Avoid this.
80
81 Notice that the style of the language in which this guide is written, is mostly imperative. That's not an example to follow when writing diagnostics.
82
83 ## Other Resources
84
85 One language and community where good error messages have been discussed intensi vely is [Elm](http://elm-lang.org/blog/compiler-errors-for-humans).
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/base/errors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698