Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python Module: nift

Reply
Thread Tools

Python Module: nift

 
 
Paul McGuire
Guest
Posts: n/a
 
      02-09-2009
On Feb 8, 3:28*pm, Chris Rebert <(E-Mail Removed)> wrote:
> This I disagree with as being unnecessarily clever; the dict literal
> is just fine as-is and the zip() makes it less clear. However, I would
> definitely rewrite the dict to use less lines, which, after removing
> the capital dupes (as I mentioned in my post, just use .lower()),
> looks like:
>
> LEET_LETTERS = {"e" : "3", "a" : "4", "i" : "1", "t" : "7", "s" : "5",
> * * "o" : "0", "b" : "8"}
>


Maybe so, I was trying to illustrate zip() and maybe this was getting
too far ahead for a new Python user.

I *do* find that when initializing a list of characters (and for some
reason a string wont do), then instead of this:

vowels = ["A", "E", "I", "O", "U"]


using the list constructor is much easier:

vowels = list("AEIOU")


Or more non-deterministically,

sometimes = lambda s : [s] if random.random() > 0.5 else []
vowels = list("AEIOU") + sometimes("Y")


-- Paul
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      02-09-2009
J wrote:
> What are your thoughts on this module I created?
>
> '''
> A Python Module created by a High School Student.
> Includes rev(), reet(), and leet().


Gutsy of you to post this.

> Setup:
> * Save to Python Directory\Lib\ as nift.py


Add-in modules and packages like this should better go in
pythonxy/Lib/site-packages, which is there just for this purpose.
One can then easily see what add-ons ore present or not, or delete them,
or avoid deletion with uninstallation, or move to another version of
Python.

tjr

 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      02-09-2009
On Sun, 08 Feb 2009 13:34:50 -0800, bearophileHUGS wrote:

> Gabriel Genellina:
>> bearophile:
>> > - Generally I suggest to learn to code in the small, using as little
>> > code as possible.

>>
>> I completely agree with all the above suggestions, except this last
>> one. Ok, I think I know what you mean, but a beginner might understand
>> this completely wrong. Readability is important, and trying to compress
>> too much code into one single line should not be the ultimate goal.

>
> What I meant is to use less code as possible, keeping readability and
> the original flexibility.


I think a better description is, use as little code as you need, and no
extra, but no less. As Einstein said about physics theories: "As simple
as possible, but no simpler."


> I can't stress enough the importance of writing less code. Every new
> programmer has to learn how much important it is. Less code means less
> bugs, less lines to edit and debug, etc.


[pedant]
There's less code, fewer bugs and lines. Less applies to continuous
quantities, like weight and "amount of code", and fewer applies to
countable quantities.

Don't worry, I frequently get it wrong too, and I'm a native English
speaker


> Less code is usually more
> elegant, and often more readable (even if you take 3 times to read each
> line it may be good anyway if you have 1/10 of the lines of code.
> Recently in the "Java to Python" thread someone has posted some Java
> class that is scary, you can probably write the same thing in 1/10-1/20
> of the lines of code).


Within reason, naturally. There's a reason why we write:

for button in buttons:
move(button, delta_x, delta_y)

instead of

for b in bs: mv(b, x, y)

even though the second is significantly shorter. Keyword arguments versus
positional arguments is another example where more verbose code is easier
to read and maintain than shorter code.


Also, I don't think there's much advantage in trying to push new
programmers to reduce the amount of code. Until you're really comfortable
with the language, you need training wheels and scaffolding in the form
of verbose code. Sometimes you really don't appreciate Python's labour
saving features until you've experienced how much labour there is to be
saved.


--
Steven
 
Reply With Quote
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      02-09-2009
Steven D'Aprano:
> There's less code, fewer bugs and lines. Less applies to continuous
> quantities, like weight and "amount of code", and fewer applies to
> countable quantities.


Thank you, I'll try to improve my use of the language.


> Within reason, naturally. There's a reason why we write:
> for button in buttons:
> * * move(button, delta_x, delta_y)
> instead of
> for b in bs: mv(b, x, y)
> even though the second is significantly shorter.


Often Shortening names and packing more stuff in single lines that
deserve to be two lines aren't good ways to shorten code.


> Also, I don't think there's much advantage in trying to push new
> programmers to reduce the amount of code. Until you're really comfortable
> with the language, you need training wheels and scaffolding in the form
> of verbose code. Sometimes you really don't appreciate Python's labour
> saving features until you've experienced how much labour there is to be
> saved.


I don't agree. When you learn to code you also have to learn what does
it mean to write "good code", you have to learn that there are several
things that are important beside writing a correct output, like good
comments, well thought out names, good indentation, good idioms, quick
running time, small memory usage, writing clear and readable code, and
later develop elegance, the power of composition, abstraction,
indirection, meta programming, etc. Among such things there's the
importance of writing short programs. All such things are the seeds
that will develop into the personal style of the future programmer.

Such things are also useful for another purpose: to help the student
understand that code is craftsmanship, so she/he/shi can (and is
supposed to) be proud of the code that writes. This helps the student
understand that programming isn't just an ugly way to tell orders to a
moronic CPU, that helps develop appreciation for the act of writing
code, because it becomes something you do also for the sake of it, as
you do art, beside for usefulness. So you have to teach and show such
things from more or less the beginning.

Bye,
bearophile
 
Reply With Quote
 
r0g
Guest
Posts: n/a
 
      02-10-2009
J wrote:
> Thanks for your answers, especially Chris Rebert and Paul McGuire's. I
> have a question:
> How far does Python go in the Game Development field? (Using Python
> only, no extensions)



Hey J,

Python's all about the libraries (extensions), you won't be able to do
much without them but that's no big whoop. AFAIK most python libs are
released under LGPL or BSD style licenses so there's pretty much no
restriction on what you can use them for. A lot of games are written in
C for performance reasons but most python gaming libs are just wrappers
round C gaming libs and share the same names and methods so your
knowledge should travel with you.

As for which libs to use...

There's PyGame which is a a good mature library for 2D stuff.

Pyglet seem to be the most popular OpenGL lib for 3D stuff.

You might also want to look at the "Blender Game Engine" and the free
game "Yo Frankie", they use C for the heavy lifting and Python for
scripting levels and stuff, it might be a good way to test the waters.

Regards,

Roger Heathcote.
 
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
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 R. David Murray Python 0 01-17-2011 02:23 PM
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 Senthil Kumaran Python 0 01-17-2011 10:31 AM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Martin v. L÷wis Python 0 03-01-2008 10:51 PM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Paul Moore Python 0 03-01-2008 10:39 PM
Searching comp.lang.python/python-list@python.org (was: UTF-8) skip@pobox.com Python 0 03-10-2007 02:50 PM



Advertisments