-
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
Dart Monocle Mustache #1889
Comments
Right -- the interesting thing about this being that it's all about method calls and chaining, not just property merges. |
-1. Feels like feature creep. This is the code that is being syntactically cleaned up:
The above code seems to violate the DRY principle, but it's a case of the syntax actually revealing repetition, not causing repetition. |
Also see #1431. |
And especially #1495. |
This is the Hemingway vs. Faulkner debate.
|
@showell: I think you've just made the most persuasive argument in favor of local variables that I've ever heard. Nicely done. |
@jashkenas Thanks! I still think it's an interesting debate...I'm not completely oblivious to the benefits of nesting. But I like the way I framed it... :) |
Or Perl vs Python: given (<>) {
s/f/b/;
print uc;
} import sys
s = sys.stdin.readline()
s = s.replace("f", "b")
print(s.upper()) |
Current chaining works very well for me: items
.map (item) ->
someRandomThing
bla bla bla
item
.filter (inner) ->
inner?
.sort (a, b) ->
a - b
.reduce (memo, value) ->
memo - value
.reduce (memo, value) ->
bla bla bla
bla bla bla In the cases of one-line methods it requires additional brackets, but it's still OK: items
.map((item) -> bla bla bla)
.reduce(((memo, value) -> bla bla bla), 0) So, 👎. This is creepy and strange feature. |
@paulmillr I am -1 like you, but just to play devil's advocate, your chaining example is slightly semantically different than the Dart proposal, which allows you to DRY up multiple calls on the same object, even if the called methods don't support chaining. |
@showell hmm, you're right. I've re-readed explanation and discussion, but it's still too strange / PERLy for me. |
Like most of the folks in this thread, I don't like the monocle mustache. Whenever I give a talk on CoffeeScript, I like to tell people that while curly braces can mean a zillion things in JavaScript, they're only used for one thing in CoffeeScript: object literals. (And destructuring assignment, which is the inverse of an object literal.) DRY cascading would be nice, but only if there were a clean, CoffeeScript-y syntax for it. The syntax proposed by @raganwald at #1495 is powerful enough to do this, at the expense of making our whitespace rules quite a bit stricter. (I think the tradeoff is worth it.) To borrow the example from the Dart mailing list, here's how it looks under CoffeeScript now:
Here's how it could look under the raganwald proposal, combined with the proposal at #1407 to make implicit parentheses end at
(This is, of course, assuming that we don't actually need to keep references to |
👍 |
👍 for the feature; 👎 for Dart's syntax. As has been said before, we have indentation to indicate nesting levels. C: |
I know that CS is only superficially similar to Python, but to the extent that Python offers any kind of guidance in the realm of indentation-based languages, they were fairly conservative about overloading the semantics of indentation. Python did eventually adopt a "with" statement, but it was more about resource teardown than syntax sugar: http://www.python.org/dev/peps/pep-0343/ The VB "with" statement is sementically equivalent to this proposal, with slightly heavier syntax, correct?:
|
I agree with all the arguments against inclusion of this feature. -1. |
-1. It just looks ugly. |
In Clojure: (doto someObject
(method1 withArgs)
(method2)
(method3)) CoffeeScript already has |
-1 this looks just awful, it doesn't belong in such a beautiful language like CoffeeScript |
That's why it hasn't been added yet. The reason everyone is still discussing it is the hope that, somewhere, somebody will come up with a way to do this while staying true to CoffeeScript's simplicity and beauty. Until that happens, rest assured that it won't make it into the language. My personal opinion is that if this is going to make it in, it has to be a more general construct of which this issue is but one use case. |
I've been using a little method added to Object.prototype, similar to the
Of course this isn't reliable cross-browser, but it's the closest possible mapping ATM to the indentation proposal. |
@ricardobeat Yeah, I've been doing similar with a global
Out of curiosity, why do you call |
Does it make sense to close this issue? It seems like nobody like the Dart proposal, but there are quite a few people who like the @raganwald proposal at issue 1495. |
@erisdiscord |
@ricardobeat ooh, I hadn't thought of that. Thanks! |
... sure thing -- closing. |
Good idea? https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/611c04100ac17142
The text was updated successfully, but these errors were encountered: