Andrew (Digitwell) Well-Known Member Licensed User Longtime User Jul 13, 2021 #1 With the introduction of casting in the latest versions of the B4X family, I was wondering if it is now recommended to cast all returns from items such as maps. for example I have plenty of if statements where I use B4X: Copy if (thismap.getdefault("SomeValue",False)) then ... end if is it now recommended to use B4X: Copy if (thismap.getdefault("SomeValue",False).As(Boolean)) then ... end if
With the introduction of casting in the latest versions of the B4X family, I was wondering if it is now recommended to cast all returns from items such as maps. for example I have plenty of if statements where I use B4X: Copy if (thismap.getdefault("SomeValue",False)) then ... end if is it now recommended to use B4X: Copy if (thismap.getdefault("SomeValue",False).As(Boolean)) then ... end if
agraham Expert Licensed User Longtime User Jul 13, 2021 #2 If it works you don't need it and it just adds meaningless bloat to your code. B4X weak typing already mostly takes care of it for you. Casting is intended to minimise your code, not maximise it! Upvote 0
If it works you don't need it and it just adds meaningless bloat to your code. B4X weak typing already mostly takes care of it for you. Casting is intended to minimise your code, not maximise it!
Andrew (Digitwell) Well-Known Member Licensed User Longtime User Jul 13, 2021 #3 Fair enough. I know there are type conversion issues with B4X: Copy if (mymap.getdefault("value",-1) = 1) then .... end if which is solved by adding As(Int) or switching the arguments, so I was just wondering if the same was true for boolean. Cheers Upvote 0
Fair enough. I know there are type conversion issues with B4X: Copy if (mymap.getdefault("value",-1) = 1) then .... end if which is solved by adding As(Int) or switching the arguments, so I was just wondering if the same was true for boolean. Cheers
agraham Expert Licensed User Longtime User Jul 13, 2021 #4 Andrew (Digitwell) said: I was just wondering if the same was true for boolean. Click to expand... It is the the same for all types. I just remember that it is the type of the left hand item that determines the type of the comparison. Upvote 0
Andrew (Digitwell) said: I was just wondering if the same was true for boolean. Click to expand... It is the the same for all types. I just remember that it is the type of the left hand item that determines the type of the comparison.