There should only ever be one way to express yourself
I've been thinking about programming languages and their design.
In her book about the divergence of the English and American languages, Lynne Murphy asks this question:
wouldn’t it be great if language were logical and maximally efficient? If sentences had only as many syllables as strictly needed? If each word had a single, unique meaning? If there were no homophones, so we’d not be able to mix up dear and deer or two and too?
That got me thinking about the creativity which can be expressed in code - and whether its a good thing.
Let's take an incredibly simple and common operation - incrementing an integer variable by one. How would you do that? You've probably see these variations:
$i = $i + 1;
or
$i = $i++;
or
$i = 1 + $i;
or
$i = int( float_adder( float($i), 1.00 ) );
or
i1, i2 = i1^i2, (i1&i2) << 1
I'm sure you can come up with a few more esoteric methods.
The Python programming language has a list of aphorisms for good programming practice. One of which is:
There should be one-- and preferably only one --obvious way to do it.
Is that right? As described in What is Pythonic?, the Python language itself has multiple ways to accomplish one thing.
But, is it a good idea?
Back to Lynne Murphy again:
No, absolutely not. No way. Quit even thinking that. What are you, some kind of philistine? If Shakespeare hadn’t played with the number of syllables in his sentences, he would not have been able to communicate in iambic pentameter.
Shakespeare wasn't writing Python though, was he?
spiffytech says:
Ivan says:
numpy
pipeline totensorflow
so that it would work faster on a GPU? Or is ittorch
? Should I wait for better GPU support injax
? Will the pile of dependencies come crashing anyway when I revisit the code a year later?furicle says:
More comments on Mastodon.