Bug 1780150

Summary: Reduce variables scope in methods
Product: [Community] GlusterFS Reporter: Barak Sason Rofman <bsasonro>
Component: unclassifiedAssignee: bugs <bugs>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: mainlineCC: bugs, pasik, sabose, sankarshan.mukhopadhyay
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-01-15 10:21:53 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Barak Sason Rofman 2019-12-05 14:00:30 UTC
Description of problem:
In many methods, variables have greater scope then required.
An example:

void foobar(...) {
    int res;
    int foo;

    res = ...
    if(!res) {
        foo = ...
    }
}

This can be modified to:
void foobar(...) {
    int res;

    res = ...
    if(!res) {
        int foo;
        foo = ...
    }
}

Actual results:
In the current state, encapsulation is adversely affected by inappropriate variables scope.

Expected results:
Variables should have "minimum viability" scope in order to enforce encapsulation.

Additional info:
Modifying this should be an ongoing effort and not focused on solely.

Comment 1 sankarshan 2019-12-23 04:38:01 UTC
Is there a list of such instances which can be referred to for continual work on the topic reported?

Comment 2 Barak Sason Rofman 2019-12-26 14:30:30 UTC
(In reply to sankarshan from comment #1)
> Is there a list of such instances which can be referred to for continual
> work on the topic reported?

I can not provide such a list, because this is something that present all over the code. Almost every method in the code behaves in this manner.
I believe that the best way to address this is keep this in mind and try to change this in whatever method we change in the ongoing patches.

Comment 3 Barak Sason Rofman 2020-01-15 10:21:53 UTC
This type of work should be performed in the scope of Bug 1193929 - GlusterFS can be improved.
Closing this.