gosukiwi / Blueberry

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

Why "echo()" ? #42

Open lazytyper opened 8 years ago

lazytyper commented 8 years ago

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?

gosukiwi commented 8 years ago

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.

lazytyper commented 8 years ago

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

gosukiwi commented 8 years ago

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 😄

lazytyper commented 8 years ago

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

gosukiwi commented 8 years ago

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 😉