4 ms·
I disagree with the article's conclusion. The evidence in it proves that it's better not to use the specialised functions (like any_of). It's immediately clear
by quietbritishjim 5y ago
I disagree with the article's conclusion. The evidence in it proves that it's better not to use the specialised functions (like any_of).
It's immediately clear to me what each of the find_if snippets does, but I haven't heard of the other functions – and the evidence from the article is that the vast majority of other programmers haven't either (in fact that's out of the subset that bother to use find_if, which I would say means even less of general coders). Sure, it's fairly obvious what they do from the name, but I'd still bother to check their signature in case there's a subtlety. In other words, there may be fewer lines of code, but it's still more cognitive overhead.
In fact I'd go one step further and say it's better to use raw primitives, like for loops (range based where appropriate), where they don't need too much extra code.
- leetcrew 5y agoit seems like your argument boils down to "I prefer a for loop because I'm more familiar with it". if that's true of you and most of the people you work with, that's certainly a valid argument. the opposite happens to be true on my team. we understand and prefer the functions from the algorithms header in most cases. one argument in favor of functions like any_of is that, once you get familiar with them, they provide additional documentation of intent. I'll concede this is a pretty minor benefit; most uses of any_of replace a pretty simple loop.
- quietbritishjim 5y ago> it seems like your argument boils down to "I prefer a for loop because I'm more familiar with it". I don't think that's it. A lot of code ends up being calls to functions, and so other types of syntax add a bit of texture. Replacing those with function calls too reduces the code to a smooth paste. It's a bit like if the standard library had a lessThanThree(x) function; it doesn't matter how totally familiar I was with it, I'd still prefer to see x<3.