Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I tutored a C++ beginners course on Linux a few times. I have had people ask me for help because the error messages were so long, their terminal history wasn't large enough to scroll back to the first error. Even if you have basic bash skills, just piping the compiler output to less or head also doesn't work, because the errors go to stderr. It's an incredible source of frustration for beginners.


> just piping the compiler output to less or head also doesn't work, because the errors go to stderr

|& is your friend:

g++ foo.cc |& less


How did I not know this until now. Fantastic.


Or, if you want to save the output to a log file:

    g++ foo.cpp 2>&1 | tee ./log
or, the shorthand of 2>&1 |:

    g++ foo.cpp |& tee ./log


I like to do `g++ foo.cc |& tee /tmp/out` then you can `less /tmp/out`, grep the file, open it in an editor etc.


Wouldn't it work if you did

  2>&1
as part of the redirect?


I know about that mechanism but I use it so infrequently that I have to look it up every time; the syntax doesn't really match anything else I know. It's also hard to look up because even the right search terms fetch a lot of nearby-concept results so I have to dig for the exact idea.

(Probably this is an ideal LLM question though!)


There used to be a search engine called SymbolHound whose entire shtick was to not ignore special characters in the query. Unfortunately it looks like it's gone now, seemingly without so much as a farewell. Their posts just stopped.


It seems to be part of my muscle memory.

I likely got that memorized from the time that I wrote a shell (/bin/sh) tutorial back in the day.


Yes, but most beginners have never seen (or remember) that.


Knowing about some of these shell bits would be useful for someone learning about C++.


Yes, but if someone only just learned about less and piping, they probably won't know about fd 2 being stderr, fd based redirection, and hence don't understand it at all


For my beginner programming class, I have them use a script `compile` which handles compilation and linking, while also enabling enabling all the warnings/errors I think are helpful, and also doing the above redirection. An absolute beginner doesn't gain anything from invoking `g++` directly.


> I tutored a C++ beginners course on Linux a few times. I have had people ask me for help because the error messages were so long, their terminal history wasn't large enough to scroll back to the first error.

A non-problem if you use any IDE which has been able to group error under foldable menus (such things have existed on Linux for longer than some of the people you are teaching may have been on this planet)


Konsole's default scroll-back is 1000 lines. I wonder what is the simplest, most realistic error a beginner would encounter that exceeds that?


If only there was some sort of invention that could be used to replace a virtual teletypewriter that could somehow parse the error messages and put them into a convenient list that could be navigated using simple visual paradigms instead of bits and pieces of a shell scripting engine… /s




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: