164
u/Wirespawn May 15 '18
Could be an answer to one of those ass-retarded interviewer questions (“Do X without doing Y”)
59
28
u/redditsoaddicting May 15 '18
Or thinking that == on ints does reference equality.
6
u/Jonno_FTW shameless May 15 '18
Pretty sure equality checks on boxed and unboxed types in java are overloaded. So it doesn't matter either way.
3
u/XplittR May 15 '18
I think I read somewhere that Integer was behaving different for small values compared to bigger values
4
u/TheUnlocked May 15 '18
I believe that's true in some cases, but not
==. It has to do with a range of ints that are cached before they're needed.2
u/XplittR May 15 '18
Yeah, a quick Google searches revealed this: https://stackoverflow.com/questions/3131136/integers-caching-in-java
2
u/Jonno_FTW shameless May 16 '18
Woops, my bad. Probably the kind of behaviour someone would pull out in an interview to trip you up.
4
32
55
9
u/ShamelessC May 15 '18 edited May 15 '18
Bastardizing exception handling this way is A-okay in the python community. For instance, to determine whether something is a float or an int, just try int and catch the ValueError! From the second answer in https://stackoverflow.com/questions/379906/how-do-i-parse-a-string-to-a-float-or-int-in-python
def parse_num_str(s):
try:
return int(s)
except ValueError:
return float(s)15
3
u/hexane360 May 15 '18
Except it's not really bastardized "like this". Using try/except to catch natural computational errors is miles away from using the fact that computations fail on certain inputs to verify inputs.
2
u/ShamelessC May 16 '18
Yeah I'm enlightened now to the "ask for forgiveness" mentality mentioned in the other comment. I regret saying "bastardizing". Although, coming from another language, it may feel a bit "wrong" until you understand python better.
10
u/Pure_Awesomeness May 15 '18
Perhaps they discovered a glitch in the matrix and this is 1000x faster!
6
4
3
-15
u/PM_ME_YOUR_HIGHFIVE May 15 '18
I guess 1 and 0 are equal
28
5
239
u/BLourenco May 15 '18
This honestly just looks like a joke, and it's pretty funny.