4
83
u/_njd_ Aug 31 '14
I especially like the way that the function name is less informative than using the underlying Enabled property directly.
59
u/thelehmanlip Aug 31 '14
and how the parameter is unused
34
u/I_EAT_GUSHERS Aug 31 '14
And how this entire function is unnecessary.
19
Aug 31 '14
getter?
8
u/I_EAT_GUSHERS Aug 31 '14
I just noticed that "Enabled" is not a function. You're right.
7
u/combatdave Sep 01 '14
Or maybe "Enabled" is a getter, and the reason that this code is if-if rather than if-else is to make sure the "Enabled" getter is always hit twice, because that getter actually launches a bunch of asynchronous WWW requests which may or may not complete at any point in the future.
(And yes, this was production code.)
1
1
1
u/SnowdensOfYesteryear Sep 01 '14
Could be there to keep API/binary compatibility?
4
3
17
u/gosslot Aug 31 '14
I've seen similar constructs so many times when I was a tutor for new CS students at my university.
6
u/idontlikethisname Aug 31 '14
I see similar constructs everyday... at work... in our existing codebase :/
6
u/Plenoge Sep 01 '14
Exactly this. People don't add me to code reviews as often anymore. I'm sorry, but unnecessary checks and variables are just that.
1
u/be3793372 Sep 01 '14
wouldnt a modern compiler optimize this?
6
u/SnowdensOfYesteryear Sep 01 '14
It's not about runtime, it's about code readability. I mean in the OP, you could save ~6 LoC with a simple return. I know it sounds trivial, but shit like this adds up over time in a large codebase.
1
u/little_z Sep 03 '14
Or you could just go without the method entirely... Enabled is a property that I'm assuming the Tool object maintains. Enabled will tell you by itself what its state is. No need to go checking it with a separate method.
1
u/SnowdensOfYesteryear Sep 01 '14
Wield the -1 hammer in code review brah.
1
u/idontlikethisname Sep 01 '14
Bro, I aint no code reviewer, I'm just a common worker having to deal with the current codebase :/
0
Aug 31 '14
[deleted]
46
u/compto35 Aug 31 '14
See, if you show them the door, they just call themselves self-taught and get paid to do this with production code
7
0
Sep 01 '14
[deleted]
1
u/Hamburgex Sep 01 '14
Self-taught taught it themselves because they liked it, grad students chose the career because they thought CS = money?
1
u/antiHerbert Sep 11 '14
because, CS teachers are rarely involved in the field. They have little idea about coding standards, or even a companies standards. They receive projects from students and cant code review everything. Imagine you have a class of 30 students, if it compiles, runs, and give the expected output => PASS. I'm speaking of my experience in school. Really in any CS major there should be a class called "Code Smells 101." Seeing bad code is the best teacher there is
3
u/drusepth Sep 01 '14
You should also return False at the end just in case neither if condition passes.
3
3
u/ElGuaco Sep 04 '14
Yes, this is terrible, but not terribly creative or original. I've seen this a thousand times with new programmers.
2
u/daniel-sousa-me Sep 01 '14
I usually help people taking the introductory programing course in my university and every year I come across a few people testing foo==True
1
u/TheRealKidkudi Sep 01 '14
To be fair, for someone just barely learning (I.e. an introductory programming course), it's a pretty easy mistake to make.
2
u/cosinezero Sep 18 '14
To also be fair, few explanations of condition checks explain that the expression is evaluated in such a way that allows you to just reference the boolean. For many beginners, they think the conditional expression has to be expression-like.
That goes doubly so for javascript and other languages where null, undefined, empty string, and zero are all falsey values. I've corrected more than a few like this:
if (myVal != null) { if (myVal !=undefined) { if (myVal != "" ) { if (myVal == "This code sucks") { return true; }}};
1
u/TheRealKidkudi Sep 18 '14
Yeah, its an easy mistake to make. I definitely got a kick out of the thought someone using code like that. As much as I can understand making that mistake, it doesn't stop me from laughing.
1
1
-8
u/burningapollo Aug 31 '14
This is literally an interview question for us, except it's 'given a string passed to a function, return whether it is or is not a palindrome'. Some people make the leap, but some don't. Needless to say it's almost an instant disqualification if you can't figure it out.
27
u/POTUS Aug 31 '14
Determining whether a string is a palindrome is:
Not terribly difficult, so okay, I get how it's a basic brain teaser to weed out morons, but also...
Not directly relevant to any job function I can imagine, and...
Not at all relevant to the OP's picture.
6
u/stubing Sep 01 '14
OMG! This is exactly the same interview question I had except it was called a fizzbuzz test and it had to do with numbers and it was nothing like what you are talking about.
2
0
Aug 31 '14
[deleted]
29
u/immibis Sep 01 '14
But what if it's a number? Or a string?
function check(en) if (Tool.Enabled == nil) then return nil end if (Tool.Enabled == true) then return true end if (Tool.Enabled == false) then return false end if (Tool.Enabled == 1) then return 1 end if (Tool.Enabled == 2) then return 2 end -- ... if (Tool.Enabled == 4294967295) then return 4294967295 end if (Tool.Enabled == "a") then return "a" end if (Tool.Enabled == "b") then return "b" end -- ... if (Tool.Enabled == "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") then return "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" end end9
u/stubing Sep 01 '14
You guys impress me. I seriously did not know how to make that code any worse while still preforming the same task.
1
u/cosinezero Sep 18 '14
Sadly, after a while you see more of these sort of things than a sane person would expect.
27
Aug 31 '14
No, no, this is the correct way:
function check(en, ab, foo, bar): //Error handling, just to be sure we don't get a type error if(Tool.Enabled instanceof Number || Tool.Enabled instanceof String) return Tool.ErrorHandling.Type.Null end //Checking if parameter is true if(!(Tool.Enabled == null) && (Tool.Enabled == true)) then return Tool.BooleanAlgebra.Parameters.True end //Checking if parameter is false if(!(Tool.Enabled == null) && (Tool.Enabled == false)) then return Tool.BooleanAlgebra.Parameters.False end //This code will probably not be reached, but if it will, make sure it doesn't cause errors return Tool.ErrorHandling.Type.Null end40
u/timlyo Aug 31 '14 edited Aug 31 '14
Couldn't you just do
function check(en) return Tool.Enabled endEdit: sarcasm isn't my strong point :(
73
69
4
7
u/ledger12 Aug 31 '14
Looks like some shitty roblox script