5 ms·
A common typo, it seems. But I'm a bit confused as to why this was submitted.
by southern 15y ago
A common typo, it seems. But I'm a bit confused as to why this was submitted.
- amirhhz 15y agoIn JavaScript, if you check for a non-existent property on a variable (e.g. aVar.lenght vs aVar.length) it will return "undefined". So people often rely on this behaviour to check if something is an array or not (no comment on whether this is good or bad), with: if(somethingThatMightBeAnArray.length){ // do things with array } So misspelling of length can be making a lot of code out there behave in an unexpected way.
- thousande 15y agoThat is a bad thing as String also have a length property "bar".length; // 3
- jpeterson 15y agoThe same pattern is widely used to test whether an array-like object is empty. Since a length of 0 is also "falsey", it evaluates as false when the array has no elements. A typo in this case would result in the tested array always being "empty".
- kaffeinecoma 15y agoIn a static language this would be flagged as an error. I assume something less than ideal happens in languages such as Ruby. I once worked at a company where a very early piece of code had a typo "properites" instead of "properties". This misspelling became institutionalized, and was used throughout the codebase because it was deemed too expensive to fix. And this was with a static language (with good IDE refactoring support)!
- palish 15y agoI'm confused as to why they couldn't simply: grep -R properites .
- chernevik 15y agoPerhaps they were using . . . something other than *nix. EDIT: Justly downvoted <strikeout>chastised</strikeout> for attempting humor without understanding.
- palish 15y agoThat command works nicely for me in Cygwin. EDIT: Eh, apologies if this sounded like chastising -- I didn't mean to. As a developer who's been trapped in "Windows-mindset" for many years, I wanted to try to inspire other Windows devs to try to use *nix-based solutions even if their only option is Windows development. Cygwin is in a very good spot right now -- it's achieved so much acceptance that even the most hardened institutions now allow it to be installed.
- chernevik 15y agoNo snarkier than my remark, and less snarky than it might have been for being so much smarter.
- storborg 15y agoPerhaps the same reason why "referer" has not been corrected to "referrer".
- kaffeinecoma 15y agoYes, it was exactly like that- lots of code had grown around the "bug", and it was not immediately obvious what other software had come to depend upon it. "Little hairs", as Joel might say.
- kaffeinecoma 15y agoThe whole software infrastructure was a scary house of cards. They were afraid that there was unknown code that might be depending on it. For example RESTful services in other departments that were not under our immediate control.
- 15y ago
- Wilya 15y agoIn ruby, and I think most dynamic languages, this type of typo is likely to raise an exception. It could hurt, but a simple test run is likely to discover it. The way javascript (which is what is linked) handles this, as amirhhz described it, leads to silent errors which could turn out a lot worse.
- kaffeinecoma 15y agoYes, but it would raise the exception at run-time, and only when the particular path is taken.
- xxbondsxx 15y agoThere's actually no exception, it just returns "undefined" and the if statement fails. That's why it's such a deadly bug -- no exception, and path dependent. Combine that with the async nature of JS and it's going to be a long night tracking that one down
- p4lindromica 15y agoThere are ways to raise this sort of error even in static languages: objc_sendMessage comes to mind
- strictfp 15y agoI had this problem as a junior dev when my english was weaker. The problem stems from that 'height' is spelled with 'ht', but width with 'th'. Since one often write those words in conjunction, it is easy to mix the endings up. If you're then a non-native speaker and don't run spellcheck on your code, you might end up writing 'lenght' and 'heigth' quite a few times, I know I did :)