Time for my two cents. When I first saw the {color:color, x:x} syntax
it did seem somewhat jarring. After I thought about it a bit more it
makes more sense. Its advantages over a "string": value syntax:

1. It gives a clear visual distinction between a dict and a struct.
2. dict values are accessed via keys that are often strings (d["k"] ->
v) whereas structs are always referred to like attributes (p.name)
3. Having what appears to be string keys doesn't reflect that the keys
are not, in fact, strings.
4. Some other languages use the same syntax (e.g. objects in JavaScript)
5. It's clear that users are restricted to Python's identifier syntax.

The disadvantage:
1. In {color:color, x:x, y:y} the 'keys' look like identifiers.

I haven't read back through the archives to catch this entire
discussion but I have a suggestion. How about having a character
before the braces to visually indicate that it is a struct? Maybe
something like s{color: color}. That would give a clear visual cue,
not introduce a significant syntax change, and be similar to 1L, u"",
and r"".

Alternatively, the struct member names could be surrounded with a
character that isn't a quote. Just off the top of my head:
- A period/dot like {.color:color}. Pros: matches to the idea of
attribute/member access, fewer characters to type. Cons: Periods
sometimes aren't very visible at the beginning of a word, still looks
somewhat like a variable.
- {|color|: color}. Pros: distinct syntax, Cons: The { and | visually
blend together. The | looks too much like an I in some fonts. Doesn't
match up to any preexisting syntax concepts.
- {/color/: color}. Pros/Cons: Same as pipes, looks like regexp syntax
in Perl and other languages.
- {`color`: color}: Pros: Vaguely looks like a string literal, but
still is distinct. Very visible in email. Cons: Introduces new syntax.



-Aaron
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to