Skip to content

Decompiler: Enhancing Code Readability and Control Flow With Inverted Ifs #6014

@pinwhell

Description

@pinwhell

Sometimes, it'd be awesome to have a way to see the code flow in other ways. It'd be neat if we could, for instance, invert the ifs to transform regular if-statements into early returns or guard clauses. it could be cool to have a feature to invert the logic of ifs, causing the content inside them to fall outside.

For instance, take a look at this piece of code:

if (condition1()) {
    if (condition2()) {
        if (condition3()) {
            // Logic after all conditions are met
            std::cout << "All conditions met!" << std::endl;
            return;
        }
    }
}

by the if for the condition1 if woud look like this:

if (!condition1())
    return;
    
if (condition2()) {
    if (condition3()) {
        // Logic after all conditions are met
        std::cout << "All conditions met!" << std::endl;
        return;
    }
}

or inverting all the ifs would look like this:

if (!condition1())
    return;
    
if (!condition2()) 
    return;
    
if (!condition3()) 
    return;
    
// Logic after all conditions are met
std::cout << "All conditions met!" << std::endl;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions