3 ms·
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 c
by TooCreative 6y ago
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.
- castwide 6y ago> 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.
- TooCreative 6y agoFor the example I took a random line from Symfony and shortened it a bit: https://github.com/symfony/http-client/blob/master/HttpClientTrait.php#L33 https://github.com/symfony/http-client/blob/master/HttpClien... You are free to link to some other example.
- castwide 6y agoAny 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.
- mplanchard 6y agoMost type systems also provide information about what’s in the array, like Array<String> or int[]
- TooCreative 6y agoThat 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.
- mplanchard 6y agoIs 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.
- unrealhoang 6y agoHeck, 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".