The only thing that really annoys me is the
, separated nature of the current call, which makes my brain hurt sometimes
because a "function call"-like syntax (yeah, I know is not a function call, but it looks like one) is not really indicative of association between the parameters to be honest.
I do understand that we could easily do this:
Code: Select all
api.headers := Map("Content-Type", "application/x-www-form-urlencoded",
"WWW-Authenticate","Basic")
Which looks ugly as hell and takes up too much space if you start separating key-value pairs to their own lines.
But the main issue is that I have been using ad-hoc objects in v1 for so long that I always try:
Code: Select all
api.headers := {"Content-Type": "application/x-www-form-urlencoded", "WWW-Authenticate":"Basic"}
before getting yelled at because I cant have
quotes around properties...
If I could modify what I just wrote a tiny bit instead of having to re-write the whole thing to change the braces, and change all
:'s to
,'s would be great.
So probably just needing to this:
Code: Select all
; any of these modifications would be appreciated as there is less to type/modify after
; I foolishly wrote all my ad-hoc object in the old notation.
api.headers := ["Content-Type": "application/x-www-form-urlencoded", "WWW-Authenticate":"Basic"]
api.headers := ${"Content-Type": "application/x-www-form-urlencoded", "WWW-Authenticate":"Basic"}
api.headers := map{"Content-Type": "application/x-www-form-urlencoded", "WWW-Authenticate":"Basic"}
without optionally having to create a custom class on each new script would be great.
Note: these examples seem trivial as there is not much data, but some times I write or copy/paste many key-value pairs (from JSON or javascript) before noticing and then having to use find/replace and deal with unwanted replacements when a simple
map,
$,
[:] would suffice.
Usually the issue is that I have a bunch of key-value pairs that
happen contain characters that cant be used in a property name.
That forces me to use a map even if I think of them as properties.
And probably you guys don't see those cases very often which is maybe one of the reasons why
@Lexicos probably decided not to implement a shorthand, but I believe that it would be a valuable addition to the language in general.
Everything that makes the programmer's intention clear is a good thing, and a "function call"-like statement does not convey the associative nature of a map.
I do understand that exception in the context of an array, as there is no association between items, except for their relative positioning to one another which can be clearly seen in
oArray := array("one", "two", "three"), but to drive my point home, I never use
object("prop", "value") notation for the same reason stated above,
{prop: value} better conveys what I am trying to do and for that reason I simply do not use
object() syntax when Im doing simple objects.