3 ms·
Python ruined Perl for me. As soon as I convinced my self that pass-by-object-reference really was that simple, and I didn't have to deal with pass-by-sigil-may
by kstrauser 4y ago
Python ruined Perl for me. As soon as I convinced my self that pass-by-object-reference really was that simple, and I didn't have to deal with pass-by-sigil-maybe, I never looked back.
Write a Python function that writes an object's string representation to a file:
def write(obj): open('/tmp/foo', 'w').write(str(obj))
Call it on an integer:
write(123)
and it works. OK. But what if I want to call it on a list of strings?
write(["spam", "eggs"])
That was too easy. I know - let's see if we can write a dict of tuples to sets of ints!
write({(1,2):{3,4,5},('spam','eggs'):{6,7,8}})
That freaking worked? And I didn't have to change the function to accept a hashref? You just pass an object... and it passes the object?
At first, I thought I had to be missing something, like maybe it was impossible to do trickier things because they made the simple things so easy, but no. It just turned out that some of Perl's design decisions increased my cognitive load way more than strictly necessary. That's clearly not true for everyone, but it sure was for me. The first day I wrote Python was the last day I wrote Perl.
- lanx 4y ago> At first, I thought I had to be missing something, Well, Data::Dumper is included in core Perl ... use v5.12.0; use warnings; use autodie; use Data::Dumper; sub logit { open state $log, ">>", 'c:/tmp/foo'; print $log Dumper(@_) } logit(123); logit(["spam", "eggs"]); logit({"(1,2)"=> [3,4,5],"('spam','eggs')"=> [6,7,8]}); # even logging multiple objects at once ... logit( 123, ["spam", "eggs"], {"(1,2)"=> [3,4,5],"('spam','eggs')"=> [6,7,8]}, ); NB: Perl has neither tuples nor sets, but there are workarounds. And I opened the filehandle only once. And for append not overwrite like you did.