Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    it("should work with booleans", () => {
      expect(classNames({a:true, b: false}).to.equal("a b")
    })
Shouldnt this just equal "a" though? See, already a bug in your homegrown solution!


My test would fail, and I would fix it. + 2 seconds. Actually, the next test has the same problem. 2 more seconds. I'm gonna be in trouble with my boss!


No, your test wouldn't fail because you wrote your code already being confident it is correct and went on. The bug would surface later in your team, somebody else in your team not familiar with your code would spent hours figuring out what is wrong, will consult you about your intentions when you wrote the code etc.


No, the test would fail in this case because the code was written properly because it was a TRIVIAL 2-line function (see above).

A few people in this thread have regurgitated the same reasoning you have. The problem is that your reasoning is NOT an invariant under complexity. This reasoning does not apply nearly as much to trivial utility functions such as:

  const isObj = o => !!o && typeof o === "object"
and classNames, etc. as it does to larger, more complex code.

> will consult you about your intentions when you wrote the code etc.

No, no they won't. No one will consult me on what my 2-line classNames functions does. It's 2 non-obfuscated lines. These aren't undergrads in CS101.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: