Encapsulation in Python
BartC
bc at freeuk.com
Mon Mar 14 19:56:19 EDT 2016
On 14/03/2016 23:19, Mark Lawrence wrote:
> On 14/03/2016 22:40, BartC wrote:
>> Was that in Python? It was /supposed/ to be dreadful. I was making a
>> case for it to be supported directly.
>
> You mean the huge great long list of hard coded function calls. They
> are directly supported. So is the loop. Anything wrong with the Paul
> Rubin response?
I tried it. It wasn't bad, but still 1/3 the speed of an if-elif chain
with discrete range-checking.
> And as my earlier link showed you often simply don't
> need a switch statement in an OO language. Not much point providing
> something, much worse optimising it, if it isn't needed in the first place?
I disagree. And presumably so do others as there are so many different
attempts to implement switch, with varying degrees of success. Here's
how I do it outside Python:
switch c
when 'A'..'Z','a'..'z','_' then
++name
when '0'..'9' then
++numeric
when "()[]<>{}" then
++brackets
else
++other
end
Anything so terrible about that that Python needs to keep well clear of
or that you think its users should be deprived of?
>> Sorry, I'm not going to do that, and I don't expect anyone here to have
>> to do so either. You will have to take my posts as they are.
>>
>
> Drivel. Any establised member of this community, or any other community
> for that matter, will always publish, unless, like the RUE, they've got
> something to hide. So you're just a chicken. Where do you buy the
> paint from for the streaks down your back?
OK, we've got another Rod Speed! He also gets a kick out of being rude
and insulting to everyone.
> on the grounds that speed simply is not
> the sole criteria for a language.
I agree with you. But once you've got the language right, then there's
no harm looking at performance. A switch statement like the above can be
executed in a single byte-code.
--
Bartc
More information about the Python-list
mailing list