gosukiwi / Blueberry

A beautiful programming language with clean syntax which compiles to PHP
MIT License
63 stars 10 forks source link

`for k, v in array` syntax looks a little bit too much like `foreach ($array as list($k, $v))` #13

Closed hikari-no-yume closed 10 years ago

hikari-no-yume commented 10 years ago

I'm not sure it's a problem, but you might look at for k, v in array and expect it to mean foreach ($array as list($k, $v)) instead of foreach ($array as $k => $v). Not that I think it should, I think explicit unpacking like that would be better as for [a, b] in array (and we could have list($a, $b) = $c in normal assignments as [a, b] = c, maybe? :D). If we were to change the syntax, it could be for k: v in array, to match the {k:v} literal syntax.

But, on the other hand, the current style could stay.

(Sorry for spamming you with all these suggestions!)

gosukiwi commented 10 years ago

Don't worry about the suggestions, they are all welcome :)

About the syntax, I like the idea of making [a, b] = c compile to list($a, $b) = $c. As for the for syntax, I borrowed it from CoffeeScript and I really liked it. Changing it to k: v wouldn't be hard, to be honest, my decision was somewhat conservative to not make developers learn too many new things about the syntax, if you already know python or coffeescript that should be familiar, but I really like that your syntax feels like JSON, and thus in Blueberry you can create associative arrays like that it might make sense to change it! :+1:

hikari-no-yume commented 10 years ago

It turns out your k, v implementation didn't actually work! See: https://github.com/gosukiwi/Blueberry/pull/17

So there's no reason not to change it, I suppose.

gosukiwi commented 10 years ago

Uhm, maybe it was just a placeholder for an implementation? Or is it broken? Well I guess the fix should just embrace the new syntax.

hikari-no-yume commented 10 years ago

Yeah, it may well have been a placeholder.