Forum > Suggestions
Not allow “do;“
Kraig:
I just spent a lot of time trying to figure out why the statement with flowpanel do was not working right, then I noticed a stray “;” after the do and removed it and now it works.
Having a semicolon after do seems to have the same effect as commenting out the entire statement containing the do.
I’d like to suggest that putting a semicolon after do should generate a compile error or at least a warning about the fact that the code is useless and will never have any affect on the statement that follows it. :o
It would also be nice if the semicolon was not automatically placed after the do in the auto completion of Lazarus ide.
Martin_fr:
You can at least get them highlighted.
Add them with no-space, one-space and two-space.
https://wiki.freepascal.org/New_IDE_features_since#Multiple_user_defined_word_highlight.2Fmarkup
https://wiki.freepascal.org/IDE_Window:_Editor_User_Defined_Words
Thaddy:
--- Quote from: Kraig on September 01, 2023, 05:25:13 pm ---I just spent a lot of time trying to figure out why the statement with flowpanel do was not working right, then I noticed a stray “;” after the do and removed it and now it works.
--- End quote ---
Stray? Of course not. That is simply programmer error. This does not warrant a warning or hint because the "stray" ; can be intentional.
And that happens very often...Intentional. (e.g. case/else)
Learn the language first. The ; simply means any code after that is not part of the evaluation.
440bx:
--- Quote from: Kraig on September 01, 2023, 05:25:13 pm ---Having a semicolon after do seems to have the same effect as commenting out the entire statement containing the do.
--- End quote ---
It doesn't comment out the entire statement. The problem is that without the statement being in a "begin"/"end" pair then the "do" executes an empty statement (which is what the ";" indicates -> an empty statement.)
--- Quote from: Kraig on September 01, 2023, 05:25:13 pm ---I’d like to suggest that putting a semicolon after do should generate a compile error or at least a warning about the fact that the code is useless and will never have any affect on the statement that follows it. :o
--- End quote ---
It would be incorrect for the compiler to generate an error because the construction "while <someboolean> do ;" is perfectly valid and sometimes _useful_. The case in which it may be useful is when the "while" expression may be changed by code that executes independently of the "while", for instance code in another thread that may be part of the program or the O/S. In that case the <expression> acts as a barrier to the execution of the code that follows it.
Considering that it is a somewhat uncommon construction, it might be reasonable for the compiler to emit a hint in that case but, it's not a really easy thing for the compiler to do because the hint would be valid only when the expression is entirely made of local variables (since those cannot be changed by external code, therefore the "while <expression> do ;" may effectively be an infinite loop (if <expression> happens to be true.)
IMO, while it would be nice to get a hint from the compiler, I would be inclined to leave the responsibility entirely on the programmer's shoulders (unless it happens to be easy for the compiler to correctly detect the case and emit the hint only when it is appropriate.)
I think @Martin_fr's suggestion to have the IDE highlight the construction is an excellent substitute for the hint you are requesting.
--- Quote from: Kraig on September 01, 2023, 05:25:13 pm ---It would also be nice if the semicolon was not automatically placed after the do in the auto completion of Lazarus ide.
--- End quote ---
If you have the IDE do auto completion for you, you have to accept that there will be times when the IDE will "complete" something in a way that is not quite the way you want. It's a downside that comes with the territory.
HTH.
Kraig:
Thanks for the answers
If I had put the “;” in there I would feel more responsible and yes it could be said that it’s my fault. However it was put there for me by the code completion which is otherwise a good feature.
Is there any way to improve the code completion to not put a semicolon everytime I have a do statement?
I don’t understand how the code completion works but surely there is a way to check if it involves a “do” and forgo the semicolon if it does. Rare instances that require a semicolon could add it. It’s much easier to add on rare occasions than remove on all occasions.
Having a choice of either no code completion or having to manually remove a semicolon that will break my code everytime I use a “do” is no fun.
Navigation
[0] Message Index
[#] Next page