5 ms·
While introducing new developers to work on the JS part of our codebase (node & client side) - I noticed some puzzled looks here and there. Not everyone unders
by berzniz 12y ago
While introducing new developers to work on the JS part of our codebase (node & client side) - I noticed some puzzled looks here and there.
Not everyone understands why && and || are used outside of if statements. Not everyone knows about joining strings using an array.
This summarises the things you'll have to know to read code in our codebase.
- xorcist 12y agoDon't they know about the join operator at all, or is there something else here? What else would you join if not arrays?
- berzniz 12y agoTell a novice JS developer to concatenate a list of strings: "first", "middle" and "last" into "first, middle, last". You'll probably get a solution using loops and a check if adding a comma is needed or not. I know, I asked my friends. Ask your new teammates.
- nmjohn 12y agoI would be concerned by someone not knowing || - it is used all the time by almost every major project. Not knowing what that one did outside of an if functions tells me 1.) Said person hasn't actually looked at any code other than their own OR 2.) They saw it and didn't care enough to learn what it did. Either way, strike against them. The && though, I've never used in this context. And I'm not sure if I've seen it out in the wild or not. I knew what it did right away so I imagine if I have seen it before I wouldn't remember.
- talles 12y agoI second that. I use the || trick really often, but never the && one. By the way, why not use a one-liner if instead? if (condition) something; I find more readable this way.
- nmjohn 12y agoIt is definitely more readable. Best practices would say always to use curly braces though. I go back and forth on my opinion of that. Also, for example I use a sublime plugin to automatically tidy my code, and that isn't an option in it, so I don't do it anymore.
- vlunkr 12y agoOr 3.) They are new developers. I learned to use that at some point and so did you.
- nmjohn 12y agoWell yes, absolutely, but the context was someone being hired for a job and seeing the codebase. Someone that green is, at least in my opinion, not yet qualified to be hired as a programmer.