AJ ONeal
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
It didn't seem to affect any of our benchmarks. So, to claim speed
changes, we'll have to see proof.
Attributing 99% of non-strict JS use to laziness is a bit
presumptuous. I don't use strict in my own code primarily because I
prefer my C-style languages to support octal literals.
On Fri, Jan 20, 2012 at 9:27 PM, Isaac Schlueter <i...@izs.me> wrote:
> Attributing 99% of non-strict JS use to laziness is a bit
> presumptuous. I don't use strict in my own code primarily because I
--
HG.
AJ ONeal
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
I keep seeing this and wondering why not modify the bindings for any
APIs that want to take a permissions value to also take a string that
supports octal numbers, so you could just write chmodSync(filename,
"666") or chmodSync(filename, "r+") and have the API figure it out.
Having to figure out the numeric value for this is so C-like.
I keep seeing this and wondering why not modify the bindings for any
APIs that want to take a permissions value to also take a string that
Node's 'fs' functions already allow you to pass an octal string
instead of a numeric value for mode. Your "666" example above will
work as you expect.
--
Martin Cooper
> Having to figure out the numeric value for this is so C-like.
>
--
I use bitwise operators, doing this on strings is... ugly.
--
--
Not wanting workarounds isn't "lazy". I'm pretty sure that if you have
to replace well-written stuff that just works with "workarounds", this
is a huge -1 on that change.
> All you need to do to remove harmful and confusing features of the language
> is to start each file you right (browser or node) like this:
>
> (function () {
> "use strict";
Without the indent. Please.
> Globals are EVIL. BAD. RUDE. INCONSIDERATE. NASTY.
>
> I can't believe I'm hearing support for globals!!
I think you're exaggerating a lot here. What about, for example,
"process"? Or what about logging?
> I'm being sincere. I thought that everyone in the programming communities
> had gotten the memo that globals and gotos are words you feel dirty inside
> for using (except in the kernel where you use gotos to implement the
> decorator pattern without the overhead of function calls - and the people
> there are hopefully disciplined enough to not make severe design mistakes).
Uh? So you're basically saying "globals aren't too bad, but they're
sharp tools that can be used for nasty stuff, so drop them and use
this wooden knife instead"? Yes, it sometimes is bad to use them, and
yes, it's not what we should put on top of tutorials, but we
definitely shouldn't discourage them that much.
> Browser
> ---
> You don't need globals either. A TON of effort has gone in to making sure
> that you can write modular JavaScript. Thanks to RequireJS, Pakmanager, and
> Ender, you can install straight from npm into packed browser-safe code.
What about JSONP? You need global functions for that, no?
> Octals
> ---
>
> This is another one that blows my mind.
>
> I guess since a lot of people on this list work with c++ for native node
> modules it makes sense.
Uh... and e.g. working with the filesystem, too.
> But JavaScript is a high-level language primarily used for interacting with
> users.
> If you want to use octals... USE C!
Ah, right, Javascript doesn't belong on the server or so. You're sooo
right.</scnr>
> Do you know how many times I've been bitten by parsing user input that had a
> leading '0' and have scratched my head for too long trying to figure out
> where the math had gone wrong? A lot! (but I'm getting better and
> remembering to check for corner cases that strict mode can't protect me
> from);
Well then, sounds like you're using the wrong tools to parse user
input. And like you're not reading documentation. E.g. parseInt only
tries to determine the radix based on the input if you don't
explicitely specify it.
Oh, and yes, I don't think eval should be banned either. Yes, you
should think about whether you really need it three times before doing
it, but it can be extremely powerful and useful.
--
Have a look at this:
function foo() {
var bar = 1
if (bar > 5) return
foo(bar)
}
Do you want that to return the result of `foo(bar)` if bar>5? I don't.
You *still* have to be aware of ASI on restricted productions (most
hazardously, "return"), being careful with user input, writing a
program that does what you want, and so on. The only real value, that
I can see, is that it doesn't allow you to accidentally leak a global.
If you're working on a project with a big enough group, you still
probably need some kind of linter to stay sane, so what does strict
mode get you that the linter doesn't?
If you are the type to choose to use eval or with, then you will just
*not* choose to "use strict". It's opt-in, and much less of an issue
in node (where all code is trusted) than in the browser sandbox, where
one frequently has less-trusted code (ads, plugins, etc.) running
right next to the application.
I think it'd be nice to add a switch for this maybe, but it's a
low-priority feature. If it improved performance we'd probably just
add it manually to all the internal modules.
Why 0b and not 0o? Surely 0b should be binary?
Have a look at this:if (bar > 5) return
function foo() {
var bar = 1
foo(bar)
}
Do you want that to return the result of `foo(bar)` if bar>5? I don't.
A while ago (0.5, I think?) I looked into adding a NODE_USE_STRICT
environment var that the module system could respond to, by putting
"use strict"; in the module wrapper.
It didn't seem to affect any of our benchmarks. So, to claim speed
changes, we'll have to see proof.
Attributing 99% of non-strict JS use to laziness is a bit
presumptuous. I don't use strict in my own code primarily because I
prefer my C-style languages to support octal literals.
On Fri, Jan 20, 2012 at 11:11, AJ ONeal <cool...@gmail.com> wrote:
> There seem to be few primary reasons that people aren't using strict mode:
>
> 99% Laziness (the inefficient kind)
> 0.9% FUD - They're new to JavaScript or otherwise don't know about /
> understand it
> 0.09% They forget to type it out
> 0.009% They wan't to pretend to be cool using `with`
> 0.0001% They have a deep hatred for other living creatures and purposefully
> and knowingly use `this` to access the global object
>
> Since node is all about speed and "use strict"; mode allows for significant
> performance enhancements, why doesn't it warn you when you forget or are
> lazy?
>
> I'm watching one of the Crockford videos right now as and just aching inside
> as I think of how many rookie mistakes make it in to npm that wouldn't have
> a chance with a simple "use strict";
>
> AJ ONeal
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
All the JavaScript in node-core gets linted. (We're not warning-free
yet, we're getting closer.) We do not have octal literals in the
node-core JavaScript. If you find any JavaScript in node that is not
strict-compliant already, please send a patch. That is a bug, and
would be highly surprising.
Past analysis (in node 0.5) showed that adding "use strict" made our
benchmarks relevantly worse. If that changes, we'll start adding "use
strict" in node's internal JavaScript. As long as the "toxic waste"
is faster, we'll keep using it. Winning is more important than being
right.
On Sat, Jan 21, 2012 at 12:44, Marcel Laverdet <mar...@laverdet.com> wrote:
> The above is fine. But if you add an innocent paren the meaning of the
> program changes entirely:
>
> function foo() {}
> var foo = foo()
> (foo) ? bar() : etc()
>
> Anyway I've developed strict coding standards to avoid the pitfalls of
> semicolon insertion in JS, as I'm sure semicolon non-believers have had to
> do as well. It's just annoying because the way JS is designed, neither
> "never using semicolons" or "always using semicolons" is safe.
Marcel, you know full well that responsible semicolon minimalists
would balk at the very notion of starting a line with ( and not
prefixing it with a semicolon.
This "always" "never" business is a strawman duel. No one who knows
what they're talking about endorses either.
> Anyway I've developed strict coding standards to avoid the pitfalls of semicolon insertion in JS, as I'm sure semicolon non-believers have had to do as well. It's just annoying because the way JS is designed, neither "never using semicolons" or "always using semicolons" is safe.
I always use semicolons where they belong, or at least, that is my intention. In what way is this not safe?
Would this also force REPL users to write strict JS?
It certainly doesn't increase performance and up until recently was harmful to performance.
Certainly go ahead and use it for writing new stuff, but the idea of blanket applying it downright stupid and dangerous because it *will* often break code not specifically written with the differences in mind.
It certainly doesn't increase performance and up until recently was harmful to performance.This is a bit counter intuitive, but I suppose the checks that it forces adds a cost to performance.
One way to deal with it is to turn it on during the development and may be remove it during the deployment (or in production). If there is a single configuration option with which this can be achieved then it is all the better.
Certainly go ahead and use it for writing new stuff, but the idea of blanket applying it downright stupid and dangerous because it *will* often break code not specifically written with the differences in mind.
I can't imagine code breaking often for using 'use strict' in all use cases. Even if you can avoid it for now, isn't the JS language itself is going in that ( 'use strict') direction. Future versions will be far more less forgiving than the current.
@mark> +1 to adding "use strict" to the module wrapper, so that all server side code is implicitly strict, whether it says so or not. Having uses of octal be a bit more awkward is a small price to pay for the increase in sanity.Bit surprised to hear this from you! It seems dangerous to introduce this.. Without "use strict" it's impossible to tell the toxic waste from otherwise, among other hazards.
On Sun, Jan 22, 2012 at 10:38, Dick Hardt <dick....@gmail.com> wrote:
> If you want node.js to warn on strict, tell the v8 people :)
I wouldn't be opposed to an env/cmdline/compile-time flag to make Node
add "use strict" to all modules it loads. But it'd have to be clean,
and introduce no other hazards, or break anything that already works.
And if it's not demonstrably faster, it won't be the default.
>> I always use semicolons where they belong, or at least, that is my intention. In what way is this not safe?
>
> For the most part you should be fine. The only thing I could realistically imagine biting you is the example above.
> function foo() {
> return
> 'foo';
> }
>
> foo() returns undefined!
Of course it does. I wouldn't expect it to do anything different. :)
It would also never occur to me to write the above code. If I wanted to return 'foo' I would write:
return 'foo';
If I wanted to return undefined I would write:
return;
Not wanting workarounds isn't "lazy". I'm pretty sure that if you have
to replace well-written stuff that just works with "workarounds", this
is a huge -1 on that change.
> (function () {Without the indent. Please.
> "use strict";
> Globals are EVIL. BAD. RUDE. INCONSIDERATE. NASTY.I think you're exaggerating a lot here. What about, for example,
>
> I can't believe I'm hearing support for globals!!
"process"? Or what about logging?
> I'm being sincere. I thought that everyone in the programming communitiesUh? So you're basically saying "globals aren't too bad, but they're
> had gotten the memo that globals and gotos are words you feel dirty inside
> for using (except in the kernel where you use gotos to implement the
> decorator pattern without the overhead of function calls - and the people
> there are hopefully disciplined enough to not make severe design mistakes).
sharp tools that can be used for nasty stuff, so drop them and use
this wooden knife instead"? Yes, it sometimes is bad to use them, and
yes, it's not what we should put on top of tutorials, but we
definitely shouldn't discourage them that much.
What about JSONP? You need global functions for that, no?
> Browser
> ---
> You don't need globals either. A TON of effort has gone in to making sure
> that you can write modular JavaScript. Thanks to RequireJS, Pakmanager, and
> Ender, you can install straight from npm into packed browser-safe code.
> Octals
> ---
> I guess since a lot of people on this list work with c++ for native node
> modules it makes sense.
Uh... and e.g. working with the filesystem, too.
Ah, right, Javascript doesn't belong on the server or so. You're sooo
> But JavaScript is a high-level language primarily used for interacting with
> users.
> If you want to use octals... USE C!
right.</scnr>
> Do you know how many times I've been bitten by parsing user input that had aWell then, sounds like you're using the wrong tools to parse user
> leading '0' and have scratched my head for too long trying to figure out
> where the math had gone wrong? A lot! (but I'm getting better and
> remembering to check for corner cases that strict mode can't protect me
> from);
input. And like you're not reading documentation. E.g. parseInt only
tries to determine the radix based on the input if you don't
explicitely specify it.
In return you will subtly change the functioning of existing code in ways that can be difficult to track down.
Exactly what isaacs said. It doesn't provide a benefit outside of a handful of specific scenarios. It certainly doesn't increase performance and up until recently was harmful to performance.
Mikeal, did you ever know that you're my hero?
In return you will subtly change the functioning of existing code in ways that can be difficult to track down.I don't believe so. All of the changes to strict mode throw errors.this = null -- throws an errorusing octal -- throws an errornot declaring a variable -- throws an errorusing with -- throws an errorin which case would the problem be subtle?
The following actually happened to a friend of mine. A brilliant Smalltalk programmer who has done many impressive things, but had not yet immersed himself in JavaScript arcana for years. In order to use various primitives in a more object-like way, he added (among other things) the following method:Boolean.prototype.not = function() { return !this; };After this, true.not() returns false as expected. Guess what false.not() returns. Making this be instead
Boolean.prototype.not = function() { "use strict"; return !this; };or if this code occurs in a strict context, solves the problem. No nasty hidden coercion surprise.
How aboutfunction foo(str) {var x = 8;eval(str);return function bar() { return x; };}When bar is later called, what x variable does it read?For both of these, the difference is not an easy to diagnose error. It is silent confusion.
The following actually happened to a friend of mine. A brilliant Smalltalk programmer who has done many impressive things, but had not yet immersed himself in JavaScript arcana for years. In order to use various primitives in a more object-like way, he added (among other things) the following method:Boolean.prototype.not = function() { return !this; };After this, true.not() returns false as expected. Guess what false.not() returns. Making this be instead
Boolean.prototype.not = function() { "use strict"; return !this; };or if this code occurs in a strict context, solves the problem. No nasty hidden coercion surprise.Interesting. That's just weird.
How aboutfunction foo(str) {var x = 8;eval(str);return function bar() { return x; };}When bar is later called, what x variable does it read?For both of these, the difference is not an easy to diagnose error. It is silent confusion.Okay, interesting point made.I suppose which is expected would depend on what you would expect.Intuitively I would expect that `str` executes in it's own context and that `x` would always return 8.So in not-strict mode perhaps it's possible to access `x` in `str`?
Globals---
Globals are EVIL. BAD. RUDE. INCONSIDERATE. NASTY.I can't believe I'm hearing support for globals!!
Seriously, that blows my mind.
I'm being sincere. I thought that everyone in the programming communities had gotten the memo that globals and gotos are words you feel dirty inside for using (except in the kernel where you use gotos to implement the decorator pattern without the overhead of function calls - and the people there are hopefully disciplined enough to not make severe design mistakes).