Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I haven't programmed in Coffeescript, but does it bother anyone else that new variables are introduced without "var"?

When reading js, seeing the "var" really helps me to know the programmer's intent that this is a new variable being introduced, not an attempt to reassign one that should already exist. Does CS have features that make this point mute?



> I haven't programmed in Coffeescript, but does it bother anyone else that new variables are introduced without "var"?

Yes. I've come to see it as a mistake in Python and Ruby both, and I'm definitely not pleased by its usage in CS. Even less so as it uses the same rules as Ruby's lambdas without the stops of its methods and global scopes.


Actually I think this is a big plus, as it's much more common to want to declare a new variable than to want to reassign a global, and hard to notice when something is missing like "var". It would be nice if there was an explicitly different operator for reassignment. (p.s. I think you mean "moot")


For more discussion of this feature -- see yesterday's conversation on Reddit: http://www.reddit.com/r/programming/comments/zx137/coffeescr...


Nope, and I don't miss having to have all of the var statements everywhere.

Can you provide an example in js where knowing whether it's a new var vs. reassignment is useful? I can't think of a case, but it could just be me.


This doesn't bother me at all. Mostly because this feature comes from Ruby and so I'm already used to it, but also because it takes away the nasty surprise that JavaScript gives you if you leave 'var' out. I find this invaluable. As for knowing whether or not a new variable is being declared, well, that's why you keep your functions (and therefore your scopes) short.


> This doesn't bother me at all. Mostly because this feature comes from Ruby and so I'm already used to it

This and that are completely orthogonal though, I've been using Python for 8 years and Ruby for 6 so I'm used to implicit scoping. Doesn't mean I like it, or find it a good idea to use it in new languages (I don't).

And the issue is actually bigger in coffeescript than in ruby and python both, interestingly because (through javascript) coffeescript's scoping is much more regular than Python's or Ruby's.

The only language in which I don't know implicit scoping to be an issue is Erlang, because it uses bind-once and immutable structure semantics.

> also because it takes away the nasty surprise that JavaScript gives you if you leave 'var' out.

That can trivially be fixed by linting, or using strict mode. That's really no argument.


I think it depends on what you are used to. I find "var" to be noise.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: