HN user

thestoicattack

680 karma
Posts19
Comments101
View on HN

the readline keybindings come from Emacs

Because I’m a vim user, It took me a very long time to understand where these keybindings come from

libreadline supports a basic vi mode. In bash, `set -o vi` lets you use vim-style editing. It is a lifesaver.

As a note,

    find . -type f -exec grep stuff {} \;
will also invoke a new grep process for every file, which can be slow. If you think find is going to return a lot of files, it is often better to use
    find . -type f -exec grep stuff {} +  # note plus sign
which will replace {} with as many filenames as allowed (all correctly quoted, etc).

Sorry, I see I didn't answer your question. I am not one of those programmers that would deliberately ignore an error code, so I don't know what they're thinking.

My suspicion (and naive hope) is that most people would not ignore that case if they knew it was dangerous. But I would expect them to ignore it if they didn't know it existed. Hence this article, I guess, which serves to remind everyone that it can in fact happen and is quite dangerous (due to a potential later interaction with kill).

If by ignoring, you mean non catching anything, I'm often okay with that. If an exception makes it top-level, you'll get a std::terminate and be done.

The "canonical" example people use a lot is std::bad_alloc. Often, there is no point in catching it -- what cleanup or fallback work are you planning to do when you can't even allocate memory?

Of course, silently swallowing exceptions with an empty catch-block is terrible.

I agree that the result, while cool, is not readable. An obvious next step would be to demonstrate how the type-checked lambda-heavy implementation can be refactored into something that also makes sense to a human.

just because the types check out doesn't mean it's free from bugs

That's certainly true in the general case. In fact, the author gives a type-checked-but-wrong example of "we need an Int, so just return zero."

But in some specific cases, as the author writes, "One of those facts we can infer [from a type signature] is often the the only possible implementation." The article demonstrates that "possible" includes "also makes use of all the values available (or else the signature would be simpler)."

This could leak information to the other party if bailing is still available during the event. By trying to bail myself after you show up I could "prove" you really didn't want to be here after all.

So I was all set to bash include/data-swap.c for allocating on the heap every time you need to swap memory. Turns out that gcc can optimize out that temporary, and it ends up the same as std::swap.

But if we use operator new/delete instead of std::malloc the optimization doesn't take place: https://godbolt.org/z/vtxqD2

To avoid this insidious bug:

    std::lock_guard<std::mutex>(m);  // guard is immediately thrown away
versus the correct
    std::lock_guard<std::mutex> g(m);  // hold mutex til end of scope