4 ms·
As long as it's "single page bound" JS like this, I honestly don't think it matters one bit. Reusable components and utility libraries is something different,
by Deestan 14y ago
As long as it's "single page bound" JS like this, I honestly don't think it matters one bit.
Reusable components and utility libraries is something different, of course.
- sjs 14y agoIt's still incredibly error prone and just bad practice. It's a telltale sign of a bad developer because a good dev would instinctively just use var without thinking about it. Good devs may make a mistake here or there but this is clearly well beyond a forgotten var keyword.
- slantyyz 14y ago>> It's a telltale sign of a bad developer I'm just guessing, but the site was probably not developed by a technical team, probably some web shop that specializes more on the design/layout/content side and not on the JS side. So it's likely it's the work of a non-developer than a bad developer. The net result is the same (bad code) but the distinction is that the code was possibly written by someone who wouldn't even be considered a developer.
- aaronasterling 14y agoBut when writing code, how do you know that it's always going to be "single page bound"? YAGNI is frequently useful poison and nothing more. When it's so easy to do it right the first time, why not?
- Deestan 14y ago> When it's so easy to do it right the first time, why not? a) Because it isn't "right" as such. It's just "better" if the code is going to be reused. Which it isn't. b) The code style serves as documentation. I can clearly read from this code that it's not a reusable component. It is now easier for me to get an idea of how and where this code is being used in the site. c) Personally, I'm wary of "pre-emptive generalization". Every layer of abstraction makes the code slightly less readable. Also, unless there exists at least two use cases right now, you're not likely to get the reusability right anyway.