Blueberry icon indicating copy to clipboard operation
Blueberry copied to clipboard

Why "echo()" ?

Open lazytyper opened this issue 8 years ago • 5 comments

I'm using CoffeeScript as replacement for JavaScript.

I've been searching for a language like "CoffeeScript" for "PHP" and found this here. and I've just been reading the README and I see the

echo(...)

Why echo(...). PHP does not need the ()'s. ???

Just make the syntax more like CoffeeScript or is there a better language?

lazytyper avatar Sep 29 '16 18:09 lazytyper

Just because it's a function call, and all function calls must have parens.

In PHP echo is a keyword, which basically means it's embedded into the language as a special rule. It's also a function. When Blueberry compiles to PHP it just treats it as a function. This is mostly because I wanted to keep things simple.

If for some reason, we decide to change echo to work without parens, the good solution would be to enable any function call to be called without parens.

Personally I don't mind the mandatory parens, the only case I find them annoying is when calling a function with no arguments 😛

Treating functions a special way, like PHP does with echo is a complexity I'd rather avoid in Blueberry.

gosukiwi avatar Sep 29 '16 18:09 gosukiwi

The echo is a keyword in PHP, but your compiler does not need to treat it like a keyword. echo is a like a function, which does not need ()s. Same like this here:

# coffee
console.log 'Hello world!'

And I've got a question: Does your compiler support cson style, like in CoffeeScript, too? -> https://github.com/bevry/cson/tree/master/test/src

lazytyper avatar Sep 29 '16 21:09 lazytyper

Yeah, it is different from PHP, it's not a 1-to-1 translation, like CoffeeScript is to Javascript.

As for cson, nah it's quite a dummy JSON parser. You can see the grammar here: https://github.com/gosukiwi/Blueberry/blob/master/src/grammar.g#L553 😄

gosukiwi avatar Sep 29 '16 21:09 gosukiwi

CoffeeScript does not require return either: http://coffeescript.org/

lazytyper avatar Sep 30 '16 01:09 lazytyper

Blueberry is inspired by CoffeeScript, not an alternative implementation. I get your point though, implicit return is a nice feature to have, I wouldn't mind if someone made a PR implementing it 😉

gosukiwi avatar Sep 30 '16 02:09 gosukiwi