Strict - Function return values
BlitzMax Forums/BlitzMax Programming/Strict - Function return values
| ||
I would like to suggest that if Strict mode is used functions and methods not be allowed to return types that are not the type specified by the function/method. function foo() Local x:Float=1 return x end function should not compile. The coder should be forced to cast the value to an int in the above case. Actually I think this should be the case even when strict isn't used. At the very least a warning should be produced. |
| ||
Numeric casts are done implicitely, so it would be more of a harm than use if you needed to cast it explicitely for returns. (means local a = float (b) is casted automatically) |
| ||
I'm not suggesting that assignments don't get implicitely casted only the return values. If I can't return the incorrect Type from a method I shouldn't be able to return an incorrect primitive. This is of course, my opinion. The use of the strict keyword should enforce the highest level of type checking. |
| ||
I see no logic in this. |
| ||
what your asking for exists... Strict Local b:Int=blah() Print "b="+b Function blah:String() Local a:Int=123 Return a End Function wont compile cause it says cant convert string to int... the reason the return works is because int seem to get automatically cast to strings strict local a:string a=123 print a will work, just like return does... |
| ||
however this will compile and is in my opinion incorrect: function foo() Local a:Float=1.2 return a end function the incorrect value is getting returned from the function. |
| ||
yeah automatic cast to int by the looks - not too strict is it! |
| ||
This compiles in C:int weeble( ) { return 5.55858473f; } So I don't see why BlitzMax shouldn't be able to automagically cast to and from different (numeric) data types unless you're some nutty pedantic person. ;) |
| ||
He is just lazy or not willing to "use his brain" while sending out returns ;-) |
| ||
Acutally I'm not the one that had a problem with this. It was another user on the forum and the since this is a "basic" language it should do what it can to keep less experienced folks from having these problems. Lazy would be people that aren't willing to do a simple cast to the correct type. :) |
| ||
Why does it force the exact type when initializing arrays?This code doesn't work and I find it very annoying. Think if the whole language was like this, you would have to convert all your Int and Double parameters to Float just for a drawrect command! I don't care if Cos() actually accepts Double only, convert it for me!Local a:Float[2] a=[1.1, 2] Local a:Byte[2] a=[1, 2] |
| ||
As I said before: I'm not suggesting that assignments don't get implicitely casted only the return values. If I can't return the incorrect Type from a method I shouldn't be able to return an incorrect primitive. This is of course, my opinion. The use of the strict keyword should enforce the highest level of type checking. |
| ||
ok, I was just taking this line out of context. its really easy to do "The use of the strict keyword should enforce the highest level of type checking." |