Bug 1780150 - Reduce variables scope in methods
Summary: Reduce variables scope in methods
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: GlusterFS
Classification: Community
Component: unclassified
Version: mainline
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
Assignee: bugs@gluster.org
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-12-05 14:00 UTC by Barak Sason Rofman
Modified: 2020-01-15 10:21 UTC (History)
4 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2020-01-15 10:21:53 UTC
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Embargoed:


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.