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

adding ? and ! to methods #48

Closed
weepy opened this issue Jan 6, 2010 · 7 comments
Closed

adding ? and ! to methods #48

weepy opened this issue Jan 6, 2010 · 7 comments

Comments

@weepy
Copy link

weepy commented Jan 6, 2010

It's incredibly useful in Ruby to be able to end methods with ? and ! We could rewrite the variable names to include these as text. E.g.

exists?: x => typeof x != 'undefined' && x != null
merge!: x, y => x = x.merge(y)

compiles to

exists__question = function(x) { return typeof(x) !== 'undefined' && x !== null }
merge__exclamation =  function(x, y) { return x = x.merge(y) }

I realize that there's a clash with the existence operator here -- but it would be really useful and we could come up with another operator for existence e.g. if ?obj or if obj??

@breckinloggins
Copy link
Contributor

in a sense, it might not clash. You could argue that

if exists?

and

if exists?(x)

Are pretty consistent. They both ask the same type of question, only the latter is more specified. The one problem I have with this, though, is what is the value of the expression

if exists?(x)

If exists isn't a function?

Lastly, I personally find ! to be more useful semantically than ?, so ! could be incorporated by NOT ?; that might be an option.

@weepy
Copy link
Author

weepy commented Jan 6, 2010

I think it would be least confusing to have a separate operator, my vote goes with my_var??.

@weepy
Copy link
Author

weepy commented Jan 6, 2010

I use ! and ? quite alot in ruby, as I find it useful semantically. I.e. potentially unsafe operations can be tagged with ! and questions with? It would be entirely an opt in feature - if you don't like the style, don't use it.

On the other point converting my_var? to myvar_question_mark is hardly name mangling.

@noonat
Copy link
Contributor

noonat commented Jan 7, 2010

This feature request has the same problem as symbols: there is no direct mapping to JS. The direct mapping to JS is what makes Coffee so great, and as soon as you have to start mapping to alternative names, you end up with annoying behavior.

e.g., if a library uses lowerCamelCase, the method name foo? should be renamed to something like isFoo. If, however, Coffee makes the assumption of lower_underscored, you end up with naming clashes in the generated code. Not pretty.

In my opinion, not worth the loss of clean JS portability.

@jashkenas
Copy link
Owner

Yep. What noonat says is absolutely right. We can't start fiddling with identifiers. Documentation for CoffeeScript libraries should be usable by JavaScript developers and vice-versa. No translation required. If we step away from that, we take a major step away from being a viable alternative way to write solid JavaScript libraries.

Closing the ticket...

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

No branches or pull requests

4 participants