DWIM is consistent
Moshe Zadka has been writing a mostly excellent exploration of the Zen of Python for Opensource.com. Not sure I approve of this take on guessing, from The importance of consistency in your Python code:
What should the result of
1 + "1"be? Both"11"and2would be valid guesses. This expression is ambiguous: there is no single thing it can do that would not be a surprise to at least some people. Some languages choose to guess. In JavaScript, the result is"11". In Perl, the result is 2. InC, naturally, the result is the empty string. In the face of ambiguity, JavaScript, Perl, and C all guess.
I can’t speak for the other languages, but Perl isn’t guessing. It’s adding these two values as numbers because we told it to by using the numeric + operator. If we wanted a string, we would tell Perl, by using the . concatenation operator.
Let’s fire up tinyrepl for a quick demonstration.
Code Sample
$ tinyrepl
re.pl$ 1 + "1"
2
re.pl$ 1 . "1"
11
Perl operators do the type casting for you. This is DWIM in action. You say you want numbers? Perl gives you numbers. You say you want strings? Perl gives you strings.
Are 1 + "1" and 1 . "1" better than 1 + int("1") and str(1) + "1"? I don’t know. Perl was born for text processing. Most of its affordances make the most sense in that context.
DWIM can be surprising to those unfamiliar with this approach. But it’s not guessing.
The points about consistency and ambiguity are solid. The Zen of Python can be applied with slight modifications to all programming. Just remember that “obvious” is different in different languages.
Activity Log
hackers.town: 2019-12-27 Fri 01:19
ok cool so i figured out how to do the thing with sql
now how to with the orm
um
connection.cursor().execute(sql, bindings)
ok cool
hackers.town: 2019-12-27 Fri 02:23
There’s the easy way to make a #drawing and then there’s whatever I’ve been doing the last couple of months.

hackers.town: 2019-12-27 Fri 08:49
Network Solutions sending me email reminders to renew my domain.
Very helpful.
Expires in November 2024.
Very helpful.
hackers.town: 2019-12-27 Fri 09:49
Responding to ticket tracker messages from a week and a half ago because I thought the timestamp was from yesterday.
Twitter: 2019-12-27 Fri 13:09
Great point. I know for a fact that most of the overwork I’ve done has been meh. The only exception has been when it was some kind of tedious repetitive task. In every other case my task would have been better served by a nap, or by a full night’s rest and distraction.
I keep scrolling back to this tweet.
Sometimes someone else’s words make it impossible to ignore something you already know (and may have even said yourself on occasion).
hackers.town: 2019-12-27 Fri 14:54
Installing the latest OpenJDK version so I could run a thing was clearly a mistake.
Wondered why there were three distinct versions in the apt repo.
hackers.town: 2019-12-27 Fri 15:02
Am now at least three setup tasks removed from running the thing so I could check something real quick.
Twitter: 2019-12-27 Fri 15:03
Dick’s
https://twitter.com/chadloder/status/1210127891347853312
Twitter: 2019-12-27 Fri 18:42
I’m going with “carpeted toilet”
Sounds classy.
https://twitter.com/CateSpice/status/1210713915182604289
Twitter: 2019-12-27 Fri 19:35
I’ll do my best.
https://twitter.com/stonefly_ky/status/1210602461758656512
Twitter: 2019-12-27 Fri 20:54
The more blogs the merrier.
And especially noteworthy: introduce your readers to RSS. My “follow” page assumes potential blog readers know RSS, but TBH that’s not a safe assumption in 2020.
So blurbed goal:
- have the RSS links
- explain what RSS is
- link to reading tools.
https://twitter.com/bmann/status/1210452960737710080