Skip to content
loading...

re: What's the worst code you have seen by a senior dev? VIEW POST

FULL DISCUSSION
 

Remember that Javascript is "truthy" in how it handles booleans. Depending on the rest of the code base, performing a hard check here might not actually be a mistake.

Regardless, this could also just be a matter of personal preference, as it has zero impact on the actual execution.

For example, our previous senior dev always reversed the order of their conditionals: if(null === var).

This is a pretty subjective application of logic here, as isRequired might not even be a boolean at all times - would have to see the full context to know.

 

Agreed! Right to the point Brandin. My point was more to inform all that even the senior dev sometimes do the basic mistake. That's where code review comes handy. Reviews make sure that the quality of code is good.

Coming to isRequired. I always expect high code standards and when it comes to the variable names like isRequired, hasKey, isPresent, etc.. I expect that to be a boolean. It's not good if boolean has non-truthy values which means we don't have the control of the values being stored. As devs, we have to decide which type will be stored in a variable :)

 

My comment was more to indicate that the line in question is hard to evaluate as an objective "mistake", and I personally would not evaluate it as such.

As for the variable names, there is often a very wide gap between what we as developers expect a value to be, and what it actually is, especially in a loosely typed language like Javascript.

If we ourselves don't know what's being stored, then it's a matter of concern. If used JS in the right way, it will help to do wonders. Else, get ready to fix bugs mate, lol. I had the same mindset during the early stage of my career. Way to go.

I have the same opinion as Brandin as a dev of 15 years. Also your way of communicating is quite patronising. In a language like JS, this kind of conditional makes sense, especially in bigger projects with multiple developers. It adds no weight but is a stricter check that helps to prevent bugs. If this value is changed by someone to a non-truthy value for whatever reason, a code review will most likely not catch it and even your tests might work and you have an extremely hard to track bug. Software projects are never perfect and you should never assume so.
In our company of 150+ devs, the strict checks in loosely typed languages are actually in the coding standards and will get flagged if you don't do them.

 

My thoughts exactly. You might want to check that the value is specifically true, rather than any other non-falsy value.

code of conduct - report abuse