From: Alf P. Steinbach /Usenet on
* rantingrick, on 11.07.2010 08:50:
> On Jul 11, 1:22 am, Stephen Hansen<me+list/pyt...(a)ixokai.io> wrote:
>
>> Utter nonsense. No one does that unless they are coming from C or some
>> other language without a True/False and don't know about it, or if they
>> are using a codebase which is supporting a very old version of Python
>> before True or False were introduced.
>
> Ah yes, when nothing else seems to work fall back to you default
> programming... FUD and ad hominem
> attacks

I agree with Stephen, but for a different reason: that given desirability of
implicit conversion to bool for some elementary types, then for uniformity there
should be such conversion for all of them (and AFAIK there is), and given that,
the rule should be the same, namely that default value of each type bool's to
False, and other values to True, and so it is.

The OP should simply represent "not found" as e.g. integer -1 instead of as a
value of a different type.

And write e.g.

not_found = -1

...

if choiceIdx1 == choiceIdx2 == not_found:
bah, none of them
elif choice2Idx == not_found:
use choice 1
elif choice1Idx == not_found:
use choice 2
else:
determine bestest choice


Cheers & hth.,

- Alf


--
blog at <url: http://alfps.wordpress.com>
From: Alf P. Steinbach /Usenet on
* Stephen Hansen, on 11.07.2010 09:19:
> On 7/10/10 11:50 PM, rantingrick wrote:
>>
>> It was a typo not an on purpose misspelling
>
> If this had been the first time, perhaps. If you had not in *numerous*
> previous times spelled my name correctly, perhaps. If it were at all
> possible for "f" to be a typo of "ph", perhaps.

It is a natural mistake to make in some languages. E.g. in Norwegian the Devil
can be spelled Faen or Fanden (modern) or Phanden (old-fashioned, no longer in
dictionaries but still used to sort of tone down the expression). It's even
there in English, like "file" and "philosophy". So it's an error committed not
by the limbic system but by a slightly higher level sound-to-text translator
brain circuit. The text is generated from how the word sounds in one's head.


Cheers & hth.,

- Alf

--
blog at <url: http://alfps.wordpress.com>
From: Paul Rubin on
rantingrick <rantingrick(a)gmail.com> writes:
> unspeakably ugly code.

I'd write the code differently to not do all those branches.
I like to use 1-elemnt lists as an option type, instead of using None,
so you can just concatenate them together to get the first non-empty
one. Untested code:

array = [c1,c2,c3,c4,c5,c6,...]

# return first element of iterable that matches condition, wrapped
# as a 1-element list. If no match, return empty list.
def xfind(condition, iterable):
for x in iterable:
if condition(x): return [x]
return []

while looping:
cs = xfind(this_condition, array) + xfind(other_condition, array)
# cs is now a list of either zero, one, or two matching elements
if len(cs) == 1:
r = cs[0]
elif len(cs) = 2:
r = <whichever is best>
else:
break
best = array.pop(r)
do_somthing_with(best)

Obviously you can golf the above in various ways.
From: Stephen Hansen on
On 7/11/10 12:30 AM, Alf P. Steinbach /Usenet wrote:
> * Stephen Hansen, on 11.07.2010 09:19:
>> On 7/10/10 11:50 PM, rantingrick wrote:
>>>
>>> It was a typo not an on purpose misspelling
>>
>> If this had been the first time, perhaps. If you had not in *numerous*
>> previous times spelled my name correctly, perhaps. If it were at all
>> possible for "f" to be a typo of "ph", perhaps.
>
> It is a natural mistake to make in some languages. E.g. in Norwegian the
> Devil can be spelled Faen or Fanden (modern) or Phanden (old-fashioned,
> no longer in dictionaries but still used to sort of tone down the
> expression). It's even there in English, like "file" and "philosophy".
> So it's an error committed not by the limbic system but by a slightly
> higher level sound-to-text translator brain circuit. The text is
> generated from how the word sounds in one's head.

I'm aware of the "f" vs "v" vs "ph" thing, and the complexity of it
between languages and between the spoken verses written nature of
language. And for most instances, I'd just idly note, hey-- "My name is
Stephen" and leave it at that -- but this is not the first time with
I've run into it with this person, and neither is it the first time I've
responded to him and politely corrected him.

That, and I have seen absolutely no reason to think this person speaks
anything but standard American English. He has, for example, gone so far
as to create a rant which declared quite vocally that everyone should
adopt English, destroy Unicode and the usage of any other language, and
that anyone who didn't follow through with this was ultimately hurting
humanity. That any programmer which cow-towed towards this evil empire
of Unicodeness was just embracing separatism and decisiveness.

When this guy on more then one occasion chooses to articulate my name
improperly, I take it as an underhanded act with no purpose but to
belittle my point of view.

So yes. The first time, its a natural mistake, and I hold no hard
feelings. I regularly deal with people who misspell my name and
mispronounce my name. A polite correction invariably solves the problem,
and we are all happy.

But if one then makes the mistake again-- and in an entirely different
way (Stefan vs Steven) then they were politely corrected before-- its no
longer an issue of linguistic confusion at that point. At that point, I
have to assume he's doing it on purpose, and for the sole purpose of
being disrespectful and disparaging.

--

Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/

From: rantingrick on
On Jul 11, 2:19 am, Stephen Hansen <me+list/pyt...(a)ixokai.io> wrote:

> Nonsense.
>
> Prove it. Show actual benchmarks and actual problems to that style.

I can't believe i actually have to prove to you that creating a tuple
and then testing for bool-inity takes more time than just the bool
test, but here goes *another* Sunday school lesson...

>>> s1 = "if (a, b) != (None, None):\n pass"
>>> t1 = timeit.Timer(s1, 'a=1;b=1')
>>> min(t1.repeat())
0.23950232000015603
>>> s2 = "if a is not None and b is not None:\n pass"
>>> t2 = timeit.Timer(s2, 'a=1;b=1')
>>> min(t2.repeat())
0.14334155999995346

> Tests that do, in essence, "if whatever in (constant1, constant2)" are
> exceedingly common. The burden is on you to prove they are bad. With
> real data.

yea, been there done that.

> And yes, I do consider mangling my name to be an insult.

obviously i sounded out your name in my head. It is getting pretty
late here after all so give me break for crying out loud.

> 1 is something.

Yes, but not necessarily a "True" something!

> 0 is nothing.

Yes, but not necessarily a "False" nothing!

What is a True "something" and what is a False "nothing" Stephen? Put
that one up where it belongs with the chicken and the egg where it
belongs -- next to the toilet with Hustler and Time.

> My statement is neither FUD, nor even an ad hominem attack. If you
> dispute my dismissal, show evidence. Any will do.
>
> Oh, I do admit that in the end, I did venture into the ad hominem area
> where I called into question your attitude and general behavior

haha, i love how you denied the fact that you used ad hominem attacks
and then directly after that tried to makes excuses for the very
behavior you denied. Clinton made a career out this very same story
telling. Nice work Bill Jr. *wink*

> Do you see the pattern? Every fundamental data type has a "nothing"
> state: and they ALL evaluate as false in conditionals.
>
> Why should integers be any different? Because, uh, you say so.

No because i provide a very good reason --specifically in the case of
a conditional bool-ing-- that integers bool-ing to True/False can be
disastrous. And not only did i provide one reason, i provided two. The
second being that 1/0 as compared to True/False is misleading in it's
intention. Which renders code less readable, and supports bad
programming styles.