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

[Improvement]: Change bal add generated code to adhere to best practices #41775

Closed
gayaldassanayake opened this issue Nov 28, 2023 · 1 comment · Fixed by #42136
Closed

[Improvement]: Change bal add generated code to adhere to best practices #41775

gayaldassanayake opened this issue Nov 28, 2023 · 1 comment · Fixed by #42136
Assignees
Labels
Area/CLI Ballerina CLI related issues. good first issue Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Improvement

Comments

@gayaldassanayake
Copy link
Contributor

Description

The current generated code when we add a module using bal add looks like,

public function hello(string name) returns string {
    if !(name is "") {
        return "Hello, " + name;
    }
    return "Hello, World!";
}

Describe your problem(s)

How ever it is not the best practice to use a NOT to negate the name is "".

Describe your solution(s)

Instead, we should use if name !is "" there.

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@gayaldassanayake gayaldassanayake added Type/Improvement Area/CLI Ballerina CLI related issues. good first issue Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) labels Nov 28, 2023
@ShammiL ShammiL self-assigned this Feb 9, 2024
@ShammiL ShammiL moved this to In Progress in Ballerina Team Main Board Feb 9, 2024
@ShammiL
Copy link
Contributor

ShammiL commented Feb 9, 2024

Replaced the existing generated code with the below as passing a nil value instead of an empty string is encouraged in Ballerina.

public function hello(string? name) returns string {
    if name !is () {
        return "Hello, " + name;
    }
    return "Hello, World!";
}

Fixed in #42136

@ShammiL ShammiL moved this from In Progress to PR Sent in Ballerina Team Main Board Feb 9, 2024
@github-project-automation github-project-automation bot moved this from PR Sent to Done in Ballerina Team Main Board Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/CLI Ballerina CLI related issues. good first issue Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Improvement
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants