Skip to content

{+flag}, {-flag} as shorthand for {flag: true}, {flag: false} #885

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

Closed
TrevorBurnham opened this issue Dec 1, 2010 · 8 comments
Closed

Comments

@TrevorBurnham
Copy link
Collaborator

It's great that {foo} is shorthand for {foo: foo}, because that's a common (and awkward) construction; {option: true} and {option: false} are also very common, and a series of options could be made much more readable by introducing a shorthand. For instance, instead of

options = {invert: true, buffer: false, copy: true, thumbnail: false, zoom: true}

you could write

options = {+invert, -buffer, +copy, -thumbnail, +zoom}

I see this as a significant improvement in readability—it's much easier to check whether a particular option is enabled or disabled— as well as sheer succinctness.

Note that I'm proposing that this syntax only work inside of explicit curly braces, just as the {foo: foo} shorthand should only work that way (currently, no one has figured out how to implement this desired behavior).

@satyr
Copy link
Collaborator

satyr commented Dec 1, 2010

Like the idea, but prefixing +/- seems problematic as they mean completely different things elsewhere. Postfix maybe?

options = {invert+, buffer-}

@TrevorBurnham
Copy link
Collaborator Author

Hmm, I find the postfix form a little less readable (due to spacing), and it would still be ambiguous in a curly-brace free context, since

a = b+
c

is a legitimate way of writing a = b + c. Within curly braces, neither syntax is ambiguous.

@satyr
Copy link
Collaborator

satyr commented Dec 2, 2010

Wasn't talking about debracability (?) there (though it's a possibility in postfix version). Observe that +invert, can be a valid expression, while invert+, cannot.

@TrevorBurnham
Copy link
Collaborator Author

{+invert, -buffer}

and

{invert+, buffer-}

are both invalid expressions.

Is your point that the meaning of +invert should be kept consistent even in invalid contexts? Normally I'd agree, but I don't see the use of invert+ as a self-contained expression as any more consistent; after all, invert+ is a valid line, as I pointed out above (making debracability impossible), and +invert is of course meaningless as an expression when nothing is done with the resulting value.

Let's go with whichever syntax is most readable. I think that's the prefix syntax, especially when broken into multiple lines:

options = {
  +invert
  +copy
  +zoom
  -buffer
  -thumbnail
}

@satyr
Copy link
Collaborator

satyr commented Dec 4, 2010

especially when broken into multiple lines

Uh, I see your point now. prefixes line well.

@satyr
Copy link
Collaborator

satyr commented Dec 4, 2010

satyr/coco@3bc8c6f

@jashkenas
Copy link
Owner

Sorry, Trevor, this is a couple degrees too far golfed for my taste. I'd rather see:

invert: yes, zoom: no

Closing the ticket.

@michaelficarra
Copy link
Collaborator

Related: satyr/coco@457f3e9

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