This is an archive of the discontinued LLVM Phabricator instance.

[Docs] CodingStandards: for_each is discouraged
ClosedPublic

Authored by lebedev.ri on Jul 8 2020, 3:00 PM.

Details

Summary

As per disscussion in D83351, using for_each is potentially confusing,
at least in regards to inconsistent style (there's less than 100 for_each
usages in LLVM, but ~100.000 for range-based loops

Therefore, it should be avoided.

Diff Detail

Event Timeline

lebedev.ri created this revision.Jul 8 2020, 3:00 PM
hubert.reinterpretcast added inline comments.
llvm/docs/CodingStandards.rst
1305

Even if what's available in the context of the code is a pair of iterators and a callable (and using a range-based for loop would involve extra boilerplate)?

lebedev.ri added inline comments.Jul 8 2020, 3:20 PM
llvm/docs/CodingStandards.rst
1305

That is my understanding, yes.

As per lengthy/heated disscussion in D83351,

Probably could drop those adjectives. =P Also, s/disscussion/discussion/.

using for_each is potentially confusing,

I guess @dblaikie did use the term confusing, but it might be useful to better reflect his point about confusion in regards to inconsistent style in the commit message. It certainly begs the question otherwise.

llvm/docs/CodingStandards.rst
1305

it might be useful to provide more information here.

Use of X is discouraged because ...

IIUC @dblaikie 's points in https://reviews.llvm.org/D83351#2139727 and https://reviews.llvm.org/D83351#2139861 were that:

  1. more concise error messages.
  2. more concise unless an existing function/method/lambda already exists.

I love functional programming styles, but if an inline lambda definition isn't shorter than a range-for, I agree with @dblaikie and feel a lambda is overkill.

lebedev.ri edited the summary of this revision. (Show Details)Jul 8 2020, 3:35 PM
lebedev.ri edited the summary of this revision. (Show Details)Jul 8 2020, 3:37 PM
lebedev.ri updated this revision to Diff 276585.Jul 8 2020, 3:41 PM

It's okay if no new labmbda is needed though.

llvm/docs/CodingStandards.rst
1305

I'm not really sure i understand the point about error message.
Is this better?

nickdesaulniers accepted this revision.Jul 8 2020, 3:47 PM
This revision is now accepted and ready to land.Jul 8 2020, 3:47 PM

@dblaikie does this look like the wording you'd expect?

@dblaikie does this look like the wording you'd expect?

Yep, looks alright, thanks!

dblaikie accepted this revision.Jul 9 2020, 12:59 PM
llvm/docs/CodingStandards.rst
1306

Typo: s/the the/if the/;