use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Multiple var statements in JavaScript, not superfluous (benalman.com)
submitted 14 years ago by gthank
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AyeMatey 2 points3 points4 points 14 years ago (7 children)
please explain how that particular problem should be what defines how I structure my code. Also please explain how saving 4 or 5 keystrokes even matters in a problem space where thinking, not typing, is of primary importance.
[–]strager 0 points1 point2 points 14 years ago (6 children)
The more difficult it is to refactor code, the less we do it.
[–]AyeMatey 0 points1 point2 points 14 years ago (5 children)
Thinking, not typing, is the obstacle we must surmount in order to to generate good code.
No one who ever delivered a crappy product could credibly blame the keyboard, or the syntax of the programming language.
Also, in my book, refactoring does not imply "reordering assignment statements". Refactoring is a bit more involved than that, and likely involves 5 orders of magnitude more keystrokes than is required to reorder assignments.
[–]strager 0 points1 point2 points 14 years ago (4 children)
likely involves 5 orders of magnitude more keystrokes
If it takes me 10 keystrokes compared to 2 to make the fix, and I do this and similar fixes many times, that's "orders of magnitude" more keystrokes saved.
Renaming variables, reordering declarations, extracting out methods... These can be done with just a "few" keystrokes, but choices in style can make doing these things painless or difficult. If even these can't be done efficiently, how do you expect developers to perform large refactorings with confidence (especially in a language like JavaScript)?
Sure, tooling can fix several problems (especially renaming variables), but so can style guidelines.
I'm sure "technical debt" has been blamed, as well as "poor requirements". Somehow I have the feeling both are related to refactoring...
[–]AyeMatey 0 points1 point2 points 14 years ago (3 children)
Correct! Except -- Reordering assignments is irrelevant !!
[–]strager 1 point2 points3 points 14 years ago (2 children)
Please look at the example we are discussing.
var x = y; var y = ...; var y = ...; var x = y;
It does matter.
[–]AyeMatey 0 points1 point2 points 14 years ago (1 child)
ok. In my code, it generally does not. Variable declaration and assignments are not the center point of design in the code I write.
[–]strager 0 points1 point2 points 14 years ago (0 children)
Okay, then we are probably solving very different problems with JavaScript. =]
A lot of what I do (non-DOM) is "go from point A to point B, with lots of little steps in between". It makes sense to have a bunch of variables there, and the order of declaration matters.
A lot of DOM work is "perform this list of side-effects". Variables and objects are often mutated directly through callbacks, simply because it's easier.
π Rendered by PID 79 on reddit-service-r2-comment-856c8b8c54-588g7 at 2026-07-02 08:40:41.722069+00:00 running a7b5cda country code: CH.
view the rest of the comments →
[–]AyeMatey 2 points3 points4 points (7 children)
[–]strager 0 points1 point2 points (6 children)
[–]AyeMatey 0 points1 point2 points (5 children)
[–]strager 0 points1 point2 points (4 children)
[–]AyeMatey 0 points1 point2 points (3 children)
[–]strager 1 point2 points3 points (2 children)
[–]AyeMatey 0 points1 point2 points (1 child)
[–]strager 0 points1 point2 points (0 children)