Hacker News new | past | comments | ask | show | jobs | submit login

> I wonder why there isn't a popular gradually typed language that natively allows writing both dynamic and type-safe code, allowing quick prototyping and then gradual refactor to type safety.

Popularity aside, Perl 6 supports exactly this.

So does php 7

Well, kind of.

I have an old website built on PHP, using a PHP 7 runtime, and I recently had to make a few small changes and discovered PHP had added typing in recent years.

My interest was piqued, and I dug into the docs a bit.

And was promptly disappointed - yes, PHP allows gradual typing, but the type system it has is woeful! Aside from the pitiful selection of types, basically only function arguments can have type hints (e.g. no typing of local vars).

Another huge problem is the lack of typing for arrays.

Considering the prevalence of array types in PHP, this considerably reduces the available safety.

Basically your only option is to use only classes for keyed arrays, and array wrapper classes like `MyClassArray` with typesafe methods like `push` and `get`.

Typescript solves this beautifully generics and interface types.

> the type system it has is woeful

Check out a thing I made: https://psalm.dev. It allows you to add more descriptive types in docblocks.

> no typing of local vars

Why do you want explicit types for local vars?

> Why do you want explicit types for local vars?

I suppose mainly because of deficits in the static analysis tooling that exists (or at least, that I used), as they usually cannot infer types correctly. Psalm looks pretty nice though, so I'll check that out next time I'm working in this PHP codebase :)

Even with exellent tooling though, there are still occasions where I like to use an explicit type.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact