This is an archive of the discontinued LLVM Phabricator instance.

Refactor: Simplify boolean conditional return statements in lib/Edit
AbandonedPublic

Authored by LegalizeAdulthood on May 25 2015, 1:19 PM.

Details

Summary

Use clang-tidy to simplify boolean conditional return statements

Diff Detail

Event Timeline

LegalizeAdulthood retitled this revision from to Refactor: Simplify boolean conditional return statements in lib/Edit.
LegalizeAdulthood updated this object.
LegalizeAdulthood edited the test plan for this revision. (Show Details)
LegalizeAdulthood added a subscriber: Unknown Object (MLST).

I like the idea of all of these changes (this change list and the others), but just a suggestion -- it looks like when the branch of the original condition returns false, as was the case in the original code here, the internal expressions of the check are transformed via De Morgan's laws in the new code. IMO, this transformation sometimes makes things more complicated rather than less, where by "more complicated" I mean that the transformation produces an overall expression that is constructed from a considerably greater number of logical operations. For instance, here it changed a bunch of || expressions into a bunch of && expressions, with each operand individually prefixed with "!". The equivalent without having applied De Morgan's laws would just have left all of the || expressions as-is and added a single ! around the overall expression parenthesized. It would have also looked much more similar to the original code.

My general thought here is that it might make sense when performing this kind of transformation to first see if the translation via De Morgan's laws actually produces an overall expression that has fewer logical subexpressions, otherwise prefer the minimal transformation of a ! around a parenthesized expression.

dblaikie added inline comments.
lib/Edit/RewriteObjCFoundationAPI.cpp
634

Looks like a chain (see prior review on your changes for more detail on what I mean by this)

Update from latest.
I do not have commit access.

I like the idea of all of these changes (this change list and the others), but just a suggestion -- it looks like when the branch of the original condition returns false, as was the case in the original code here, the internal expressions of the check are transformed via De Morgan's laws in the new code. IMO, this transformation sometimes makes things more complicated rather than less, where by "more complicated" I mean that the transformation produces an overall expression that is constructed from a considerably greater number of logical operations. For instance, here it changed a bunch of || expressions into a bunch of && expressions, with each operand individually prefixed with "!". The equivalent without having applied De Morgan's laws would just have left all of the || expressions as-is and added a single ! around the overall expression parenthesized. It would have also looked much more similar to the original code.

My general thought here is that it might make sense when performing this kind of transformation to first see if the translation via De Morgan's laws actually produces an overall expression that has fewer logical subexpressions, otherwise prefer the minimal transformation of a ! around a parenthesized expression.

This should be addressed in the latest diff.

LegalizeAdulthood abandoned this revision.Feb 19 2016, 9:20 AM