-
Notifications
You must be signed in to change notification settings - Fork 2k
backslash line continuation pre-object breaks objects #2457
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
Comments
I think you have a big misunderstanding about backslashes. Backslashes cause the following newline to be ignored. Would you expect callFunction arg1, object_key_1: data1
object_key_2: data2 to compile? Of course not. |
Ah, got it. Was a misunderstanding indeed -- I thought backslashes just "forced" the next line to be interpreted as part of the same statement, not that they literally removed the newline from parsing. Is there a way to get this backslash behavior officially documented? I'd do a whole pull-request thing with the website and add it myself, but I don't know if that's the preferred way or not for CS. Anyways, thanks, closing the issue. |
Pull requests are always welcome. Whether or not we want line-continuing backslash in the documentation is a different question. |
Right, I'd be happy to add it, but only if it's wanted. My $0.02 is that I wish the CS docs were much more comprehensive; I feel like half of what I use day-to-day in CS is undocumented and was learned from frustrating trial and error, and a lot of time could have been saved if things like backslashes were in the docs, since they're clearly a core and necessary language feature to write things that can't be achieved any other way (like the switch statement at the top of this issue). |
... for what it's worth, the reason they're not in the docs is because you're not really supposed to ever have to use them. I'd write your initial example like this:
... where |
Hi Jeremy, thanks for the suggestion. First of all, I didn't even know you could use a switch statement without a parameter after the Although I feel like hiding the switch values inside a function defeats the whole purpose of the switch statement, which is to be able to compare a single values to other sets of values in a straightforward (and, above all, visible) way. To write a maintainable solution without using backslashes, I suppose I'd have to rewrite the whole switch as a big |
I tend to use backslash line continuation liberally, since I've been bitten by a lot of times when CoffeeScript breaks without it, for example this breaks if any of the backslashes are missing:
But now I'm being bit by the opposite, I tried writing:
But it compiles, bizarrely, to:
I can't imagine why it's splitting up the object. Removing the backslash produces the desired behavior:
produces
Now, backslashes aren't even a documented functionality of CoffeeScript, at least not that I can find on the website, despite the fact that they're sometimes required for multi-line functionality (as in the
switch
above). And I can't figure out for the life of me when they're required, and when they're not, except through trial-and-error.But the fact that they break existing code when they're added in places where they should just be redundant, seems like a bug, unless there's something additional that backslashes mean that I'm missing.
Basically, shouldn't I be able to add a backslash to the end of any line (except perhaps object property lists, and of course multiline strings), without it changing the meaning of my code? So I'm filing this as a bug... Please correct any misunderstandings I may have here, though!
The text was updated successfully, but these errors were encountered: