if (condition === true) {
...
When I see something like the above, I have a presumption that there is a high probability that whoever coded it, must be relatively new to the field of programming.
What are a few other code examples from programmers that might tip you off of their inexperience?
I don't consider mentioned code a bad or newbie practise. I prefer to write the code this way, because it tells you more explicitely what are you testing. You might get wrong behaviour using this approach, consider this:
if({}) { console.log('true') } else { console.log('false') } // true
if([]) { console.log('true') } else { console.log('false') } // true
if({} === true) { console.log('true') } else { console.log('false') } // false
if([] === true) { console.log('true') } else { console.log('false') } // false
Also, comparing objects in Javascript using double-equals can create unwanted behaviour, hence it's recommended to use three-equals operator:
console.log(99 == "99"); // true
console.log(0 == false); // true
Read more here impressivewebs.com/why-use-triple-equals-javascipt
Wow, you think an inexperienced developer wrote that piece of code?
YOU ARE WRONG!
What if condition actually can be a string or be numeric? What if you only want to account for condition to be boolean? Sure, in any different language, it might not make a difference, but this is JavaScript (see your own tags). So for me, the given code might be written by anyone and you yourself should start learning about the implicit type system of JavaScript!
To be honest, your text would mean to me that you are rather inexperienced. Other examples include flamewars about how programming language X is better than Y in every way or how a certain compiler is faster than another. In the real world, stuff like that does not matter and it's just about how well your algorithm works and how well you know the underlying structures.
If you have a long switch maybe it's a bad signal that the inheritance it's not correct, or a lot of if/else concatenated.
When I see people post stuff like this, I have a presumption they think they are above everyone without considering maybe there is a reason behind . Like some others pointed out below, condition might have different cases and dev might be looking for true case.
const MyComponent = ({someVar, ...others}) => {
let config = {};
if( !someVar) {
Object.assign(config, {...others});
} else if (someVar === true ) {
Object.assign(config, {x: 54, y: 54})
}
else {
Object.assign(config, {someVar, ...others})
}
return (
<AnotherComponent {...config}>
);
}
MyComponent.propTypes = {
someVar: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.shape({ x: PropTypes.number, y: PropTypes.number})
]),
......
}
j
stuff ;)
Do you mean the language context ?
the triple equal for example is linted on my side in JS and PHP because I'm extra strict and maybe I have more than 1 return value and only true should be correct.
it's a zen of python thing : explicit is better than implicit.
I was thinking about this question for quite a while now, and basically I cannot distinguish experienced developer from inexperienced developers by such simple examples of code structure.
Maybe the person is so deep in the knowledge of the language that they actually are so precise that I don't know it ? for example knowing how many assembly instructions in C are executed on a disc read and that's why they have a weird if structure combined with a certain resource structure ...
I know people who learned it that way and they've built computer chips so I would not call them noobs, their syntactic structure looked like shit but they actually could break it down to the instruction.
The only thing I know to do, is ask why things are done in a certain way and if they cannot answer it reasonable.... that's how I know for certain if it's a noob or not.
and if they write their own date function gg ... as I did .... because modulo four has to be good enough ! :D