News for hackers. Stuff that matters.
Re:PHP compile time generics: yay or nay? by mrkeen on Monday August 11, 2025 @02:25AM (#44861244)
> Erased generics the type information is not available at run time. That's the way Java does it and it kinda sucks.

In a good statically-typed language you don't need runtime type information. It could be a Void in the bytecode for all I care, as long as it behaves correctly.

> obj.GetType() == typeof(typename)

In a statically-typed language, this can be optimised away to a bool at compile time.

Re:PHP compile time generics: yay or nay? by Gibbon1 on Monday August 11, 2025 @05:21AM (#44862271)
Oh absolutely not true AT ALL.
Re:PHP compile time generics: yay or nay? by positr0n on Monday August 11, 2025 @11:13AM (#44865066)
Occasionally it is really useful to be able to do something like `new T()`. Without reified generics that is not possible.
Re:PHP compile time generics: yay or nay? by mrkeen on Monday August 11, 2025 @11:40AM (#44865439)
new T? What's wrong with the old one?

Jokes aside, what's the use case for not knowing what T is until runtime?

Re:PHP compile time generics: yay or nay? by chuckadams on Tuesday August 12, 2025 @12:15PM (#44878340)
Pretty much all polymorphism works by not knowing the concrete type til runtime. If you have an Animal reference to a Dog instance, any method you call on it is resolved at runtime, because the reference knows the type. Reified generics do the same for type parameters, whereas erased types are only used for type checking at compile time.
Re:PHP compile time generics: yay or nay? by mrkeen on Sunday August 17, 2025 @01:48AM (#44929194)
Nah I think I'd just prefer to figure out the types in type-checking phase, then erase and get on with things.

I don't buy that most polymorphism is dynamic.

No example of 'new T()' (which wouldn't be improved by static typing was given) so I got nothing else to say.