Page 1 of 1

Helpfile - specify the actual DATATYPE instead of "a number"

Posted: Thu Sep 03, 2015 8:45 am
by Keya
In just about every page of the helpfile for Return Value it simply says something like "The return value is a number".

I find this vagueness perplexing because I don't see it being any harder to document whether this "number" is a "Long", "Quad", hybrid 32/64 "Integer", or otherwise, and it's simply asking for trouble forcing the programmer to guess or wasting their time forcing them to experiment/disassemble if they need to be pushing 32 or 64bits onto the stack. Likewise there's no mention of signed or unsigned. This is what documentation is for, and it when it comes to the datatype being returned I thought this was fundamental in getting the code right!?

And no you certainly can't "just use Integer for everything" - FileSize() for one example always needs a Quad, and never a Long or Integer if you always want correct results on both x86 & x64, but the PB compiler will let you use a Long with FileSize(), and it'll usually work until you try a 4GB+ file, in which case it'll either crash or return invalid result.

Try OpenFile() with a Long in Windows-32 and it'll work, again the compiler won't complain or give you a hint, but your code will crash in 64bit Mac and Linux - the handle needs to be hybrid Integer.

How many of these .Q's, .L's, and .I's i've gotten wrong in my source code I have no idea for these reasons, and I'm forced to assume that "if it doesn't crash i've probably chosen the right one"... yet impossible to be confident. :(

Re: Helpfile - specify the actual DATATYPE instead of "a num

Posted: Thu Sep 03, 2015 8:49 am
by Fred
The helpfile should already tells which type is expected if it's not integer:

http://www.purebasic.com/documentation/ ... esize.html

About compiler complaining, may be a warning would be handy, yes. But that means than every affectation which won't fit in destination will raise a warning which can be painful if you actually know what you are doing.

Re: Helpfile - specify the actual DATATYPE instead of "a num

Posted: Thu Sep 03, 2015 8:51 am
by Keya
i picked a bad example in Filesize() as its documentation does say "Result.q =" for usage, but OpenFile for example just says "Result ="
But that means than every affectation which won't fit in destination will raise a warning which can be painful if you actually know what you are doing.
Im not sure about "painful if you actually know what you are doing", because asm and C compilers will alert users with Warning or Error if they try to use wrong datatypes, and they typically know what they're doing? :)

Re: Helpfile - specify the actual DATATYPE instead of "a num

Posted: Thu Sep 03, 2015 8:53 am
by Fred
Yes, because an integer (which is the PB default type) is enough. So Result = OpenFile() will actually work everywhere.

Re: Helpfile - specify the actual DATATYPE instead of "a num

Posted: Thu Sep 03, 2015 8:54 am
by Keya
Great! So you can specify "Result.i =" instead of "Result =" in the documentation then! :oops:

It's not just Return values btw, virtually ALL parameters also ...

For OpenWindow just to quickly pluck one example at random ...
"Result = OpenWindow(#Window, x, y, InnerWidth, InnerHeight, Title$)"
Which are L, Q, I, or other, and why isn't this specified? It only takes an extra two letters after each parameter, then there'll be less guessing, less time wasted, less crashes, less incorrect bug reports.