Comments on: JS adolescence https://j11y.io/javascript/js-adolescence/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: Andy https://j11y.io/javascript/js-adolescence/#comment-2563 Tue, 26 Mar 2013 11:07:28 +0000 https://j11y.io/?p=2170#comment-2563 Interesting article. It would be useful for these types of discussions to also include an example of what is right.

]]>
By: Steve Kwan https://j11y.io/javascript/js-adolescence/#comment-2562 Sat, 23 Feb 2013 21:54:23 +0000 https://j11y.io/?p=2170#comment-2562 This is a really, really great article. It does an awesome job of balancing pragmatism versus good coding. Too often language debates turn into name-calling and nitpicking over semantics, but your article really demonstrates the difference between a junior developer and a seasoned vet. This is required reading for my team now. Thanks!

]]>
By: Pawel https://j11y.io/javascript/js-adolescence/#comment-2561 Thu, 27 Dec 2012 12:54:10 +0000 https://j11y.io/?p=2170#comment-2561 I have always over-commented my code till the moment my co-worker said it’s because I write ugly and unclear code. Since then I started to focus more on the code’s aspects.

]]>
By: Ivan https://j11y.io/javascript/js-adolescence/#comment-2560 Mon, 17 Dec 2012 02:00:14 +0000 https://j11y.io/?p=2170#comment-2560 Agree with all except this one:

if (!cachedReturnValues[key]) {
    cachedReturnValues[key] = value;
}

In very few situations this is dangerous; it only can become an issue in for-in loops.

]]>
By: Sean Harvell https://j11y.io/javascript/js-adolescence/#comment-2559 Sat, 01 Dec 2012 22:02:35 +0000 https://j11y.io/?p=2170#comment-2559 Heard about this on The Javascript Show Podcast, nice post & thanks for the tips.

]]>
By: R2_Made https://j11y.io/javascript/js-adolescence/#comment-2558 Sun, 18 Nov 2012 16:19:30 +0000 https://j11y.io/?p=2170#comment-2558 @Buggy Bug
“I consider this an extremely weak argument. Code that breaks because of the replacement of var with let, is code already broken logically. Why was the coder using a variable outside of a block that he declared it in the first place? I can’t think of any reason, besides bad design. ”

This argument is a lot stronger than you agree with. First and foremost javascript allows the use of variables outside of a block scope. But essentially are these variables outside their scope? My answer is no. Note, javascript allows variables to be used; “outside of block scope”, which doesn’t mean(or better put is not equivalent to) “outside of scope”. Javascript expands the scope of a variable declared in a block, beyond the scope of the block(contrary to what exists in most other programming/scripting language idioms).

Of course this is a bad design, but it is accepted javascript coding practise. And I can say at the minimum 10% of javascript code in live, distribution(libraries) and production, have codes written this way. And for no other reason, than because javascript allows it. Once existing code is rewriten by replacing “var” with “let”, of course bugs can and will creep into code written this way.

Qouting Douglas Crockford; “In most languages, it is generally best to declare variables at the site of first use. That turns out to be a bad practice in JavaScript because it does not have block scope. It is better to declare all variables at the top of each function.” — Awful Parts: Appendix A – JavaScript: The Good Parts

That is why why , @James gave the title of this article as “JS adolesence”. Javascript experts or wizards anywhere else in the known universe won’t have a problem with this. But there is little argument that the concept is clear, practical and objective. And a few coders may have developed such tewwwwible habits (like @james emphasized).

Or/and would you be unwilling to also accept that the ECMAscript Sages chose to introduce the “let” keyword, partly for this same reason????

For example;

//very convenient for someone out there simply because it's a //javascript ballpark
function buggyBugs(you,me)
{
     if (you>me)
                 {
                 // imagine a find and replace "var" with "let"
                   var we = you;    
                      return we;
                 }
     we = me;
     return we;
}

@James, fine article.

Thanks

]]>
By: Tom https://j11y.io/javascript/js-adolescence/#comment-2557 Sun, 18 Nov 2012 04:32:25 +0000 https://j11y.io/?p=2170#comment-2557 I’m a big fan of

function doSomething() {
  var x = 1,
      y = 100,
      z = 'hello';
}

Readable, and efficient. 🙂

]]>
By: Bill Fisher https://j11y.io/javascript/js-adolescence/#comment-2556 Sat, 17 Nov 2012 23:27:31 +0000 https://j11y.io/?p=2170#comment-2556 Aren’t your opinions on “Strict equality everywhere” and “Assuming truthiness equals presence” coming from opposite sides of the you-know-what-you’re-doing-but-just-don’t-mess-up spectrum? I’m not objecting, but I’m wondering how you reconcile that.

]]>
By: Mike Sherov https://j11y.io/javascript/js-adolescence/#comment-2555 Sat, 17 Nov 2012 17:54:51 +0000 https://j11y.io/?p=2170#comment-2555 I agree that foo==null is damned useful, that’s why I said I use it 🙂

]]>
By: Wil Moore III https://j11y.io/javascript/js-adolescence/#comment-2554 Sat, 17 Nov 2012 07:35:11 +0000 https://j11y.io/?p=2170#comment-2554 …never solves what you think it will…steer clear of over-zealous coding style dogma

I agree 100%. Dogma, cargo-culting, and complacency are developer growth killers.

]]>