Skip to content

DRY-Code. #1

@TrishamBP

Description

@TrishamBP

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions