3 ms·
What I read is "if all you have is a hammer, everything looks like a nail." > In PHP I make lots of tiny uses of it in many places. I really missed it when I s
by yedpodtrzitko 12y ago
What I read is "if all you have is a hammer, everything looks like a nail."
> In PHP I make lots of tiny uses of it in many places. I really missed it when I switched to Python (sure, there's OrderedDict, but it's a second-class citizen: there's no syntax for literals and standard APIs don't explicitly take advantage of it).
Missing syntax sugar makes it a second-class citizien? How? Also what advantages could standard API (<- what does that even mean?) take?
> It's neat for sorting objects without having to mutate them to add a key or wrap them in a key/value object.
It's called set()
> It's great for configuration with JSON-like structures, but key order gives extra flexibility in the design, e.g. instead of [{id:"foo"},{id:"bar"}] you can use ["foo"=>[],"bar"=>[]].
...and the reason you cant use OrderedDict here is you dont like it.
About ordering stuff: after years I can still remember the problems I had with ordering in PHP. There's more than a dozen of sorting methods, which is mess. No one can remember if they all behave the same way and what's the order of its parameters. In Python you've sorted() and that's it.
You cant do any advanced stuff with these array, because sometime they act as lists and sometime they act as hashmaps. I'll take this example from "Fractal...":
$first = array("foo" => 123, "bar" => 456);
$second = array("foo" => 456, "bar" => 123);
array_diff($first, $second);