News for hackers. Stuff that matters.
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.