Illustration by Ivan Haidutski from Icons8
You've probably read and listen a lot about Clean Code and probably you're tired of acronyms like YAGNI...
For further actions, you may consider blocking this person and/or reporting abuse
If, in a code interview, someone wrote code along the lines of:
I wouldn't hire them
I would like to know why?
I think that clean code is not the main concern on a whiteboard job interview.
But cleaning up some code can also be a good question for a candidate.
The
ifand two returns are entirely superfluous. This type of code to me indicates a lack of understanding of what a boolean expression is. My above example should really be written:Or, better still:
There is nothing tricky or clever going on in my code. Being overly verbose is not the same as being clean
I see.
I think that writing pseudo code on a whiteboard explaining what I have in mind, it's not the same as writing production code.
The uncecessary if and return statement will help exposing the implementation to another humans.
It's just that, I often refctor boolean expressions as you did here, so it is just that I was courious about your reasons about failing a job interview.
The code should never be written that way in the first place - it's as bad as writing something like this in pseudocode:
Definitely a red flag
Also, violates SOLID's first principle, because now function
does two thing instead one.
Those functions are poorly named. Proper names would be
areaCircle,areaSquareandareaRectanglerespectively. You can turn the names around, but puttingareafirst makes for easier sorting.Yeah I wasn't too careful with the naming here since that wasn't the problem of the exercise. I think that
calculateAreaCirclewould be better though, since methods should have a present tense verb.I don't see any methods in that code.
Nice and easy understanding. Thanks for sharing :)