Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyphens for identifiers #137

Closed
satyr opened this issue Jun 6, 2012 · 26 comments
Closed

hyphens for identifiers #137

satyr opened this issue Jun 6, 2012 · 26 comments
Milestone

Comments

@satyr
Copy link
Owner

satyr commented Jun 6, 2012

gkz/LiveScript#28
jashkenas/coffeescript#2370

Allow - before an alphabetic character within identifiers just like Perl6, transforming to camelCase.

Pros

  • Can satisfy and/or shut up snake_casers, preventing API style fragmentation.

Cons

  • Incompatibility. x-y will no longer be a subtraction.

Thums-{up,down}s?

@vendethiel
Copy link
Contributor

Makes me think about jashkenas/coffeescript#425
Like @jashkenas said :
"Unfortunately, we can't muck with literal identifiers. Since you can access the property of an object by a string index (obj["camelCase"]), or a variable (obj[name]), it's really out of the realm of possibility..."
What'd happen if we were to use a variable? The only (and ugly!) solution would be to apply a function to each time [] is used. Did I forgot legacy part using eval ?

@satyr
Copy link
Owner Author

satyr commented Jun 7, 2012

What'd happen if we were to use a variable? The only (and ugly!) solution would be to apply a function to each time [] is used. Did I forgot legacy part using eval ?

Hm? I don't follow. Can you show me code example(s) that would be problematic?

@goto-bus-stop
Copy link

an-object = key-one: 1 key-two: 2
an-object.key-one is 1
an-object.'key-two' is not 2

@satyr
Copy link
Owner Author

satyr commented Jun 7, 2012

an-object.'key-two' is not 2

Expected since key-two would be the same as keyTwo on as early as lexing. We have several aliases act like this already:

$ coco -se
  o = :: : 1
  console.log o.prototype, o'prototype', o::, o'::'

1 1 1 undefined

@vendethiel
Copy link
Contributor

@satyr

obj:
  real-name: 'coco'

attribute = 'real-name'
obj[attribute]

obj will be {realName: 'coco'}, and that co will do obj['real-name'], so that'll fail.

@satyr
Copy link
Owner Author

satyr commented Jun 7, 2012

Note that plain JS has similar quirks as well:

$ node
> o = {0x1: 2}
{ '1': 2 }
> o['0x1']
undefined

They are trivial compared to the incompatibility:

$ coco -bcs
  obj:
    real-name: 'coco'

({
  obj: real - {
    name: 'coco'
  }
});

@mcfog
Copy link

mcfog commented Jul 10, 2012

IMO, this feature sounds unnecessary and may hurt readability

#wtf
hidden-height = scroll-height - scroll-top - visible-height

vs

hiddenHeight = scrollHeight - scrollTop - visibleHeight

vs

hidden_height = scroll_height - scroll_top - visible_height

long variable name should be completed by editor so what separate words don't matter so much

@vendethiel
Copy link
Contributor

After using it, I have the feeling that it's not so bad.

@goto-bus-stop
Copy link

I'm pro-this, by the way; although it's odd that (a): b might not be accessible through b[a], it would certainly be useful in many cases.

$ \#asdf .animate do
  margin-top: 1000px
  background-color: \#000

@satyr
Copy link
Owner Author

satyr commented Jul 11, 2012

ups: 2, downs: 1

long variable name should be completed by editor so what separate words don't matter so much

It comes to matter when you're dealing with public API, where camel case is the de-facto standard.

@satyr satyr closed this as completed in f4d34db Jul 28, 2012
@andrewrk
Copy link

andrewrk commented Aug 6, 2012

I'd like to see this removed. It's confusing and pointless. Variables compile to camelCase, so why not just use camelCase? Instead when reading code, one has to have more cognitive overhead to understand this fact.

Also, as a snake_caser, I feel alienated.

@satyr
Copy link
Owner Author

satyr commented Aug 6, 2012

as a snake_caser, I feel alienated

You deserve it. JavaScript has never been java_script.

@andrewrk
Copy link

andrewrk commented Aug 6, 2012

That's title case!

@vendethiel
Copy link
Contributor

it's so more readable with dashes than being camelCased ...

@andrewrk
Copy link

andrewrk commented Aug 6, 2012

  1. That is subjective.
  2. It does not compensate for the 2 issues mentioned above:
    • Confusion / complication with arithmetic operators.
    • Cognitive overhead when reading code.

And here's another thing:

For some language features, if you don't like them, you can simply avoid them. For this language feature, I am forced to understand this concept, because this seemingly simple code:

c = a-b

Compiles differently than I think it should. So every line of code which has a dash, I have to keep this cognitive overhead in mind, even if I don't use dash-variables anywhere.

This feature makes the learning curve of coco steeper, harms the readability of coco, and the benefit that it gives is subjective. My subjective view of the way dash variables look is that they look harder to read than camelCase.

@andrewrk
Copy link

andrewrk commented Aug 6, 2012

Also just to be clear, when I say I am a snake caser, this is what I mean.

some_variable
SOME_CONSTANT
someFunction
SomeClass

One convention to rule them all.

@satyr
Copy link
Owner Author

satyr commented Aug 6, 2012

some_variable

some_non_function_variable you mean? That's an interesting variation of Hungarian notation.

@vendethiel
Copy link
Contributor

I've read some science article about how is the brain reading, and apparently it's not that "subjective", the brain does the separation better.

@andrewrk
Copy link

andrewrk commented Aug 6, 2012

The fact that the brain separates the words better makes it less readable. You don't want to read aVariableName as 3 words; you want to read it as one word.

@vendethiel
Copy link
Contributor

It depends whether I want it to be understandable or not, I guess.

@andrewrk
Copy link

andrewrk commented Aug 9, 2012

I am porting some code to coco from coffee-script, and now I have to go through the code looking for this.

@satyr
Copy link
Owner Author

satyr commented Aug 9, 2012

I have to go through the code looking for this

Why? Were you using this feature even though you didn't like it?

@andrewrk
Copy link

andrewrk commented Aug 9, 2012

from coffeescript to coco

Because the code might have a = b-c and I would need to insert a space around the hyphen.

@andrewrk
Copy link

andrewrk commented Aug 9, 2012

It actually was pretty painless with a good regex, but it seems relevant to this thread.

@michaelficarra
Copy link
Contributor

@superjoe30: Ever heard of regexps?

edit: looks like you have

@vendethiel
Copy link
Contributor

Something like /([^\s]+)\-([^\s]+)/, "$1 - $2" I guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants