Why doesn't SuperStrict throw an error if...
BlitzMax Forums/BlitzMax Programming/Why doesn't SuperStrict throw an error if...
| ||
...a function, that has a return type, does not return something?SuperStrict Framework brl.standardio Local something:Object = IReturnSomething() Function IReturnSomething:Object() Print "OHai!" End Function |
| ||
It'll return Null? |
| ||
Maybe because in your example nothing is returned. Or it's handled automatically by bmax |
| ||
I'm new to blitzmax but that does seem odd to me for SuperStrict Plash, yes. |
| ||
It'll return Null? It has a return type, and should throw an error because I am not returning a value - imo. Maybe because in your example nothing is returned. That's the point, it should throw an error.. :( Or it's handled automatically by bmax I wish it weren't. SuperStrict is for avoiding typo's/error's, the function should have to return something in code, not by default. I'm new to blitzmax but that does seem odd to me for SuperStrict Plash, yes. :/ |
| ||
Basically its down to you to check something is loaded into the object, this is the same for ALL loading commands its down to you to check its loaded. If nothing can be loaded it returns Null as default, just check to make sure your value isnt null and you will be ok. I prefer BlitzMax SuperStrict to stick to the way it is as checking for null is a lot easier than checking through for loads of errors because I didnt return a value, its not C where 'function should return a value' warnings crop up everywhere. |
| ||
its not C where 'function should return a value' warnings crop up everywhere Right, but functions that have a return type should be returning something. If you want to check if a function returned Null it can cause issues if has done that by default and the developer forgot to return the correct value (in this case Null).I suppose its just opinion.. SuperStrict should be truly super strict! |
| ||
its not C where 'function should return a value' warnings crop up everywhere. Unfortunately. C doesn't do that simply to be a pain in the arse, it does it to try and point out to the coder that they've made a mistake. |
| ||
I would find typing Return 0 (this is what BMax does) at the end of every function as hassle. |
| ||
I think Plash has a good point, here. Not that I think failing to return a value is really a huge problem for most of us, but when you ask for "SuperStrict," you should get super strictness. Saying that you don't want errors cropping up or you don't want to have to add return statements to your functions is the same as saying, "I want to be sloppy." So, why are you using SuperStrict? SpaceAce |
| ||
I would find typing Return 0 (this is what BMax does) at the end of every function as hassle. That's not what I'm saying. I'm saying that, in SuperStrict, you should have to return a value for every function/method that has a return type.So for: Function SomethingOrAnother() Print "I don't have to return jazz" End Function I wouldn't have to return a value, especially since you can't actually return a value from that function. Saying that you don't want errors cropping up or you don't want to have to add return statements to your functions is the same as saying, "I want to be sloppy." So, why are you using SuperStrict? This is why I protest the modules being Strict and not SuperStrict.. But since it currently doesn't MAKE YOU return a value from a function/method that HAS a return type it wouldn't help.This is an example of one of the recent errors due to the standard modules being Strict and not SuperStrict (if it were actually SUPER strict). |
| ||
How about some DoublySuperStrict for the masochists? Dont mess with my SuperStrict, i likes it the way it is! |
| ||
This could be a good example for a compiler warning. But Max doesn't produce compiler warnings, so... |
| ||
That's not what I'm saying. I'm saying that, in SuperStrict, you should have to return a value for every function/method that has a return type. OK got it. I see what you mean. |
| ||
could there be a situation where you would want to not return anything sometimes? A brief but not directly useful example: |
| ||
Yes, in this case a Return Null would be enough :D |
| ||
Hi, I think it should be an error...but would it break much SuperStrict code if 'fixed'? |
| ||
So.. maybe add SuperDuperStrict? :) EDIT: @Perturbatio: So how do you plan on informing the developer that the item could not be added? By returning Null, which is what it does by default - if it didn't you would just have to be certain you told the developer that the object wasn't created (the better way, in my opinion). |
| ||
What about a superstrict that can hold optional arguments that can alter the default options? SuperStrict(<optional values>) |
| ||
Mark, warnings would be more cool and will not break any existing code. No strict statement: No warnings, no typechecking Strict: No warnings, but typechecking SuperStrict: All warnings, and restrictive typechecking maybe we could find some useful compilerwarnings except those "missing return value", like if/then complete checking ect. |
| ||
warnings would be more cool and will not break any existing code. I agree, and this way the warnings could just be added to the current SuperStrict - functions/methods should still return null by default. |
| ||
I also agree. I think proper warning are always welcome on a great compiler such as the blitzmax one. |
| ||
Is there really much danger of breaking code by making this an error? It seems to me that the worst case scenario involves going through your code and add a few returns. You'd only have to fix paths that led to no return value. SpaceAce |
| ||
OK, Havent read it all, no time nowadays too buzy I dont mind either way about this, BUT PLEASE dont make superscript throw an error if the Function Does return an object which isnt then allocated to anything Yep I know this thread isnt about this. BUT as MArk has asked, thought Id just make sure |
| ||
I agree with SpaceAce. I've got a huge amount of existing BlitzMax code, and I'm sure I have a fair few functions which can return something but do not always do so. However, fixing that is a simple job, and would take very little time. You shouldn't hold back from changing something relatively important for such a trivial reason as me having to add a few Return's. |
| ||
BUT PLEASE dont make superscript throw an error if the Function Does return an object which isnt then allocated to anything I don't think that's how it would work. You should still be able to return an uninitialized object from the function (it will just be returning Null, since the object hasn't been set - or 'initialized') without an error, the change should just be checking for the return call. |