Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRY-Code. #1

Open
TrishamBP opened this issue Feb 2, 2022 · 0 comments
Open

DRY-Code. #1

TrishamBP opened this issue Feb 2, 2022 · 0 comments

Comments

@TrishamBP
Copy link

Hi, the implementation of your logic is excellent, I had some suggestion tho. While adding participants I see that you call/define a function every time. I have some improvements on your code which will make it follow the DRY principle. Right now there is a lot of repetitive code which does not make your code dry and difficult to comprehend easily. Instead o specifying so many functions why don't you try using a single function

// Participant Characteristic.
    struct participant {
        string userName;
        string password;
        string participantType;
        address participantAddress;
    }
    mapping(uint32 => participant) public participants;

function addParticipant(
        string memory _name,
        string memory _pass,
        address _pAdd,
        string memory _pType
    ) public returns (uint32) {
        uint32 userId = participant_id++;
        participants[userId].userName = _name;
        participants[userId].password = _pass;
        participants[userId].participantAddress = _pAdd;
        participants[userId].participantType = _pType;

        return userId;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant