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

Could you consider removing the semicolons at the end of the lines #870

Open
gitchc opened this issue May 8, 2024 · 5 comments
Open

Could you consider removing the semicolons at the end of the lines #870

gitchc opened this issue May 8, 2024 · 5 comments

Comments

@gitchc
Copy link

gitchc commented May 8, 2024

Could you consider removing the semicolons at the end of the lines or make them optional?
While adding semicolons can make the code appear more rigorous, for a scripting language, ease of use might be more important. Like Python or JavaScript do not require them. hope you can take this into consideration

@gitchc
Copy link
Author

gitchc commented May 8, 2024

Or consider making it a parameter that can be freely chosen, so that scripts written in other languages can switch over at a relatively low cost

@schungx
Copy link
Collaborator

schungx commented May 8, 2024

JavaScript's semicolon omission is known to cause very subtle bugs and is generally considered a bad idea.

Python I believe is line-based so that a line break sort of acts as a semicolon?

Rhai is not line-based so it continues to the next line, there must be a deterministic way for the parser to decide whether it is the end of the statement, or the next token is part of the current statement.

A typical scenario:

let a = foo; +b

let a = foo
+b

@gitchc
Copy link
Author

gitchc commented May 9, 2024

What I actually want to express is that omitting semicolons can make scripts more user-friendly, although it might also introduce some minor issues. Like JavaScript and Python, also like Groovy. There seems to be an tacit agreement that diminishes the importance of semicolons. Regarding the issue you mentioned earlier, if parsing is done on a line-based; and if there is a start with ([{, it might be possible to treat the related code as a single line by closing it appropriately, maybe a solution. Just a suggestion

@Crazy-Bunny
Copy link

As we know, languages like Python, Shell, etc., typically don't require semicolons at the end of statements, and in JavaScript, semicolons are also optional. RhaiScript as a scripting language, adhere to the same guideline and provide semicolons as an optional feature to developers? This would greatly help in replacing our existing projects with RhaiScript

@schungx
Copy link
Collaborator

schungx commented May 9, 2024

Well, whitespace-significant languages like Python use whitespace to provide structure so a line break acts as a form of statement delimiter.

C-type languages are not whitespace significant and so they form blocks with braces, instead of indentation like Python. Rhai is a C-style language (so is Java, C#, Rust, Go etc).

These two styles are quite different... Would you be content to have no semicolons but requiring braces to form blocks?

Because the way of defining blocks for both styles are different.

I believe it would be relatively easy to provide a no-semicolon option, but very difficult to avoid braces to delimit blocks. I can, though, change it to begin and end.

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

No branches or pull requests

3 participants