Allow optional parentheses #4760
Replies: 5 comments
-
I noticed that it's no problem for if-statments. // this is ok
for (!rl.WindowShouldClose()) {
// ...
} This makes the traditional for-loop not supporting parentheses feel inconsistent. |
Beta Was this translation helpful? Give feedback.
-
Corsin escribió/skribis/wrote/scrit (2025-02-06T02:58:10-0800):
I noticed that it's no problem for if-statments.
Also, with some for-loops you can also use parentheses:
```odin
// this is ok
for (!rl.WindowShouldClose()) {
// ...
}
```
This makes the traditional for-loop not supporting parentheses feel inconsistent.
Those unnecessary parenthesis are part of their corresponding boolean
expression. Therefore there's no inconsistency: parenthesis are not
syntax of the `if` and `for` structures.
…--
Marcos Cruz
http://programandala.net
|
Beta Was this translation helpful? Give feedback.
-
@programandala-net Sure, makes sense! I thought that might be the reason. But regardless of whether or not the parentheses are a part of the boolean expression, I think it should be possible to add optional parentheses. This would also allow people do this, which I know some people (not me) prefer in some cases: for (
i := 0;
i < 10;
i += 1;
) {
// ...
} |
Beta Was this translation helpful? Give feedback.
-
Corsin escribió/skribis/wrote/scrit (2025-02-06T08:22:33-0800):
This would also allow people do this, which I know some people (not me) prefer in some cases:
```odin
for (
i := 0;
i < 10;
i += 1;
) {
// ...
}
```
Well, this is possible:
```odin
for
i := 0;
i < 10;
i += 1
{
// ...
}
```
I find the Odin syntax very practical and beautiful because of its
extraordinary combination of conciseness (including absence of
unnecessary parentheses) and flexibility.
…--
Marcos Cruz
http://programandala.net
|
Beta Was this translation helpful? Give feedback.
-
Corsin escribió/skribis/wrote/scrit (2025-01-25T08:50:34-0800):
I think it'd be nice if it were allowed to use parentheses around the
components of a for-loop, if-statement, etc..
I could use `ci)` for example to clear the contents of the parenthesis
and instantly start rewriting.
I have used first Vim and then Neovim, my current editor of choice, for
many years. The key mapping you mention is very useful, but you have
alternatives. For example, you can just position the cursor after `if`
or `for` with a few keypresses and then press `d/{<Enter>` to delete
until the brace. In fact you can configure your own ad hoc key mapping
for those cases.
That is simpler than allowing unnecessary parentheses in the language
just to make it easier to delete their contents with a default key
mapping of a certain editor.
…--
Marcos Cruz
http://programandala.net
|
Beta Was this translation helpful? Give feedback.
-
I think it'd be nice if it were allowed to use parentheses around the components of a for-loop, if-statement, etc..
Within Vim, I find things like parentheses and braces very useful for navigating around or editing the code.
I could use
ci)
for example to clear the contents of the parenthesis and instantly start rewriting.Was there a specific reason for disallowing parenthesis?
How do other people feel about this?
Beta Was this translation helpful? Give feedback.
All reactions