[Python-ideas] Descouraging the implicit string concatenation

Søren Pilgård fiskomaten at gmail.com
Wed Mar 14 09:48:52 EDT 2018


On Wed, Mar 14, 2018 at 2:26 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Wed, Mar 14, 2018 at 01:43:53PM +0100, Søren Pilgård wrote:
>
> [...]
>> I have also experienced beginners asking why you can do `x = "abc"
>> "def"` but not `a = "abc"; b = "def"; x = a b` and then you have to
>> either explain them the differences between strings and string
>> literals or just tell them to always use `+`.
>
> If you tell them to "always use `+`", you are teaching them to be
> cargo-cult coders who write code they don't understand for reasons they
> don't know.
>
> Life is too short to learn *everything*, I know that, and I've certainly
> copied lots of code I don't understand (and hoped I'd never need to
> debug it!). If that makes me a cargo-cult coder too, so be it.
>
> But never over something as simple as the difference between names a and
> b, and string literals "abc", "def".
>
>

Yes of course the skilled programmer needs to understand the
difference. But I am talking about absolute beginners where python in
many regards is an excelent first language.
And in time they will probably get an understanding of why there is a
difference, but when you still have trouble telling the difference
between 5 and "5" then telling them the difference between strings and
string litterals will only confuse them more.
Trying to teach a person everything at once does not work well,
limiting the curriculum and defering some parts for later study is
hardly cargo-cult coding. At least not more than all the other things
that just work the way they do because thats how it works - from the
beginners point of view.


More information about the Python-ideas mailing list