3 ms·
That is one thing I like better in Python than in Perl. In Perl, I was having difficulty with nested data structures and then realized this was something I did
by FractalLP 8y ago
That is one thing I like better in Python than in Perl. In Perl, I was having difficulty with nested data structures and then realized this was something I did in Python daily without even knowing it was a thing on a conscious level. Who hasn't made some weird dictionary with its values being lists or tuples or something like that?
- ajross 8y agoThis is exactly backwards to my eyes. Perl's autovivification behavior (assigning through a empty reference to something autocreates the object of the right type) makes nested data much, much cleaner. Who hasn't made some weird dictionary with its values being lists and forgotten to check for and write code to create it when it doesn't exist, and had to fix that later after a runtime crash? In perl that's literally covered by the one-line assignment you used to set the field you parsed. This is why it's sad that everyone's forgotten perl.
- FractalLP 8y agoSorry, but I didn't catch your example. Can you explain a little more? What does Perl do better there?
- kqr 8y agoDefaultdicts to the rescue! But I think it should be an explicit choice. If you only intend to have lists at some keys, and then accidentally mistype a key, it shouldn't (in my opinion) silently create a list, effectively hiding the bug.