Share good error reading habits

###Hi, Programmers and Developers!

**Errors are really annoying after editing source code.** Badly, for a complete awareness of errors, compiler or some interpreter is obliged to feedback *every detail* in its error report. If it reports about 10+ lines, it is becoming annoying as error itself.

**Errors are inevitable, at least for beginners.** For example, when my classmate demonstrate a C++ snippet in the old version of *MSVC++ 6. 0*, for some reason, 18 errors pop out on the screen, which make everyone insane. Moreover, semi-programmers borrow and modify code in the modern time, such as in the area of physics, chemistry or math. They are afraid of huge amount of errors too. They, including me, need to know what hell is the error-feedback really talking about **in one sentence**.

**How to read errors and make use of it for us?** Taking C++ as an example, how to address one sentence
error feedback?

- Firstly, if error exsits, output the error into a file, in linux, we can say,

`g++ -g -Wall -o executable main.cpp 2> Compile_Error`

- Then, extract lines that only contain keyword like "error", in linux, we can say,

`cat Compile_Error | grep -in error`.

- Finally, modify the source code and continue doing this.

In this way, we can resolve some non-intelligent errors very quickly by reducing every error item into one line. Similarly, **is there any more suggestion on how to reduce C++ error information from compiler like g++/gcc into less lines so that errors are explicitly located?**
is there any more suggestion on how to reduce C++ error information from compiler like g++/gcc into less lines so that errors are explicitly located?
Use clang, it has better error reporting.

Use IDE which extracts error information (and allows neat things like jumping to the line containing error)

18 errors pop out on the screen, which make everyone insane
Backward port from C++11 to C++03 reporting:
Build finished: 1587 errors, 10328 warnings
Thank you.

Build finished: 1587 errors, 10328 warnings

That's insane. It would feel much relief, when 1000+ errors can be categorized into much less error types.
It doesn't matter how many errors you see, most of them are consequences of earlier errors. So only fix the first one or two and recompile. They'll disapper very quickly.
> `cat Compile_Error | grep -in error`
useless cat
$ grep -in error Compile_Error

Or you could avoid the intermediate file
$ g++ -g -Wall -o executable main.cpp 2>&1 | grep -in error



By the way, apart from -Wall also use -Wextra and -Wpedantic. (and read the warnings, your commands are suppressing them)
Last edited on
@ne555
+1
Good suggestion for one-liner.
@kbw You are right. Many errors are subordinative.
g++ -g -Wall -o executable main.cpp 2> Compile_Error

If you only want to see the errors then why are you generating all the warnings?
Hey;
Thumb rule is treat your warnings as errors.
Make sure you have 0 errors and 0 warnings.

Use some SCA (Static code analysis tool) to fix hidden warnings and erors.
if you are using VS,
VS 2012 have inbuilt SCA for both managed and unmanaged code.

After SCA do a self code review, whether one line or 100 lines of code followed by a 2nd person review whether changed a code or comment.
This will ensure that the file changed has not introduced new errors or warnings.

After review a self testing of the written code vs tthe requirement that you have worked for.
**Errors are really annoying after editing source code.**

Who says they are annoying.

Perhaps it's better to be grateful for every error message or warning issued by the compiler, as it is providing valuable assistance in avoiding certain flaws or defects. The compiler is there to help you write good-quality code, not an obstacle placed in your path.
@Chervil Of course. We learn from errors. Your are right. That's why I want to make better use of it by focusing only on errors. My real concern is about the way how error is presented. The g++ error presentation is a little more than annoying. That's why I need to filter error message myself. Sorry for not expressing it explicitly.
Last edited on
@dhayden
Sometimes I want to see warnings.
@Rabindra Hota
It is true and this is a good habit.
Topic archived. No new replies allowed.