On 14/05/2015 21:45, Andrew Sutherland wrote:
On 05/14/2015 04:22 PM, Gijs Kruitbosch wrote:
"==" is not any less explicit than "===". Both versions have an exact,
specified meaning.
They both have exact meanings. But people, especially new contributors
new to JS, frequently use "==" without understanding the nuances and
footguns involved. In Firefox OS/Gaia I think the emergent
convention[1] is that you should always use "===" unless you have a
specific need to use "==" and in that case you should have a comment
explaining exactly why you want the coercing behaviour. I, at least, do
this in all my reviews. And I find this disambiguates things nicely and
helps me as a reviewer in understanding the expected data-flow of the
code I'm reviewing.
Can you give a concrete example where you had to change a contributor's
patch in frontend gaia code to prefer === to prevent real bugs ?
As I noted in a snipped part of my message, I can believe that different
parts of the codebases have different needs here - I've just had the
opposite experience where I don't recall running into issues of the type
you describe, but rather things where contributors use:
if (typeof x == "undefined" || x == false || x == "")
or similar, and I suggest if (!x).
While I agree we should do our best to welcome new contributors, I don't
know that having our style guide dictate "use === instead of =="
would be helpful.
Andrew
1: I could swear we have a style-guide for Gaia but I can't find it.
https://developer.mozilla.org/en-US/Firefox_OS/Developing_Gaia/Understanding_the_Gaia_codebase#Gaia_coding_style
which doesn't seem to mention this, but defers in part to the general
Mozilla code style (but not the section where this line is hiding).
~ Gijs
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform