-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Alternate Form for Parentheses #1614
Comments
One major setback with this proposal is that As for the idea: it's one of those features I absolutely love about Haskell but I'm not really sure whether it's appropriate for coffeescript. A simple explanation of my understanding of the You might be interested in #1429 as well. |
Just to throw a quick reaction in here, this syntax is fascinating, but strikes me as horrifically unreadable. The beauty of parens in nested method calls is that they're the same way you'd group things in English, as well as in Math. The best way to write this seems to be:
... or better yet, with local variables. |
I love the $ in haskell. Once you have many operators at different precedences, you have to use parenthesis, But it is ok to invent syntax for very common operators. But, because of many toolkits using method chaining, method calls are more common than function application in coffeescript. I would like a low precedence method call operator to avoid parenthesing the method call parameters. Let's take an example from http://geekiriki.blogspot.com/2010/08/jquery-meets-coffeescript.html show_message = (msg) ->
$('#message').hide().text(msg).fadeIn(2222,
-> $('#message').append('!')
) Anyway, to be fair, the example can be written show_message = (msg) ->
$('#message').hide().text(msg).fadeIn 2222, -> $('#message').append '!' Using the -.- as low precedence . operator, we get show_message = (msg) ->
$ '#message' -.- hide().text msg -.- fadeIn 2222, -> $ '#message' -.- append '!' This is not shorter in term of characters count, but that suppress the parentheses clutter -> seen as an operator bind less then .-. I suppose you can combine method chaining with fonction application. I suppose that functionsapplication |
Function calls in haskell don't have commas. And the language itself has currying. I don't think that function application would be a great idea for coffee script, if there will be no built-in currying and 'comma-less syntax'. genOutput number = return $ concat $ mapMaybe numberToValue [1..number]
vs
genOutput number = return(concat(mapMaybe numberToValue [1..number])) |
@paulmillr: "currying", as in the mathematician Haskell Curry. |
@michaelficarra sorry, just a typo. fixed. |
@paulmillr: sorry, didn't mean to nitpick a typo, but it was made twice (and they were identical), so I thought you might rather be educated. |
@michaelficarra -- Yes, I wasn't actually thinking we should use the @jashkenas was thinking that this would be pretty unreadable, and @paulmillr had a good point that the @cognominal's idea on using something like this for chaining function calls without having to use parens stood out to me as a great example of where parentheses could be eliminated in both a practical and useful way. I don't know if
The rationale for the As for the readability of this snippet, I'm not totally sure. I suppose that because it isn't natural for us to see this we immediately brand it as "unreadable" (I admit it doesn't seem terribly readable to me). The successful use of a similar operator in haskell, however, seems to indicate that it would be readable if we were used to it. Looking at that, I think I could get used to it, providing the line isn't too long. A snippet like this would be more readable:
Thoughts? |
@benekastah I am very open on the choice of the alternative method call operator (MCO) name. My point is that the visual aspect of it matters very much. Also my comparaison with the $ was to show that one can go to totally opposite direction in this visual choice. I chose -.- because it contains a dot like the standard MCO and its length is a hint at the low binding. May be three characters is going overboard. So -. would be enough. -.- being symmetric hints at a commutativity that does not exist. But I like &. even more. The & is visual reminder that somethings stands before that is handled by that operator. The -.- is in fact five characters because it needs space around to stand out when &. does not so we got 2 chars vers 5. @paulmillr I agree that $ (or whatever token chosen) works better with haskell syntax. |
Howdy. This is related to #1520, except this:
Will currently produce this:
But I reckon I'll probably make it more like what you are suggesting:
|
I have made this change, and it's actually more consistent (read: correct) with respect to the indented syntax:
Is the same as:
And:
|
@alexkg looks interesting! I'll have to try out your branch soon. |
In Haskell there is the
$
operator which helps you avoid parentheses. I think this is great because it would establish readability without having to worry about marking the beginning and the end of a parenthetical grouping (inasmuch as it can be inferred correctly with the slightly more limited$
operator).A few examples:
In this case, the rule is that wherever you would put an opening paren, you simply put a
$
instead. The closing parens will be inserted at the end of the line. I believe this is the way Haskell does it.An interesting alternative would be to put the
$
in the place of the closing paren instead. This way, you could insert them as you realize you need them a little bit easier. It may also be more handy to interrupt the normal parenthesizing process for custom behaviors. This would require a different example:The text was updated successfully, but these errors were encountered: