Roman Yankovsky Thanks. I ask because this issue cropped up on SO with a user getting the same warning from Peganza.
It got me thinking about the nature of loops. And a thread here yesterday got me thinking more about it. Eric made a good point about ordering. A for loop implies an ordering. In the simple loop I presented above, ordering is not irrelevant. But the simplest language feature we have for unordered repetition is the for loop, which is ordered.
There is no better solution than to just not use the loop variable performance wise. Of course we can come up with all fancy ideas that involve creating iterators and passing anonymous methods and that but at the end of the day we just had an effing variable that was not used inside the loop which only FixInsight complained about ;)
FWIW it should be possible to just omit the variable in the loop and write - that would be the cleanest solution I can think of (similar to scala where the syntax (x to y) represents a range): for 1 to 10 do ...
oh and while improving that syntax also add the step size to the loop so I can write for 1 to 100 step 3 do ;)
How about running it on the rtl & vcl. I ran it on the rtl, found a couple of issues that looked like bugs. Couldn't find any dpk's for the vcl and FI needs a project to run.. would be good to be able to just point it at a folder.
David Heffernan I have no idea what Vincent Parrett is running but it could be that Vincent would like to see if anything has been fixed since the initial test, compared to update #1... ?
Nicholas Ring I could just create my own dpk's, but I have better things to do! David Heffernan thx, didn't see the links, read the post on my phone pre-coffee and without glasses!
This really points out the value of FixInsight!
ReplyDeleteThanks, Lars Fosdal :)
ReplyDeleteRoman Yankovsky Good work. It saddens me that bugs don't get fixed even after they have been pointed out. I wish Emba were more committed to quality.
ReplyDeleteNow an aside. What would you do about a loop like this?
for i := 1 to 10 do
List.Add(Random());
Would that result in W528? And if so, is it possible to suppress locally?
David Heffernan the answer is "Yes" on both questions :)
ReplyDeleteYes, that would result in W528. And yes, you can suppress it locally using a special comment.
For instance, this will not result in W528:
for i := 1 to 10 do //FI:W528
List.Add(Random());
Roman Yankovsky Thanks. I ask because this issue cropped up on SO with a user getting the same warning from Peganza.
ReplyDeleteIt got me thinking about the nature of loops. And a thread here yesterday got me thinking more about it. Eric made a good point about ordering. A for loop implies an ordering. In the simple loop I presented above, ordering is not irrelevant. But the simplest language feature we have for unordered repetition is the for loop, which is ordered.
Anyway, looks like FI has this one covered.
FixInsight could ignore this when the loop variable is called _
ReplyDeleteSee http://stackoverflow.com/questions/3685974/python-iterate-a-certain-number-of-times-without-storing-the-iteration-number-a
P.S. I am not completely serious. Personally I would not call this loop variable _
Roman Yankovsky I love these blogs - want more!! :-D
ReplyDeleteSad that Emb didn't fix these bug
ReplyDeleteDavid Heffernan The correct way would be to use an enumerator returning random numbers and then use for..in with Take (rng, 10) or equivalent.
ReplyDeleteAsbjørn Heid Wrong post?
ReplyDeleteStefan Glienke My suggestion would generate 10 random numbers without the unnecessary loop counter, which is what David asked for in his follow-up no?
ReplyDeleteIt was also slightly tongue-in-cheek by claiming it to be "the correct" way.
ReplyDeleteThere is no better solution than to just not use the loop variable performance wise. Of course we can come up with all fancy ideas that involve creating iterators and passing anonymous methods and that but at the end of the day we just had an effing variable that was not used inside the loop which only FixInsight complained about ;)
ReplyDeleteFWIW it should be possible to just omit the variable in the loop and write - that would be the cleanest solution I can think of (similar to scala where the syntax (x to y) represents a range):
for 1 to 10 do ...
oh and while improving that syntax also add the step size to the loop so I can write for 1 to 100 step 3 do ;)
do 3 times
ReplyDeletebegin
end :)
How about running it on the rtl & vcl. I ran it on the rtl, found a couple of issues that looked like bugs. Couldn't find any dpk's for the vcl and FI needs a project to run.. would be good to be able to just point it at a folder.
ReplyDeleteVincent Parrett If you follow the links from the article you can see that Roman already did just that.
ReplyDeleteGood job.
ReplyDeleteDavid Heffernan I have no idea what Vincent Parrett is running but it could be that Vincent would like to see if anything has been fixed since the initial test, compared to update #1... ?
ReplyDeleteVincent Parrett Couldn't you mock up a dummy dpk/dpr for the units you want checked?
ReplyDeleteIf only Embarcadero ... err... Idera checked the whole RAD Studio codebase with FixInsight!
ReplyDeleteIlya S Come on... give Idera a break. They have only just got their new toy and still playing with it to see what it can do.
ReplyDeleteI am more than happy to pass the blame to Idera but I won't do that until after the next release at the earliest.
Nicholas Ring I could just create my own dpk's, but I have better things to do! David Heffernan thx, didn't see the links, read the post on my phone pre-coffee and without glasses!
ReplyDeleteVincent Parrett Don't we all :-)
ReplyDeleteSimon Stuart Welcome back!
ReplyDelete