-
Notifications
You must be signed in to change notification settings - Fork 157
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
Idea: add support for dashes in variable names, mangle them #17
Comments
Still thinking about this. |
So then |
Yeah that's why I'm not sure about the idea. Any ideas on how better to do it? |
Use gensym, forget about preserving identifiers in the target. |
I don't think there will be great impact of this it will be implemented as a simple converter to user = document.query-selector('.user')
user.add-event-listener 'click', ((event) -> console.log event), yes
id = window.set-interval ->
console.log 'hello'
, 1000
window.set-timeout (-> window.clear-timeout id), 1500
encoded = encode-URI-component string
number = parse-int '5'
string = number.to-string!
page-text = document.query-selector('body').inner-text
logged-in = $('body').has-class 'logged-in'
obj = {a: 1, b: 2}
descriptors = Object.get-own-property-names(obj).map((name) -> Object.get-property-descriptor obj, name) vs user = document.querySelector('.user')
user.addEventListener 'click', ((event) -> console.log event), yes
id = window.setInterval ->
console.log 'hello'
, 1000
window.setTimeout (-> window.clearTimeout id), 1500
encoded = encodeURIComponent string
number = parseInt '5'
string = number.toString!
pageText = document.querySelector('body').innerText
loggedIn = $('body').hasClass 'logged-in'
descriptors = Object.getOwnPropertyNames(obj).map((name) -> Object.getPropertyDescriptor obj, name) |
Wouldn't that be |
@satyr uppercase letters in vars with dashes can transform as-is, so no. |
Uh right. It'd be author's choice.
would all work as |
Yep, you've got it right. |
@paulmillr: doesn't that strike you as insanely confusing? |
@michaelficarra no, it's one simple rule: a letter after |
Sure, the rule is simple, but it could lead to some really confusing errors when you're not thinking carefully about it, no? |
Errors like what? |
Believing you're working with two distinct variables, when you're actually referencing the same one. It's easy to see, but only if you're actually thinking about the variable name transformation. Also, "How did I separate it above? Was it |
I agree this can cause them but I don't think it will be really popular error. This definitely deserves prototyping. I'll see what I can do.
And this type of confusion could only happen in acronym vars. |
+1 for this feature. I've implemented it in my toy language and while I've ran into the The dash isn't what's confusing, the DOM is confusing with their sometimes inconsistently cased acronyms. |
I don't care enough about this feature to do it myself, but I will accept pull requests. |
I'd just like to say that I love this feature, but I totally disagree with "while I've ran into the encode-URI issue already I feel the benefits far outweigh the headaches." while this is an awesome feature, the headaches caused by it could be almost impossible to track down. Suppose you have a metric called "TCHA" in your code (doesn't matter what it means) and you're using CAPTCHAs somewhere. Maybe you have two global functions called This should at least be documented on the homepage so that users can find out about the feature without digging through the issue list. |
It wouldn't be difficult to keep track of identifiers somewhere and throw a compile error when two identifiers mangle into the same camel-cased identifier. I can provide a patch for this if there's interest. |
@goatslacker: I think that's a great solution. |
Landed in 3b1a69d now you can call your function |
Why this was landed? I don't think stuff like edit oh well, I understood now what this did. |
@paulmillr is drunk githubbing. |
I might submit a patch to make it only fail on compile if it finds two variables which would mangle to the same thing but use different hyphenation. probably has to wait til tomorrow though. |
lol nevermind, i just looked at the commit info, seems that what you did. so |
Why dashes?
Cons:
-
will be prohibited from using as OP without indenation likea - b
(which is good IMO).Examples
Examples
Clojure. Pretty readable.
reposted from jashkenas/coffeescript#2345
The text was updated successfully, but these errors were encountered: