Re: About reading Python code

2008-03-25 Thread Phil
On 2008-03-18, sturlamolden [EMAIL PROTECTED] wrote:
 First, I recommend that you write readable code! Don't use Python as
 if you're entering the obfuscated C contest.

 Two particularly important points:

 * Comments are always helpful to the reader.

It would be nice if this was the case! I once saw a preogram where 
a line of code like this:

   foo++;

Would be annotated with a comment like this:

   //
   /*  */
   /* Increment foo*/
   /*  */
   //

This comment was worse than useless, because it (and others like 
it) took up space that distracted from the information-containing 
parts of the code.

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


Re: About reading Python code

2008-03-18 Thread hellt
On 18 мар, 03:57, sturlamolden [EMAIL PROTECTED] wrote:
 On 17 Mar, 04:54, WaterWalk [EMAIL PROTECTED] wrote:

  So I'm curious how to read code effectively. I agree that python code
  is clear, but when it becomes long, reading it can still be a hard
  work.

 First, I recommend that you write readable code! Don't use Python as
 if you're entering the obfuscated C contest.

 Two particularly important points:

 * If you find yourself thinking this module is too long, that's
 probably what it is. Half a page of code per module is fine. Two pages
 of code per module can be too much.

 * Comments are always helpful to the reader.

 Second, I recommend getting a good IDE. E.g. pick one of:

 * Microsoft Visual Studio (commercial)
 * Eclipse with PyDev and CDT (free)
 * SPE (free)
 * ActiveState Komodo IDE (commercial)

under Microsoft Visual Studio do you mean IronPython instance?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: About reading Python code

2008-03-18 Thread sturlamolden
On 18 Mar, 08:00, hellt [EMAIL PROTECTED] wrote:

 under Microsoft Visual Studio do you mean IronPython instance?

AFAIK, with the latest VS 2008 you can develop for CPython and
IronPython.

http://blogs.msdn.com/haibo_luo/archive/2007/10/16/5482940.aspx



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


Re: About reading Python code

2008-03-17 Thread WaterWalk
On Mar 17, 1:54 pm, Stargaming [EMAIL PROTECTED] wrote:
 On Sun, 16 Mar 2008 20:54:01 -0700, WaterWalk wrote:
  Hello. I wonder what's the effective way of figuring out how a piece of
  python code works.

 If your Python code is well-written, it should be easy figuring out what
 it means by just reading it. For more complex programs, of course, this
 method can fail.

  With C I often find it very useful to be able to run
  the code in step mode and set breakpoints in a debugger so I can watch
  how the it executes, how the data change and how the code jumps from one
  function to another. But with Python, the debugger is a little
  primitive. The default IDLE doesn't even allow me to set a breakpoint.
  When the code is long, I am often lost in it.

 IDLE is just, well, a batteries-included editor. There are many people
 (me included) who do *not* like it because it's so weak and doesn't have
 any real uses cases if your programs get sufficiently complex (because
 IDLE itself is sufficiently primitive).

 You might be interested in *real* debuggers, such as the Python Debugger
 `PDB http://docs.python.org/lib/module-pdb.html`_. If you don't find
 its usage obvious, a quick google search just turned up a nice `tutorial
 http://www.ferg.org/papers/debugging_in_python.html`_.

 You might find the `Python Profilers http://docs.python.org/lib/
 profile.html`_ particularly interesting, `profile` for finding out which
 function sucks up the most calls/time, `trace` for more sophisticated
 stuff.
 `pythontracer http://code.google.com/p/pythontracer/` sounds like a
 good combination of both.

  So I'm curious how to read code effectively. I agree that python code is
  clear, but when it becomes long, reading it can still be a hard work.

 A common practice is just inserting `print` statements since it's so
 easy. If you think your debugging isn't temporary but could be useful and
 will be enabled every now and then, you could also use the `logging
 module http://docs.python.org/lib/module-logging.html`_ with the
 ``DEBUG`` level.

 There was a blog post recently about how to do this `generically for
 functions http://wordaligned.org/articles/echo`_.

  BTW. I think this problem also exists in other script languages.

 FWIW, I think it's particularly easier in scripting languages to
 implement all kinds of tracing (apart from debugging, which is rather
 unpopular in Python) because you have one *extra* level (the interpreter)
 between your machine and your code.

 HTH,
 Stargaming

Thanks for your informative reply. I'll try them. I think I need more
practice to familiarize myself with those idioms of Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About reading Python code

2008-03-17 Thread Ben C
On 2008-03-17, WaterWalk [EMAIL PROTECTED] wrote:
 Hello. I wonder what's the effective way of figuring out how a piece
 of python code works. With C I often find it very useful to be able to
 run the code in step mode and set breakpoints in a debugger so I can
 watch how the it executes, how the data change and how the code jumps
 from one function to another. But with Python, the debugger is a
 little primitive. The default IDLE doesn't even allow me to set a
 breakpoint.

It does, you just right-click and go set breakpoint. But yes IDLE is a
bit basic.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About reading Python code

2008-03-17 Thread Nir
On Mar 17, 5:54 am, WaterWalk [EMAIL PROTECTED] wrote:
 Hello. I wonder what's the effective way of figuring out how a piece
 ofpythoncode works. With C I often find it very useful to be able to
 run the code in step mode and set breakpoints in adebuggerso I can
 watch how the it executes, how the data change and how the code jumps
 from one function to another. But withPython, thedebuggeris a
 little primitive. The default IDLE doesn't even allow me to set a
 breakpoint. When the code is long, I am often lost in it.

 So I'm curious how to read code effectively. I agree thatpythoncode
 is clear, but when it becomes long, reading it can still be a hard
 work.

Try Winpdb - www.winpdb.org (works on Linux as well). Don't forget to
send feedback.

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


Re: About reading Python code

2008-03-17 Thread Roman Dodin


WaterWalk пишет:
 Hello. I wonder what's the effective way of figuring out how a piece
 of python code works. With C I often find it very useful to be able to
 run the code in step mode and set breakpoints in a debugger so I can
 watch how the it executes, how the data change and how the code jumps
 from one function to another. But with Python, the debugger is a
 little primitive. The default IDLE doesn't even allow me to set a
 breakpoint. When the code is long, I am often lost in it.

 So I'm curious how to read code effectively. I agree that python code
 is clear, but when it becomes long, reading it can still be a hard
 work.
   

You also can use free IDE (for example Eclipse) and PyDev plugin, which 
includes comfortable Debugger
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: About reading Python code

2008-03-17 Thread Gabriel Genellina
En Mon, 17 Mar 2008 01:54:01 -0200, WaterWalk [EMAIL PROTECTED]  
escribi�:

 Hello. I wonder what's the effective way of figuring out how a piece
 of python code works. With C I often find it very useful to be able to
 run the code in step mode and set breakpoints in a debugger so I can
 watch how the it executes, how the data change and how the code jumps
 from one function to another. But with Python, the debugger is a
 little primitive. The default IDLE doesn't even allow me to set a
 breakpoint. When the code is long, I am often lost in it.

See the wiki at http://wiki.python.org/moin/DevelopmentTools for more  
editors, debugging tools and IDEs.

-- 
Gabriel Genellina

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

Re: About reading Python code

2008-03-17 Thread sturlamolden
On 17 Mar, 04:54, WaterWalk [EMAIL PROTECTED] wrote:

 So I'm curious how to read code effectively. I agree that python code
 is clear, but when it becomes long, reading it can still be a hard
 work.

First, I recommend that you write readable code! Don't use Python as
if you're entering the obfuscated C contest.

Two particularly important points:

* If you find yourself thinking this module is too long, that's
probably what it is. Half a page of code per module is fine. Two pages
of code per module can be too much.

* Comments are always helpful to the reader.

Second, I recommend getting a good IDE. E.g. pick one of:

* Microsoft Visual Studio (commercial)
* Eclipse with PyDev and CDT (free)
* SPE (free)
* ActiveState Komodo IDE (commercial)

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


Re: About reading Python code

2008-03-17 Thread Paul Rubin
WaterWalk [EMAIL PROTECTED] writes:
 from one function to another. But with Python, the debugger is a
 little primitive. The default IDLE doesn't even allow me to set a
 breakpoint. When the code is long, I am often lost in it.

Try winpdb.org which despite the name has nothing to do with MS Windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About reading Python code

2008-03-17 Thread Jeff Schwab
sturlamolden wrote:
 On 17 Mar, 04:54, WaterWalk [EMAIL PROTECTED] wrote:
 
 So I'm curious how to read code effectively. I agree that python code
 is clear, but when it becomes long, reading it can still be a hard
 work.
 
 First, I recommend that you write readable code! Don't use Python as
 if you're entering the obfuscated C contest.

Er, don't use anything other than C if you're entering an obfuscated C 
contest, or anything other Perl for an obfuscated Perl contest, etc.

Do use Python if you're entering an obfuscated Python contest.  Found 
online:

[#[#[#[#[#[#[#[#[# By TaroOgawa #]#]#]#]#]#]#]#]#]


  globals()
.update({   __:
 lambda x: globals()
 .update(( dict([[x]
*2])))}),   __(((
  Just)))
,__((   another
 )),__ (Python
  ),__(   Hacker)
  ];print (.join(
 [(Just),( (another)
),(Python   ),Hacker]
  ));__


 Two particularly important points:
 
 * If you find yourself thinking this module is too long, that's
 probably what it is. Half a page of code per module is fine. Two pages
 of code per module can be too much.
 
 * Comments are always helpful to the reader.

If only 'twere so.  *Good* comments are always helpful.  Please do not 
comment every method with this is a method or the like.  One of the 
things that often makes newb code stand out is that the programmer 
couldn't tell the things that needed to be commented from the places 
where comments just got in the way.

 Second, I recommend getting a good IDE. E.g. pick one of:
 
 * Microsoft Visual Studio (commercial)
 * Eclipse with PyDev and CDT (free)
 * SPE (free)
 * ActiveState Komodo IDE (commercial)

* Vim on Linux.  (No desire here to debate the meaning of IDE, but with 
Vim or Emacs on any Unix-like platform, the whole system effectively is 
the IDE.)
-- 
http://mail.python.org/mailman/listinfo/python-list


About reading Python code

2008-03-16 Thread WaterWalk
Hello. I wonder what's the effective way of figuring out how a piece
of python code works. With C I often find it very useful to be able to
run the code in step mode and set breakpoints in a debugger so I can
watch how the it executes, how the data change and how the code jumps
from one function to another. But with Python, the debugger is a
little primitive. The default IDLE doesn't even allow me to set a
breakpoint. When the code is long, I am often lost in it.

So I'm curious how to read code effectively. I agree that python code
is clear, but when it becomes long, reading it can still be a hard
work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About reading Python code

2008-03-16 Thread WaterWalk
On Mar 17, 11:54 am, WaterWalk [EMAIL PROTECTED] wrote:
 Hello. I wonder what's the effective way of figuring out how a piece
 of python code works. With C I often find it very useful to be able to
 run the code in step mode and set breakpoints in a debugger so I can
 watch how the it executes, how the data change and how the code jumps
 from one function to another. But with Python, the debugger is a
 little primitive. The default IDLE doesn't even allow me to set a
 breakpoint. When the code is long, I am often lost in it.

 So I'm curious how to read code effectively. I agree that python code
 is clear, but when it becomes long, reading it can still be a hard
 work.

BTW. I think this problem also exists in other script languages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About reading Python code

2008-03-16 Thread Stargaming
On Sun, 16 Mar 2008 20:54:01 -0700, WaterWalk wrote:

 Hello. I wonder what's the effective way of figuring out how a piece of
 python code works.

If your Python code is well-written, it should be easy figuring out what 
it means by just reading it. For more complex programs, of course, this 
method can fail.

 With C I often find it very useful to be able to run
 the code in step mode and set breakpoints in a debugger so I can watch
 how the it executes, how the data change and how the code jumps from one
 function to another. But with Python, the debugger is a little
 primitive. The default IDLE doesn't even allow me to set a breakpoint.
 When the code is long, I am often lost in it.

IDLE is just, well, a batteries-included editor. There are many people 
(me included) who do *not* like it because it's so weak and doesn't have 
any real uses cases if your programs get sufficiently complex (because 
IDLE itself is sufficiently primitive).

You might be interested in *real* debuggers, such as the Python Debugger 
`PDB http://docs.python.org/lib/module-pdb.html`_. If you don't find 
its usage obvious, a quick google search just turned up a nice `tutorial 
http://www.ferg.org/papers/debugging_in_python.html`_.

You might find the `Python Profilers http://docs.python.org/lib/
profile.html`_ particularly interesting, `profile` for finding out which 
function sucks up the most calls/time, `trace` for more sophisticated 
stuff.
`pythontracer http://code.google.com/p/pythontracer/` sounds like a 
good combination of both.

 So I'm curious how to read code effectively. I agree that python code is
 clear, but when it becomes long, reading it can still be a hard work.

A common practice is just inserting `print` statements since it's so 
easy. If you think your debugging isn't temporary but could be useful and 
will be enabled every now and then, you could also use the `logging 
module http://docs.python.org/lib/module-logging.html`_ with the 
``DEBUG`` level.

There was a blog post recently about how to do this `generically for 
functions http://wordaligned.org/articles/echo`_.

 BTW. I think this problem also exists in other script languages.

FWIW, I think it's particularly easier in scripting languages to 
implement all kinds of tracing (apart from debugging, which is rather 
unpopular in Python) because you have one *extra* level (the interpreter) 
between your machine and your code.

HTH,
Stargaming
-- 
http://mail.python.org/mailman/listinfo/python-list