News for hackers. Stuff that matters.
Re:Things I Was Wrong About: Types by TooCreative on Sunday September 27, 2020 @08:16AM (#24606072)
Wishful thinking.

You know it returns an array, but you don't know what the array contains. So you don't know how to use it.

You still need to look into the code to see what it returns. Then you will see that it returns an array and what the array contains.

And now you had to process the information that it returns an array twice. Once in the function definition and once in the function body.

Re:Things I Was Wrong About: Types by castwide on Sunday September 27, 2020 @09:04AM (#24606333)
> You know it returns an array, but you don't know what the array contains. So you don't know how to use it.

That's a limitation of your specific example, not type systems in general.

Re:Things I Was Wrong About: Types by TooCreative on Sunday September 27, 2020 @11:01AM (#24607125)
For the example I took a random line from Symfony and shortened it a bit:

https://github.com/symfony/http-client/blob/master/HttpClien...

You are free to link to some other example.

Re:Things I Was Wrong About: Types by castwide on Sunday September 27, 2020 @12:25PM (#24607816)
Any example where the type is defined as something more specific than an array (especially in PHP, where the `array` type doesn't even differentiate between numerically indexed arrays and dictionaries).

Regardless, I still think the type hints in Symfony's version are better than nothing. It's also worth noting that `private static` is concerned with scope, not types.

Re:Things I Was Wrong About: Types by unrealhoang on Sunday September 27, 2020 @10:23AM (#24606841)
Heck, not only I don't have to look at the code, with proper IDE setup, I even don't have to go to the documentation page, just `item.` and my IDE/editor will present me with the list of things that are applicable to my item.

And that's only the response part of the usage, there's absolutely no way for me to know if the method is an enum/constant or is it a string without looking into the code for dynamic typing, and again, sometime N-level deep to get enough information of "what to pass to this function so it will work".

Re:Things I Was Wrong About: Types by mplanchard on Sunday September 27, 2020 @09:56AM (#24606626)
Most type systems also provide information about what’s in the array, like Array<String> or int[]
Re:Things I Was Wrong About: Types by TooCreative on Sunday September 27, 2020 @10:54AM (#24607068)
That is just another piece of metadata. But it does not help either. Now you know you get an array of strings. But you still don't know what is inside of the strings.

It might be ['headers'=>'...','body'=>'...' ] or ['status'=>'...','response'=>'...'] or god knows what.

And you are back to reading the function body.

Re:Things I Was Wrong About: Types by mplanchard on Sunday September 27, 2020 @11:11AM (#24607193)
Is that like a hashed array you’re implying? In that case, the type wouldn’t be string anyway, but something like HashMap, Object, Dict, etc. More commonly though, something like HTTP options would be its own type, with defined properties, which you could browse via autocomplete or your IDE’s hover/peek functionality. That type would then specify the types of its values, so you can be certain that options.status is an integer, for example.

You’d generally only use an otherwise untyped array of strings when you can’t know beforehand what their values can be.