On 3 February 2023 22:48:14 GMT, "Thomas Krüger" <thomas.pakka...@posteo.de> 
wrote:
>Hi,
>
>why not using the existing Typescript programming language and transpile it to 
>PHP? :)
>
>There are community examples for doing that:
>"ts2php"
>https://www.npmjs.com/package/ts2php


I can think of a few reasons.

Firstly, TypeScript is a language designed with a very specific purpose: to 
build a statically typed language on top of the existing functionality of 
JavaScript. Although some of the decisions that follow from that would also aid 
compatibility with PHP, some would lead to serious mismatches - for example, 
JavaScript has an entirely different object model, with prototypes rather than 
classes [1], and methods more closely resembling closures bound to the object.

Secondly, designing the language is only half the battle, probably less. It 
requires expertise to do well, but the bulk of the time is spent *implementing* 
that design. It can be deceptively easy to implement a proof of concept that 
can run some carefully chosen sample code, but actually making something 
production ready is a much bigger effort. It doesn't surprise me at all that 
the project you linked had some initial beta releases, and then went quiet for 
several years.

Thirdly, if this approach made sense, TypeScript wouldn't need to exist - 
Microsoft could have written tooling to translate C# to JavaScript instead. The 
reason languages like TypeScript are created is specifically to bridge existing 
code and existing knowledge from an existing language. That might mean running 
in the same run-time as the older language, or just being similar enough to 
allow a supervised one-off conversion. For PHP, that's the thinking behind Hack 
(from HHVM), Zephir (from the Phalcon framework), and more recently Ara 
(https://ara-lang.io/).

To succeed, a new language needs a rare combination of committed resources 
(which generally means commercial backing to pay multiple full time 
developers), plus a critical mass of users. Zephir lacked both; Hack had 
backing inside Facebook, but didn't gain traction outside it; I wish Saif luck 
with Ara, but I'm not holding my breath.


[1] Yes, there's now a "class" keyword, but it's just syntactic sugar; the 
fundamental inheritance model still consists of prototype chains.

-- 
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to