Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Programming newbie coming from Ruby: a few Python questions

Reply
Thread Tools

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

 
 
Delaney, Timothy (Tim)
Guest
Posts: n/a
 
      08-01-2006
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
 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Luis_M._Gonz=E1lez?=
Guest
Posts: n/a
 
      08-02-2006

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

 
Reply With Quote
 
 
 
 
Ravi Teja
Guest
Posts: n/a
 
      08-02-2006
> 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".

 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      08-02-2006
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 '(E-Mail Removed)'.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 = '(E-Mail Removed)'.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 '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
simonharrison@fastmail.co.uk
Guest
Posts: n/a
 
      08-02-2006
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

 
Reply With Quote
 
BartlebyScrivener
Guest
Posts: n/a
 
      08-02-2006

(E-Mail Removed) wrote:

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


Slander! Defamation!

 
Reply With Quote
 
Tim Chase
Guest
Posts: n/a
 
      08-02-2006
> 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



 
Reply With Quote
 
=?iso-8859-1?q?Luis_M._Gonz=E1lez?=
Guest
Posts: n/a
 
      08-02-2006

BartlebyScrivener wrote:
> (E-Mail Removed) 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!!!!

 
Reply With Quote
 
Jarek Zgoda
Guest
Posts: n/a
 
      08-02-2006
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 **** 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/
 
Reply With Quote
 
infidel
Guest
Posts: n/a
 
      08-02-2006
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet connects for a few seconds then disconnects for a few sec Cody Wireless Networking 2 06-28-2009 08:24 PM
Programming newbie coming from Ruby: a few Python questions simonharrison@fastmail.co.uk Python 13 08-03-2006 04:16 PM
Few basic c++ questions regarding 64 bit programming D Windows 64bit 4 04-21-2006 05:02 PM
To delete few lines and add few lines at the end of a text file using c program Murali C++ 2 03-09-2006 04:45 PM
PyCon is Coming! PyCon is Coming! Steve Holden Python 0 01-05-2006 11:53 AM



Advertisments