On 5/1/2012 17:11, Steven D'Aprano wrote:
My way
------

with func(some_args)<<  ':dict':
      with when_odd as 'n':
          pass
      with when_prime as 'n':
          pass


If you actually try that, you will see that it cannot work. You get:

SyntaxError: can't assign to literal

If you had read the module's docstring you would know that the public version uses
       with when_odd << 'n':
           pass

Have you actually tried to use these code blocks of yours? I asked you
for a *working* example earlier, and you replied with examples that
failed with multiple NameErrors and no hint as to how to fix them. And
now you give an example that fails with SyntaxError.

The examples I gave you work perfectly. It's clear that you don't even have the vaguest idea of how my module works or, otherwise, you'd know what you're doing wrong. Again, the module's docstring is your friend.

You have a bug in one or more of those callbacks.

Of course you do -- all non-trivial software has bugs. The question is,
how are you going to find it? You can't unit-test the individual
callbacks, because they don't exist in a form that can be tested.

It's easy to come up with a solution, in fact those functions /do/ exist. You would know that if you had read the documentation or even my reply to a post of yours.

So in this case, even though Python is slightly more verbose, and forces
you to have the discipline of writing named functions ahead of time, this
is actually a *good* thing because it encourages you to test them.

If the callbacks are trivial functions, the Pythonic way is to use
lambdas:

func(some_args, {'when_odd': lambda n: n-1,
                  'when_prime': lambda n: n**2 - 1,
                  ...})

although I would discourage that unless they are *really* trivial. But
for callbacks of any complexity, they will need to be tested, otherwise
how do you know they do what you want them to do?

Your code blocks make unit testing of the callbacks impossible, and for
that reason the Pythonic way is better.

Talking with you is a real pain. You're always partial in your opinions and this urge of yours to criticize other's work makes you look dumb or hopefully just lazy. I can't stand people like you who don't even have the decency of taking the time to read the documentation of a project and just run their mouth without any concern for facts. What I can't stand is that if I won't reply to your posts other lazy people will believe the nonsense you say, but I'll have to live with that because I've wasted enough time with you.

Kiuhnm
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to