Forum > Suggestions

Not allow “do;“

<< < (2/4) > >>

ASerge:

--- 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 ---
My IDE doesn't put a semicolon automatically after do, only after end.
From lazarus.dci (empty lines added by me for better visibility):

--- Code: XML  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---...[whileb | while statement]$(AttributesStart)EnableMakros=trueRemoveChar=true$(AttributesEnd)while $Param(LoopCondition) dobegin  |end$AddSemicolon() [whiles | while (no begin)]while $Param(LoopCondition) do  | [withb | with statement]...

MarkMLl:

--- Quote from: Kraig on September 02, 2023, 01:30:31 am ---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.

--- End quote ---

While few would be as gratuitously rude as Thaddy, it boils down to the fact that the checking of your code is your responsibility.

A Semicolon after do is valid:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---while somethingWithSideEffects() do ; 
although many would argue that it's bad style. Conversely, there are places where a semicolon should not be inserted (e.g. immediately before else) and places where Wirth's original definition of Pascal did not intend it to be inserted (e.g. immediately before end).

The rule is that ; is a statement /separator/ not a /terminator/, so all  do ;  does is iterate an empty statement.

Having said which, I sympathise if this really is something which was inserted by the IDE's code completion, although I've not seen that behaviour (and often disable that sort of thing anyway as intrusive and distracting). I'd suggest that you'd make life much easier for everybody if, having found something questionable like that, you explicitly said what version of Lazarus and what platform you're using just in case it's an "erratum" which has got in accidentally.

MarkMLl

Martin_fr:
You can switch of the ";" entirely

Menu: Tools > Options:
Page: Codetools > Identifier Completion
Checkbox "Add semicolon"

But then it won't add a semicolon on any completion at all.


Making is smarter, so it won't do it after "do" or "then" ... => only by changing the codetools implementation.

alpine:

--- Quote from: 440bx on September 01, 2023, 11:08:00 pm ---I think @Martin_fr's suggestion to have the IDE highlight the construction is an excellent substitute for the hint you are requesting.

--- End quote ---
I completely agree.

With autocomplete putting ';' after 'do' there is a risk to forget to insert the actual statement, with no putting ';' there is an equal risk to forget and the loop will execute the statement that follows. Where is the risk mitigation then?

When I want to put an empty statement, I usually put a comment before the ';' to indicate that the empty statement was intentional:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  while not Reply() and not Timeout() do    {wait a reply for a specified timeout}; Or at least:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  while some_condition do    {empty};
Then using the Martin_fr highlight trick is perfectly sufficient.
   

Martin_fr:
Actually, the problem IMHO is

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;var  FooBar: boolean;begin  while Foend. 
Completing "FooBar" in the above inserts a semicolon "while FooBar;". That is even before there is a "do".

That seems to be just wrong to me. And for me, it is that semicolon, that then gets pushed forward, until it is after the "do".

I don't know if there is already an issue about it... But currently there is no fix for that part.


Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version