Either change the way this works or cause compiler warning

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Either change the way this works or cause compiler warning

Post by Joakim Christiansen »

The code below will to most coders be quite confusing, this is because this line

Code: Select all

myArray(myRandom(9)) + 1
actually calls the function myRandom() two times.

My suggestion is either that the compiler is changed so this can not occur or that it gives the user a compiler warning informing that this may cause a unexpected result.

This is previously discussed here:
http://www.purebasic.fr/english/viewtop ... =4&t=34908

Code: Select all

EnableExplicit

Procedure myRandom(number)
  number = Random(number)
  Debug "random number generated = "+Str(number)
  ProcedureReturn number
EndProcedure

Define Dim myArray(9), i, x
For i=0 To 9
  myArray(i) = i
Next

RandomSeed(0)
x = myRandom(9)
Debug "Expected output: "+Str(myArray(x)+1)

RandomSeed(0) ;give it the same starting point as above
myArray(myRandom(9)) + 1
Debug "Actual output: "+Str(myArray(x))
I like logic, hence I dislike humans but love computers.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Either change the way this works or cause compiler warni

Post by luis »

I don't like how it was implemented either -> http://www.purebasic.fr/english/viewtop ... 95#p390395

The explanation in the manual also as far as I can tell isn't changed -> http://www.purebasic.fr/english/viewtop ... 30#p392530

Before adding any more warning, I would like some more control for them to make them useful and not annoying -> http://www.purebasic.fr/english/viewtop ... 47#p401547

For now, warnings just continue to be repeated, all, at every compilation. So I'm totally against any more warning until this changes -> http://www.purebasic.fr/english/viewtop ... =3&t=53421 or the popping message boxes are converted to simple lines in the log.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply