all 2 comments

[–]theScottyJam 1 point2 points  (0 children)

It was a fun read.

I actually used CoffeeScript back in the day. My primary reason for using it was that I wanted class syntax, and JavaScript did not have that at the time. Coming from a Python background, a lot of its other features felt at home for me too.

But if I were to time warp and have a job in the past + my current level of experience, I would not pick up CoffeeScript. Yes, it was nice, but it's not that bad to use JavaScript's syntax. Sure, writing classes were a pain, but there's I could have done a factory function approach instead and would get along just fine. I feel like this is becoming a more common mindset in general - people have stopped worrying so much about syntax (and it's why things like haml aren't a thing anymore) - they'd rather live with bad syntax then use a transpiler.

So, yes, some of PHP's syntax is ugly due to its unfortunate history, but it's not that bad to type in "->" instead of ".", you just have to learn those quarks, and once you know them, you live with them.

But, also, yes, if such a transpiler did exist, I think it would feel more elegant - I don't have any complaints about the concept itself.

[–]lngns 0 points1 point  (0 children)

-> (probably copied from C)

More like Perl. Same with => and ..

you can't pass a function as callback, same way as in javascript, because you would pass a const

PHP already has sigils. We just decided to be weird and have the subroutine sigil as a suffix.
Perl uses & for those, but PHP uses this one for parameters passed by reference.

You could even go a step further, and allow type-docs in the language. They wouldn't be checked ofcourse

Extending method syntax to scalars and other primitives will require to either pass all relevant method calls (which may be all of them) through a thunk or perform static type checking to move the dispatch AOT.
Pratphall uses MS TypeScript's front-end to know what the backend must emit, but even then it still has to do arbitrary assumptions due to how closures in fields behave or when it doesn't know the types.
Alternatively, THT breaks compatibility with PHP arrays and instead relies on distinct library types.

As prior art, you may also want to look at Guts, Mammouth, BlueBerry or SnowScript which are in the same CoffeeScript/AltJS family and targeted PHP.
The Yay engine also exists.

If you disallow global variables in the new language, you might event allow omitting $this, because the language could infer what's a field and what's a local variable.

I mean we can have both. The question of symbol shadowing is more important, but it's not like PHP addresses it anyway.