Python slang

Marco Sulla mail.python.org at marco.sulla.e4ward.com
Fri Aug 5 19:21:51 EDT 2016


On 6 August 2016 at 00:31, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Aug 6, 2016 at 8:00 AM, Marco Sulla via Python-list
> <python-list at python.org> wrote:
> This isn't slang; it's jargon

Right.


>> * `raise` instead of `throw`
>
> Quite a few other languages talk about raising exceptions rather than
> throwing them. Those would be the two most common terms, I think.
>
>> * `self` instead of `this` (I know, it's not enforced, but it's a de
>> facto standard and some IDEs like PyDev gives you an error if you
>> declare a non-static method without `self` as first parameter)
>
> Smalltalk and friends also use "self", so again, this would be the
> other common word for the parameter.
>
>> * `str.strip()` instead of `str.trim()`
>
> Another case where both words are in common use.

I want to clarify that when I say "different from the other
languages", I mean "different from the most used languages", that in
my mind are C/C++, C#, Java, PHP and Javascript, mainly.


>> * `dict` instead of `map`
>
> "map" has many other meanings (most notably the action wherein you
> call a function on every member of a collection to produce another
> collection).

Well, the word `map` of the `map` function is a verb. IMO there would
be no ambiguity.


>> * `list.append()` instead of `list.push()`
>
> Better description of what it does, IMO. It's adding something to the
> end of the list - appending to the list.

I agree.


>> * and furthermore much abbreviation, like `str` instead of `string`
>> and `len()` instead of `length()`, that seems to contrast with the
>> readability goal of Python.
>
> Brevity can improve clarity, if it is obtained without the expense of
> accuracy.

I agree it's not hard to understand that `str` is the string type and
`len()` is the function that gives you the length, even if you don't
know Python (and it's shorter to type...) But it's hard to remember,
in particular if you code also in other languages. When I come back to
Python, I always ends to write  `somelist.length` instead of
`len(somelist)`, some arcane words come out my mouth and a little
fairy dies.


> Hope that helps a bit!

yep.



More information about the Python-list mailing list