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

Include the best practice for documenting a Ballerina record in the style guide #8929

Open
nipunayf opened this issue Apr 19, 2024 · 0 comments
Labels
Area/LearnPages Issues related to all the pages of the Learn section. Category/Content All written content related issues (Technical content, english language etc) Type/Improvement Improvements required on the website.

Comments

@nipunayf
Copy link
Contributor

Description

ATM, the style guide does not specify what the best practice is for documenting a record: https://ballerina.io/learn/style-guide/annotations-documentation-and-comments/#documentation. Currently, there are two approaches to document a record.

  1. Attach the documentation at the top of the type.
# Represents a user.
#
# + id - id of the user
# + name - name of the user  
# + isMember - whether the user is a member
type User record {|
    int id;
    string name;
    boolean isMember;
|};
  1. Include the documentation along with the record field.
# Represents a user.
type User record {|
    # Id of the user
    int id;
    # Name of the user
    string name;
    # Whether the user is a member
    boolean isMember;
|};

The latter approach is used as a best practice within the Ballerina team. Even with the considered approach, it is yet unclear whether to leave a space between the fields for better readability. IMO, when a node has more metadata, having a space in between can enhance the readability of the code.

// Approach 1: Without the spaces in between
# Represents a user.
type User1 record {|
    # Id of the user
    @constraint:Int {
        maxDigits: 10
    }
    int id;
    # Name of the user
    @constraint:String {
        minLength: 5,
        maxLength: 20
    }
    string name;
    # Address of the user
    @constraint:String {
        minLength: 20,
        maxLength: 100
    }
    string address;
|};


// Approach 2: With the spaces in between
# Represents a user.
type User2 record {|
    # Id of the user
    @constraint:Int {
        maxDigits: 10
    }
    int id;

    # Name of the user
    @constraint:String {
        minLength: 5,
        maxLength: 20
    }
    string name;

    # Address of the user
    @constraint:String {
        minLength: 20,
        maxLength: 100
    }
    string address;
|};
@nipunayf nipunayf added Type/Improvement Improvements required on the website. Area/LearnPages Issues related to all the pages of the Learn section. Category/Content All written content related issues (Technical content, english language etc) labels Apr 19, 2024
@nipunayf nipunayf changed the title Include the best practice for documenting Ballerina record in the style guide Include the best practice for documenting a Ballerina record in the style guide Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/LearnPages Issues related to all the pages of the Learn section. Category/Content All written content related issues (Technical content, english language etc) Type/Improvement Improvements required on the website.
Projects
None yet
Development

No branches or pull requests

1 participant