I've ran into an interesting issue with Array.prototype.forEach with
the latest node from git.
function Something(){
['one', 'two'].forEach(function(){})
}
if I call new Something(); this will work find and the forEach
executes. However if I declare some variable first
function Something(){
var a = 'a'
['one', 'two'].forEach(function(){})
}
and create a new instance it throws the exception TypeError: Cannot
call method 'forEach' of undefined. Assigning the array to a variable
works though
function Something(){
var a = 'a'
var b = ['one', 'two']
b.forEach(function(){})
}
Any idea what's up?
Thanks,
James
http://en.wikipedia.org/wiki/Space-time_tradeoff
In this case you're trading trailing semicolon bytes for time debugging.
Matthias
>
> and create a new instance it throws the exception TypeError: Cannot
> call method 'forEach' of undefined. Assigning the array to a variable
> works though
>
> function Something(){
> var a = 'a'
> var b = ['one', 'two']
> b.forEach(function(){})
> }
>
> Any idea what's up?
>
> Thanks,
> James
>
> --
> 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.
>
>
On Sat, Jul 24, 2010 at 5:36 PM, James Carr <james....@gmail.com> wrote:http://en.wikipedia.org/wiki/Space-time_tradeoff
> Hi All,
>
> I've ran into an interesting issue with Array.prototype.forEach with
> the latest node from git.
>
> function Something(){
> ['one', 'two'].forEach(function(){})
> }
>
> if I call new Something(); this will work find and the forEach
> executes. However if I declare some variable first
>
>
> function Something(){
> var a = 'a'
> ['one', 'two'].forEach(function(){})
> }
In this case you're trading trailing semicolon bytes for time debugging.
Is there really a performance drawback for not using semi-colons in V8?
Thanks,
James
Heh. Where's the no-semicolon crowd now? :)
--
Putting unnecessary semicolons everywhere is not the answer! Don't
believe the hype. Trust your aesthetic senses, they're right and good
and you should honor and value them. Stay true to your minimalist
spirit!
Just don't start lines with "[". Start them with ";[" instead, and
then you'll be able to copy and paste them anywhere, without worrying
about what's on the line above. Same for "(", for similar reasons.
;(function (){
var a = 'a'
;['one', 'two'].forEach(function(){})
})()
That way, you're only applying semicolons where they're actually relevant.
*Every* JavaScript engine works the same way in this regard. There is
absolutely no loss of portability, and no performance impact.
--i
1. Marco has feelings about semicolons.
2. Starting with ; looks like some other construct from some other language.
You realize these are about the silliest possible arguments that could
be made, right? I mean, you're not saying anything. So, here's a
fitting rebuttal:
1. Isaac has other feelings about semicolons.
2. Magical imaginary pixies always have exactly three wings.
3. My list has one more thing in it than yours.
Ergo, semicolons should be minimized.
I propose a rule that we are only allowed to discuss this subject in
person, and after no fewer than 5 beers apiece, so at least we'll have
a good excuse for getting silly and belligerent. Or state your
priorities up front, so that we can say things that have objective
meaning.
I'm only being dismissive because this is a very stupid subject.
--i
I've seen it. He doesn't go into the details about how JavaScript
breaks statements. He tells a few scary stories and shows some broken
code. He wrote a JS parser, so I assume he knows how it works.
Here's an explanation that is based in facts rather than FUD:
http://inimino.org/~inimino/blog/javascript_semicolons
--i
if a=b then
else
/if
Is much more readable to me than
if (a==b) {
} else {
}
But I don't mind because JavaScript makes up for it. I just started running my code through Crockfords jslint and I must say it has improved my codes readability to me at least.
Terry
Sent from my iPhone
We'll then
if (a===b) {...
must cause you conniptions. What if one wanted to actually evaluate the result of an assignment?
It's worth noting that Ryan requires semicolons in nodejs code, and a
LOT of "big" node projects use the JSLint style. It's not my intent
(or TJ's, I'm sure) to browbeat anyone. I just have an issue with
people being wrong on my internets, especially when someone comes here
asking a question and gets the wrong answer. So if someone says that
semicolonless code isn't browser-safe, or compressible, or portable,
or performant, I feel the need to pipe up and point out the FUD.
For what it's worth (that is, for roughly nothing), I don't use them
in npm because:
1. It's harder for me to scan code when relevant tokens are on the
jagged-right edge.
2. The reduction in tokens, while jarring at first, is significantly
easier to scan once you get used to it.
3. npm has a lot of long lists and one-liner functions, so it's not
like there'd be a ton of semicolons anyway. They just seemed
extraneous.
I write npm for me, and it's great that some folks have found it
useful, but like... it's a hobby, and I'm going to write it in a way
that brings me artistic satisfaction. No one pays me to work on it,
it's just a fun problem space. It's like Mr. Miagi with the bonsai
tree. Your tree doesn't have to look like mine, and that's not what
it's about anyway. The JavaScript community is a peaceful anarchy.
If we're gonna talk about HOW to safely write semicolonless code (eg,
the suggestion to start lines with ";[" rather than "["), then that's
great, and super interesting, and there a lot of fascinating things
there. But this context-free "is it better to use them or not" meme,
gah, it's so lame.
And here I am totally making things worse by reacting to it. So, there's that.
--i
Ergo, I don't care about this conversation.
Huh, these random lists are fun :-)
JavaScript is not a perfect languages.
But it turns out humans don't much like using perfect languages. We
like the *idea* of them, but there's a reason English is more popular
than Esperanto, just as JavaScript is more popular than Common Lisp.
--i
Starting lines with ( is as problematic as starting them with [. You
need to wrap lambdas in parens so that the interpreter treats it as a
function expression rather than a function statement. There's no need
for parens around anonymous arrays.
On Sun, Jul 25, 2010 at 08:49, Victor S <victo...@gmail.com> wrote:
> It allows you to waste so much time debugging because of 'invisible'
> semicolons
It's not "invisible" semicolons. That's not how the language works.
> No weird formatting to confuse people,
You don't think C-style formatting is weird?
> in most other languages if you
> make syntactical mistake you know it right away, error, done, no more
> arguments.
If you make syntax errors in JS, you know right away, too.
JS isn't C. Its a different language, with a different syntax.
--i
I think they do, but they don't know it yet.
> We like the *idea* of them, but there's a reason English is more popular
> than Esperanto, just as JavaScript is more popular than Common Lisp.
And what is that reason, oh, please enlight us with your infinite wisdom!
I'd take CL anytime. Unfortunately, we don't have much choice... JS is
still pretty good, compared to many others, so at least there is hope.
Cheers,
-Mihai
Also, down with unnecessary semicolons! Think of them as a
disambiguation character for js's permissive whitespace policy.
–Jacob
(typed on a tiny keyboard)
On Jul 25, 2010, at 11:07 AM, "Mihai Călin Bazon"
<mihai...@gmail.com> wrote:
They've had a lot of time to try to figure it out, and there have been
lots of attempts. So, I'm doubtful it's a question of "yet".
>> We like the *idea* of them, but there's a reason English is more popular
>> than Esperanto, just as JavaScript is more popular than Common Lisp.
>
> And what is that reason, oh, please enlight us with your infinite wisdom!
I have no idea. Just speaking empirically. My wisdom is finite.
--i
Seems like this would be a reasonable occasion on which to plug
sibilant (and coffeescript, for that matter). Write in a more
aesthetic language that compiles to js and get the advantages of both.
Also, down with unnecessary semicolons! Think of them as a
disambiguation character for js's permissive whitespace policy.
You missed one option: IDGaF
=)
Right, because semicoloned code NEVER has bugs, right? ;P
It also always work if you prefix the rare leading [ and ( with a
semicolon. The bugs that semicolons prevent are easier to prevent
with a prefix (because it's more easy to spot when it's missing), and
are also not very hard bugs to fix.
This is nothing but FUD. You could also argue that type coercion
sometimes causes bugs, so you shouldn't ever coerce strings to
objects. But I'm gonna go ahead and keep calling substr and length on
string natives.
The vote and appeal to authority adds no new information. We already
knew which style was more common, and which style Crockford prefers.
If commonness or Crockford-approval are important to you, then the
data is as clear as ever. Adding more data convinces no one of
anything. Clearly, the no-semicolon crowd doesn't care about the
crowd or the Crock.
I'm ok with you using semicolons. I'll follow your style if I send
you a patch request. You could even make that choice for reasons that
I think are silly; it's each hacker's responsibility to decide what's
important for the projects they own. I just wish that the lies and
fearmongering would stop. It's a cultural problem in the JavaScript
community. People try to solve their problems by following rules,
believing that the underlying logic is too hard, when in fact, it's
not very complicated at all. Then they make these noisy claims about
"hard to trace bugs".
npm is over 3500 lines of JavaScript, using most of the NodeJS API
surface, and doing some complicated juggling between radically
different configurations, file systems, and HTTP. I'm not trying to
toot my own horn here, but I believe that I am more qualified than the
average JavaScripter to say that, given a few simple guidelines, the
"semicolons prevent hard bugs" argument is pretty much bunk. npm has
bunches of tricky bugs -- I'm *very* aware of that -- but they're not
because of the syntax.
You cannot convince someone of anything until you know their
priorities. You learn that by asking, not telling. Sometimes, you
may learn that what they're doing, while not the way you do it in your
situation, makes perfect sense in theirs.
--i
2010/7/26 Felix Geisendörfer <fe...@debuggable.com>:
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
This isn't homesickness, but rather a desire to clear away the dust
and clutter in the home I love.
--i
"the thing is, when you put semicolons at the end of each instruction,
it always works."
Right, because semicoloned code NEVER has bugs, right? ;P
It also always work if you prefix the rare leading [ and ( with a
semicolon. The bugs that semicolons prevent are easier to prevent
with a prefix (because it's more easy to spot when it's missing), and
are also not very hard bugs to fix.
Having no semicolons in the end, just forces you to use more
whitespace, more new lines, before that
I would just use semicolons to do lot of jobs in one line, making my
code ugly and unreadable.
Commas first, are much better, you no longer need to go on the
previous line and add a comma
if you want to add a new item. The comma defines the new item, which
is what it's supposed to do.
So it goes with it, on the same line and that's the right way, I see
it now. Also this style forces you to use more
whitespace, indentation and newlines making the code more readable.
Also I tried using a space before the bracket on functions, and a
space before the parenthesis on closures, like this:
'function foo() {', 'var foo = function() {' for functions and
'function (){' for closures, although I have yet to see the
benefit from that other than it probably makes it a bit easier to spot closures.
I can't go back, even in 3 days using this style, everything else just
doesn't look as good. And I've never written
cleaner code like this before. I'm definetely keeping it.
2010/7/27 Bradley Meck <bradle...@gmail.com>:
Are there no minifiers that simply strip spaces from the front of each line?
--
Michael Fellinger
CTO, The Rubyists, LLC
I check email a couple times daily; to reach me sooner, use:
http://awayfind.com/manveru