RE: Programming newbie coming from Ruby: a few Python questions

Discussion in 'Python' started by Delaney, Timothy (Tim), Aug 1, 2006.

  1. Edmond Dantes wrote:

    > Of course, it's all what you really mean by "clever". To me, being
    > "clever" partly means writing code without bugs in the first place,
    > so there is nothing that needs debugging!!!!!!!!


    "Clever" in this context generally means using a trick/hack that is
    non-obvious (often even after you understand it). "Cleverness" often
    leads to difficult-to-understand code, which is contrary to the "python
    philosophy".

    There are occasionally times when cleverness is useful, but in those
    cases it should always be commented explaining exactly what it is doing,
    and why a non-clever solution was not used. Most of the time there's
    still a better non-clever way to do it, but the coder is not clever
    enough to find it ;)

    Tim Delaney
    Delaney, Timothy (Tim), Aug 1, 2006
    #1
    1. Advertising

  2. Delaney, Timothy (Tim) wrote:
    > Edmond Dantes wrote:
    >
    > > Of course, it's all what you really mean by "clever". To me, being
    > > "clever" partly means writing code without bugs in the first place,
    > > so there is nothing that needs debugging!!!!!!!!

    >
    > "Clever" in this context generally means using a trick/hack that is
    > non-obvious (often even after you understand it). "Cleverness" often
    > leads to difficult-to-understand code, which is contrary to the "python
    > philosophy".
    >
    > There are occasionally times when cleverness is useful, but in those
    > cases it should always be commented explaining exactly what it is doing,
    > and why a non-clever solution was not used. Most of the time there's
    > still a better non-clever way to do it, but the coder is not clever
    > enough to find it ;)
    >
    > Tim Delaney


    Is this kind of cleverness what is usually known as "magic"?
    I suspect that this has something to do with it, but not completely
    sure...

    Luis
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=, Aug 2, 2006
    #2
    1. Advertising

  3. Delaney, Timothy (Tim)

    Ravi Teja Guest

    > Is this kind of cleverness what is usually known as "magic"?
    > I suspect that this has something to do with it, but not completely
    > sure...


    :). It must be. Now Django has a "magic removal branch".
    Ravi Teja, Aug 2, 2006
    #3
  4. Luis M. González wrote:
    > Delaney, Timothy (Tim) wrote:

    (snip)
    >> "Clever" in this context generally means using a trick/hack that is
    >> non-obvious (often even after you understand it). "Cleverness" often
    >> leads to difficult-to-understand code, which is contrary to the "python
    >> philosophy".
    >>
    >> There are occasionally times when cleverness is useful, but in those
    >> cases it should always be commented explaining exactly what it is doing,
    >> and why a non-clever solution was not used. Most of the time there's
    >> still a better non-clever way to do it, but the coder is not clever
    >> enough to find it ;)
    >>

    >
    > Is this kind of cleverness


    Which one ?-)

    > what is usually known as "magic"?
    > I suspect that this has something to do with it, but not completely
    > sure...


    Python's "magic" is mostly about using the more advanced features of the
    language (closures, special '__magic__' methods, descriptors,
    metaclasses) and take full advantage of Python's object model and
    dynamicity to reduce boilerplate and factor out repetition. All this
    surely requires a good understanding of Python's object model - and may
    look somewhat "magic" to newcomers -, but no particular "cleverness".

    The key here is not to use these features for the sake of using them,
    but only if and when it really simplifies the rest of the code by
    factoring out the existing complexity.

    The unpythonic "cleverness" is mostly about trying to stuff as much
    operations as possible in a single expression. Which doesn't change
    anything to the complexity of the code but makes the whole thing much
    more difficult to understand - so it actually *adds* a level of complexity.

    You can take a look at my sig for an example of unpythonic 'cleverness':

    print '@'.join(['.'.join([w[::-1] \
    for w in p.split('.')]) \
    for p in ''.split('@')])


    How much time do you need to understand what happens here ? Way too much
    anyway. Now look at the dumbiest way to write the same thing:

    parts = ''.split('@')
    reversed_parts = []

    for part in parts:
    words = part.split('.')
    reversed_words = []

    for word in words:
    # word[::-1] reverse the word,
    # ie "abc"[::-1] == "cba".
    reversed_words.append(word[::-1])

    reversed_parts.append('.'.join(reversed_words))

    reversed_sig = "@".join(reversed_parts)
    print reversed_sig

    It's perhaps a bit longer, perhaps less 'elegant' (for a somewhat
    perlish definition of 'elegance'), certainly less "clever", but at least
    it's something that doesn't requires any special attention to understand
    - except perhaps for the extended slice stuff, but it's explained by a
    comment.


    --
    bruno desthuilliers
    python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
    p in ''.split('@')])"
    Bruno Desthuilliers, Aug 2, 2006
    #4
  5. Delaney, Timothy (Tim)

    Guest

    thanks very much for all the comments, links to articles and other
    help.The Ruby crowd says you guys are no where near as friendly as
    them! I was half expecting a nervous breakdown after writing my first
    post here.

    Cheers again
    , Aug 2, 2006
    #5
  6. wrote:

    >> The Ruby crowd says you guys are no where
    >> near as friendly as them!


    Slander! Defamation!
    BartlebyScrivener, Aug 2, 2006
    #6
  7. Delaney, Timothy (Tim)

    Tim Chase Guest

    > The Ruby crowd says you guys are no where near as friendly as
    > them! I was half expecting a nervous breakdown after writing
    > my first post here.


    Maybe the Ruby folks have to be friendlier to make up for their
    language of choice... :*)

    The python mailing list is your pretty typical technical mailing
    list: if you do your own homework, state your problem clearly
    (with full error messages, actual data, not writing in
    AOL/133t-speak, etc), and have already tried searching the
    web/docs, then you'll find folks here are quite helpful. Not
    just helpful, but *fast* in their helpfulness too.

    -tkc
    Tim Chase, Aug 2, 2006
    #7
  8. BartlebyScrivener wrote:
    > wrote:
    >
    > >> The Ruby crowd says you guys are no where
    > >> near as friendly as them!

    >
    > Slander! Defamation!


    The time to crush our enemies has come.
    This is the Jihad! Death to the infidels!!!!
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=, Aug 2, 2006
    #8
  9. Delaney, Timothy (Tim)

    Jarek Zgoda Guest

    Luis M. González napisa³(a):

    >>>>The Ruby crowd says you guys are no where
    >>>> near as friendly as them!

    >>
    >>Slander! Defamation!

    >
    > The time to crush our enemies has come.
    > This is the Jihad! Death to the infidels!!!!


    We'll kill them all, then we'll piss on flowers in their gardens. We'll
    eat their cats and burn their yearbooks of "IEEE Proceedings". The
    revenge is tasting sweet.

    At the end of day we will be these who count bodies. ;)

    --
    Jarek Zgoda
    http://jpa.berlios.de/
    Jarek Zgoda, Aug 2, 2006
    #9
  10. Delaney, Timothy (Tim)

    infidel Guest

    > The time to crush our enemies has come.
    > This is the Jihad! Death to the infidels!!!!


    Whoa, dude, let's not get carried away now, 'k?

    Looking-over-his-shoulder-ly y'rs,
    infidel
    infidel, Aug 2, 2006
    #10
  11. Stand and fight, Python brothers. Fear not, the Ruby horde!

    From this day to the ending of the world,
    But we in it shall be remember'd;
    We few, we happy few, we band of brothers;
    For he to-day that sheds his blood with me
    Shall be my brother; be he ne'er so vile,
    This day shall gentle his condition:
    And gentlemen in England now a-bed
    Shall think themselves accursed they were not here,
    And hold their manhoods cheap whiles any speaks
    That fought with us upon Saint Crispin's day.

    rd
    BartlebyScrivener, Aug 2, 2006
    #11
  12. a écrit :
    > thanks very much for all the comments, links to articles and other
    > help.The Ruby crowd says you guys are no where near as friendly as
    > them!


    Yes. Python bashing sadly appears to be the national sport amongst
    Rubyists. Looks like a puberty crisis to me, and I guess (or at least
    hope) this will calm down when Ruby will start to mature.

    FWIW, c.l.py is still one of the more helpful and friendly place on
    usenet. This doesn't mean there's no RTFMs, but at least they are
    usually gently followed by a link to the relevant section !-)

    > I was half expecting a nervous breakdown after writing my first
    > post here.


    Sorry if you're disappointed. But you can take a chance on c.l.lisp if
    you really want a newsgroup that's nowhere as friendly as this one !-)

    > Cheers again


    Welcome on board - hope you'll enjoy the trip.
    Bruno Desthuilliers, Aug 2, 2006
    #12
  13. BartlebyScrivener a écrit :
    > wrote:
    >
    >
    >>>The Ruby crowd says you guys are no where
    >>> near as friendly as them!

    >
    >
    > Slander! Defamation!
    >

    I'd rather say cluelessness and jealousy !-)
    Bruno Desthuilliers, Aug 2, 2006
    #13
  14. On Wed, 02 Aug 2006 22:25:35 +0200, Jarek Zgoda <>
    declaimed the following in comp.lang.python:

    >
    > At the end of day we will be these who count bodies. ;)


    o/~ Listen children, to a story
    that was written long ago
    'bout a kingdom, on a mountain
    and the valley far below ... o/~
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Aug 3, 2006
    #14
  15. Delaney, Timothy (Tim)

    John Machin Guest

    BartlebyScrivener wrote:
    > Stand and fight, Python brothers. Fear not, the Ruby horde!
    >
    > From this day to the ending of the world,
    > But we in it shall be remember'd;
    > We few, we happy few, we band of brothers;
    > For he to-day that sheds his blood with me
    > Shall be my brother; be he ne'er so vile,
    > This day shall gentle his condition:
    > And gentlemen in England now a-bed
    > Shall think themselves accursed they were not here,
    > And hold their manhoods cheap whiles any speaks
    > That fought with us upon Saint Crispin's day.
    >


    :)
    Oh I say, old chap, steady on -- it's been a long while since
    Agincourt; aren't they supposed to be on your side now?
    (-:
    John Machin, Aug 3, 2006
    #15
  16. "Dennis Lee Bieber" <> wrote:


    | On Wed, 02 Aug 2006 22:25:35 +0200, Jarek Zgoda <>
    | declaimed the following in comp.lang.python:
    |
    | >
    | > At the end of day we will be these who count bodies. ;)
    |
    | o/~ Listen children, to a story
    | that was written long ago
    | 'bout a kingdom, on a mountain
    | and the valley far below ... o/~
    | --

    Oh the mountain sheep were sweeter,
    but the valley sheep were fatter,
    we therefore deemed it meeter,
    to carry off the latter..
    H J van Rooyen, Aug 3, 2006
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Holden

    PyCon is Coming! PyCon is Coming!

    Steve Holden, Jan 5, 2006, in forum: Python
    Replies:
    0
    Views:
    299
    Steve Holden
    Jan 5, 2006
  2. Replies:
    13
    Views:
    428
    Thomas Nelson
    Aug 3, 2006
  3. Replies:
    10
    Views:
    538
  4. Murali
    Replies:
    2
    Views:
    543
    Jerry Coffin
    Mar 9, 2006
  5. Markus Jais
    Replies:
    0
    Views:
    130
    Markus Jais
    Jul 22, 2003
Loading...

Share This Page