[DiscordArchive] I have some questions that I don't quite understand, so I hope your guys won't laugh at me. just I d
[DiscordArchive] I have some questions that I don't quite understand, so I hope your guys won't laugh at me. just I d
Archived author: leewheel • Posted: 2025-01-23T05:01:39.497000+00:00
Original source
I have some questions that I don't quite understand, so I hope your guys won't laugh at me. just I don't know if anyone can explain my doubts.For example,
``` if (channelName.size() >= 100 || !DisallowHyperlinksAndMaybeKick(channelName))
{
return;
} ```
I think code like this is more standardized and correct, but why do I often see new code being submitted like this?
```
if (channelName.size() >= 100 || !DisallowHyperlinksAndMaybeKick(channelName))
return;
```Does it make the execution more efficient?
Archived author: leewheel • Posted: 2025-01-23T05:03:02.574000+00:00
Original source
Personally, I think the first one is more in line with the regulations, and should not be any different from the second one in terms of execution efficiency.
Archived author: leewheel • Posted: 2025-01-23T05:06:35.751000+00:00
Original source
Possible disadvantages:
Error prone: After removing the curly braces, if you modify the code later and add more statements, you may forget to add the curly braces, resulting in logical errors. For example, the following code may go wrong when modified:
```if (channelName.size() >= 100 || !DisallowHyperlinksAndMaybeKick(channelName))
return;
DoSomethingElse();//This should be executed outside the if statement, but due to the lack of curly braces, it becomes part of the if statement.
```
Archived author: Honey • Posted: 2025-01-23T05:09:39.058000+00:00
Original source
As far as I remember, parentheses aren't enforced for a single line of code in an if block.
There's no difference in performance.
Archived author: leewheel • Posted: 2025-01-23T05:31:42.452000+00:00
Original source
In the case where there is no difference in performance, I think adding brackets will be more standardized and avoid errors
Archived author: Kitzunu • Posted: 2025-01-23T05:32:16.496000+00:00
Original source
No, it is just bloating the files. And thus we have decided that oneline if statements do not use curlies
Archived author: leewheel • Posted: 2025-01-23T05:33:18.075000+00:00
Original source
then ```if (channelName.size() >= 100 || !DisallowHyperlinksAndMaybeKick(channelName)){return;}```
Archived author: Kitzunu • Posted: 2025-01-23T05:34:19.525000+00:00
Original source
Just follow the guidelines we have
Archived author: leewheel • Posted: 2025-01-23T05:35:06.591000+00:00
Original source
Just my personal opinion, don't make fun of me because I'm a newbie