gkz / LiveScript

LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
http://livescript.net
MIT License
2.32k stars 155 forks source link

LS should allow numbers after hyphens #960

Closed ozra closed 7 years ago

ozra commented 7 years ago

I've been coding LS for yeeears, and finally I think I should issue a complainty complaint... feature wish...

So after that ado:

Thoughts?

foxbunny commented 7 years ago

I've only been coding LS for a while, on and off, never run into this before, but now that it's brought up, I'd say this is a proper bug.

determin1st commented 7 years ago

you mean variable names in code?

ozra commented 7 years ago

Haha, yes.

a-foo-1 = 47
a-foo-2 = 42
a-foo = 49
a-foo-1 is a-foo - 2
determin1st commented 7 years ago

You may use alphabet, to follow this style, for example:

a-foo-a = 47 a-foo-b = 42 a-foo = 49 a-foo-a is a-foo - 2

Personally, I use a similar approach,

a = 1 b = 2 c = 3 a == c - 2

rhendric commented 7 years ago

For that matter, a-foo1, a-foo2, etc. are also valid identifiers.

I'm of the opinion that this would be too potentially disruptive a change for too little a benefit for LiveScript's current stage of maturity. Seems like a decent thing for any LiveScript successor languages to consider, though.

foxbunny commented 7 years ago

Docs say:

Lisp hackers, you may be pleased to know that you can use dashes in the name of your variables and functions.

In LISP, you can do this:

(define foo-2-bar 12)

In LiveScript you cannot. Therefore, my conclusion is that this is a bug. I don't know why fixing this bug would be disruptive, though. In a language that allows hyphens in variable names, I'd like to believe nobody would even think of writing foo-12 to mean foo - 12.

rhendric commented 7 years ago

I regret to inform you that, despite what you'd like to believe, the LiveScript source itself has over 30 occurrences of i-1, op.length-2, etc. Do you have any reason to believe that the general population of LiveScript programmers is universally more strict in this regard?

foxbunny commented 7 years ago

Do you have any reason to believe that the general population of LiveScript programmers is universally more strict in this regard?

I no longer do. If LiveScript code base itself has such ambiguities, I guess there is no other way than to live with it.

gkz commented 7 years ago

This was done on purpose to allow for existing uses where the subtraction operator was used without spaces. This is especially prevalent in array indices, eg. arr[i-1]

ozra commented 7 years ago

@determin1st - yeah, I know :) But I want foo-1-mongoose-2, but... I've survived so far without it. Worse is all languages that don't accept dashes at all :)

@rhendric - seems LiveScripters are less prudent than the typed-langs populace then (that was the majority of code I analyzed to be honest). My "assumption" on the LS-crowd was rather tongue in cheek though, but the facts are welcome ;-). Non-typed-lang users usually code more "hacky" in my experience — so it's not entirely surprising (I code more "hacky" in LS than in C++, Onyx, Crystal... so it's not to throw blame or anything)

@gkz - yeah, it's obvious that it's purposefully designed that way, I didn't think it was an error vis a vis specs - I just believe that allowing it would be more useful than non-spaced subtraction :)

Well, I think we can definitely conclude (based on @rhendric's research) that this is a definite no go, I'll close this.