Code: Select all
s$ = "abcd"
Debug Mid(s$, 2)
Mid(s$, 2)
Regards, Little John
Code: Select all
s$ = "abcd"
Debug Mid(s$, 2)
Mid(s$, 2)
Trond wrote:Why on earth would it do that?
Soeesau wrote:I can't find the error in your code.
Code: Select all
Mid(s$, 2)
Sure. Just because the return value is not used it isn't a syntax error. Maybe an optional warning could be generated.Little John wrote:Sois a valid command?Code: Select all
Mid(s$, 2)
PB has other built-in functions, that work fine without using their return value, e.g. OpenWindow(). In theses cases, of course it's up to the PB programmer whether or not to use the return value.eesau wrote:Sure. Just because the return value is not used it isn't a syntax error. Maybe an optional warning could be generated.Little John wrote:Sois a valid command?Code: Select all
Mid(s$, 2)
Code: Select all
Mid(s$, 2)
I disagree with your opinion. However, as I wrote that's not the point here. Call it however you like.PB wrote:Nope
What has this got to do with the problem at hand?Trond wrote:The compiler can't know whether a function has side effects.
Yes, I'm only talking about internal functions, of course. I'm sorry in case I didn't make that point clear enough previously. The compiler "knows" all internal functions, and so it knows that e.g. the linec4s wrote:But the compiler knows it for the internal functions and this could be enough.
Code: Select all
Mid(s$, 2)
In principle there is no problem building this kind of error check into PureBasic, and it won't do any harm either.function result must be assigned or used
If the function had side effects (like OpenWindow()) it could be that you only wanted the side effects, and didn't want the return value. It would be annoying if the compiler put an error in this case.Little John wrote:What has this got to do with the problem at hand?Trond wrote:The compiler can't know whether a function has side effects.
The compiler could help the programmer to find this kind of "wrong code" (or however we call it). So I just wish it would do so.
No, the compiler doesn't know how the internal functions work. The compiler doesn't know that Mid() doesn't have side effects while OpenWindow() does. Because these function reside in library files, and the compiler only known their names, parameters and return type.Yes, I'm only talking about internal functions, of course. I'm sorry in case I didn't make that point clear enough previously. The compiler "knows" all internal functions, and so it knows that e.g. the linec4s wrote:But the compiler knows it for the internal functions and this could be enough.doesn't make any sense.Code: Select all
Mid(s$, 2)
In that case there needs to be a "void" return type to signify that the function doesn't return any value. PB doesn't have such type.There are programming languages that raise an error in exactly the case that I'm talking about.
Code: Select all
CreateImage(0, 10, 10) ; Return value available, but not needed
CreateImage(#PB_Any, 10, 10) ; Return value needed
Ah, now I understand what you mean. Yes, I agree.Trond wrote:If the function had side effects (like OpenWindow()) it could be that you only wanted the side effects, and didn't want the return value. It would be annoying if the compiler put an error in this case.Little John wrote:What has this got to do with the problem at hand?Trond wrote:The compiler can't know whether a function has side effects.
The compiler could help the programmer to find this kind of "wrong code" (or however we call it). So I just wish it would do so.
Such a type can be built into PB, no? I wrote my wish here, but I'm sure the PB team will know better than me how to implement it in detail.Trond wrote:the compiler only known their names, parameters and return type.
In that case there needs to be a "void" return type to signify that the function doesn't return any value. PB doesn't have such type.There are programming languages that raise an error in exactly the case that I'm talking about.
My wish refers only to internal functions such as Mid(), where ignoring the return value doesn't make any sense. Implementing my wish will not cause any disadvantage to the PB programmer.Trond wrote:And there are many functions where the return value is not always needed. What would you do about those?
The compiler has to be consistent in its error reporting. Otherwise it just creates confusion. How is a beginner supposed to know that for function X the returnvalue is always needed and for function Y it can sometimes be ignored? For him it will just look like the compiler is missing an error.Little John wrote:My wish refers only to internal functions such as Mid(), where ignoring the return value doesn't make any sense. Implementing my wish will not cause any disadvantage to the PB programmer.Trond wrote:And there are many functions where the return value is not always needed. What would you do about those?