Thanks Andrea, we'll work through your feedback and let you know if we have any questions.  BTW, I have made some good updates on Chapter 1 based on your commentary and I plan to roll them into the next update this week.  I found a few places that simply did not convert from MS Word -> restructuredText -> Sphinx.  For some of the chapters, I wrote in MS Word as that is the format we need to use while submitting to Apress.  Later in the book I began to write using restructuredText and converting to MS Word when submitting to Apress.  These later chapters all converted quite well to Sphinx so there should not be as many "missing" pieces or code and grammatical errors.

Also, the TOC resides in the repository as well.  If something is out of place in the book (or missing), please feel free to mark up the toc and send it to us.  

Best to you

Josh Juneau
juneau001@gmail.com
http://jj-blogger.blogspot.com
Twitter ID:  javajuneau


On Sun, Aug 2, 2009 at 2:37 AM, Andrea Aime <aaime@opengeo.org> wrote:
Hi,
continuing my feedback about the jython book.

This first batch has been written before you updated the
book online, not sure how current it still is:

----------------------------------------------------------------------------

http://jythonpodcast.hostjava.net/jythonbook/chapter2.html#dictionaries
->If I do:
myDict = {}
myDict['hey']
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
KeyError: 'hey'
Ugh, an error? This is surprising coming from a Java Map background,
where the same returns null. Should be documented.


http://jythonpodcast.hostjava.net/jythonbook/chapter2.html#jython-specific-collections
-> so the code example referes to a Jython < 2.2 situation? Really worth
including? I would find more interesting an example showing how to
create an ArrayList and then perform slicing or list comprehension on
it, and show that the results are still a Java ArrayList (for slicing)
or a native Jython collection (for comprehension). Something like:
 >>> import java.util.ArrayList as ArrayList
 >>> al = ArrayList(range(10))
 >>> al[0:2]
[0, 1]
 >>> al[0:2].__class__
<type 'java.util.ArrayList'>
 >>> [i * 2.0 for i in al]
[0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0]
 >>> [i * 2.0 for i in al].__class__
<type 'list'>

http://jythonpodcast.hostjava.net/jythonbook/chapter2.html#files
-> all the file operations are listed in prose, a table would be
    better to use the book as a reference as well
-> "If the file does not yet exist on disk, then it will automatically
be created." This is not what I see by running the code example (using
jython 2.5)
 >>> f = open('/tmp/newfile.txt', 'r+')
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: '/tmp/newfile.txt'
Tried in CPython, got the same error message.
If C programming memory serves me right the file has to be opened in
"w+" mode and then an extra command has to be called every time one
switches between read and write mode (seek, tell... can't remember).
-> Why do you say "Windows binary mode"? Doesn't unix have one too?

http://jythonpodcast.hostjava.net/jythonbook/chapter2.html#iterators
-> maybe an example of why using an iterator is interesting in Jython
    would be good, given the availability of comprehensions,
    map(),reduce(),filter() and lambdas.
-> also, in the end no-one is going to call __iter__() directly,
    "for x in iterable" will do it for us and using

http://jythonpodcast.hostjava.net/jythonbook/chapter2.html#referencing-and-copies
-> You don't mention that copy.copy can be used to make a shallow copy

http://jythonpodcast.hostjava.net/jythonbook/chapter2.html#garbage-collection
-> from reading the docs I assumed __del__ was something special about
    Jython, but in fact it seems it's not?
    http://www.python.org/doc/2.3.5/ref/customization.html
    If the java and python GC model do differ there are implications on
    using Python libs in Jython, i.e., the CPython one might assume
    the finalizers are actually run and within a predictable time and
    so on (at least the __del__ docs above do not seem to tell people
    that using it is bad practice or the like).

http://jythonpodcast.hostjava.net/jythonbook/chapter3.html#mathematical-operations
-> the list of operators contains more than the equivalent one in
    previous chapters
-> the example would be clearer this way (before/after comparison):
 >>> 9/5
1
 >>> from __future__ import division
 >>> 9/5
1.8

http://jythonpodcast.hostjava.net/jythonbook/chapter3.html#program-flow
-> hmmm.... this is starting to sound like "all we wanted to tell you
    in the first chapter but we did not dare to". Seriously, seeing in
    the first chapter that python has control structures like
    any other languages was... yawn.... adding this little pepper there
    would have made it more entertaining :-)


http://jythonpodcast.hostjava.net/jythonbook/chapter3.html#example-code
-> The "# Enter a player for the team" is not aligned and breaks the
visual flow of the if branch (and given python rules seems even more
out of place)
The sample program does not do much, once you enter the 'C' section
you get out of it only by exiting the program as well
-> Seeing this example I started having a urge for an IDE. Java devs
    are pretty much dependent on having a good IDE, adding pointers
    for the major IDE plugins here would be a good idea.
    So I went and installed pyDev and tried to improve a little the
    example. Attached is the result: the file is always read on startup,
    does "compile" (the original had quotes and indenting issue that made
    it not) the app does not exit after inserting, the program flow is
    easier to read (for me at least)

http://jythonpodcast.hostjava.net/jythonbook/chapter5.html#assertions-and-debugging
-> __debug__, interesting. And how does one enable debugging mode? By a
simple test:
 >>> __debug__
1
it would seem the jython interpreter starts in debug mode by default? Ugh...


http://jythonpodcast.hostjava.net/jythonbook/chapter5.html#context-managers
-> Often times, developers elect to make use of the issues. Often times,
developers elect to make use of the try-finally blocks to ensure that
such resources are handled properly.

----------------------------------------------------------------------------

 From here on I've been reading the latest version published.

----------------------------------------------------------------------------


http://jythonpodcast.hostjava.net/jythonbook/chapter6.html#basic-syntax
-> Hmmm... fields, where are the fields? Are they created just by
referencing them in __init__. Or anywhere else in the same class?
Or anywhere else in the code? Any real encapsulation (private/public
fields?)

http://jythonpodcast.hostjava.net/jythonbook/chapter6.html#more-advanced-abstraction
-> in previous context introductions
(http://jythonpodcast.hostjava.net/jythonbook/chapter5.html#context-managers)
there was no mention of "closing"
-> the code example does not run in python neither in jython
Original exception was:
Traceback (most recent call last):
  File "/home/aaime/devel/workspaces/jython/jythonbook/src/pickle.py",
line 3, in <module>
    from pickle import dumps, loads
  File "/home/aaime/devel/workspaces/jython/jythonbook/src/pickle.py",
line 3, in <module>
    from pickle import dumps, loads
ImportError: cannot import name dumps

This is under Eclipse and pydev. The example works if I run it with the
pydev python interpreter but not with the pydev jython one, even if
the pyckle.py should be in the path (I have jython/Lib in the system
libs). However at this point the files got bigger so being able
to use them in a IDE is a must (at least from the perspective of
the spoiled Java developer).

Running the example in pure python or from the jython command line
still does not work as advertised, the output is:
Loading objects from disk!
====================
<__main__.Simple object at 0xb7dcf26c>
<__main__.Simple object at 0xb7e80d2c>

It works as suggested if __unicode__ is replaced with __repr__


http://jythonpodcast.hostjava.net/jythonbook/chapter6.html#protocols
-> the code has an extra "well" into it:
   length = int(data)well
-> the description does not say that close() is part of the context
management protocol for closing, if you don't implement it the code will
break
-> the PickleStream class is missing
from pickle import dumps, loads
-> the code example on using the picklestream is missing imports,
and it's also missing the definition of Simple class (which can be
gathered from other examples. Would be nice if the
examples were runnable, thought I must admit fixing them is educational
(other people might not be as amused as me)

from __future__ import with_statement
from contextlib import closing
from picklestream import *

class Simple(object):
    def __init__(self, value):
        self.value = value
    def __repr__(self):
        return "Simple[%s]" % self.value

with closing(PickleStream(open('simplefile','wb'))) as stream:
    for i in range(10):
        obj = Simple(i)
        stream.write(obj)

with closing(PickleStream(open('simplefile','rb'))) as stream:
    for obj in stream:
        print obj

Looking into this also made me wonder what are the class/file
naming convention. In Java there is an enforced convention,
is there in Python anything similar? (if not a enforced one,
a best practice?)

http://jythonpodcast.hostjava.net/jythonbook/chapter6.html#runtime-binding-of-methods
-> kind of begs the question: can I also add fields at runtime?

http://jythonpodcast.hostjava.net/jythonbook/chapter6.html#closures-and-passing-objects
-> "use of getattr, hasattr and setattr" hemmm... which are? You can
attach attributes to function definitions? Better explain this before
using it.
-> what are *args and **kwargs? What is the "*foo" notation to start
with? Reminds me of C pointers.
This section really needs a rework or you need to explain what you're
using before it, otherwise it seems you're pulling magic out of a hat.


http://jythonpodcast.hostjava.net/jythonbook/chapter7.html#the-import-statement
-> the example is not very illuminating, why would one want to redefine
   a function if it's not available? A reason could be to write code
   that is portable across CPython and Jython, something like:
   try:
     import cPickle as pickle
   except:
     import pickle
   to get on the fast lane in CPython but still have a fallback for
   Jython (is there a fast lane impleemntation of pickle for Jython
   btw?)

http://jythonpodcast.hostjava.net/jythonbook/chapter7.html#an-example-program
-> the example does not work, there are two errors:
   - searchdir.py does not instantiate a ScanResults object, I've added
     scanner = scanner.ScanResults()
     just before starting to use the scanner
   - scanner.py first import does not work either, corrected into:
     from walker import DirectoryWalker
Sphinx allows to import files and syntax hightlight them, so you could
have all these examples as runnable code somewhere and import
the sources. And then add some unit testing to them to make sure
they do work (disadvantage of jython, if you don't unit test its code
you don't even know if there are syntax errors, let alone have it
working as expected).
-> once fixed the example reports 6 results, not 5, since the various
.py files will be turned into xxx$py.class which also do contain
the terms. Maybe limit the scan to just .py files.
-> mixing togheter GUI and code doing fs scan does not seem very clean

http://jythonpodcast.hostjava.net/jythonbook/chapter8.html#parsing-commandline-options

-> syntax errors as usual in foo3.py, the add_options call seems to be
missing a comma, but I'm not sure. The error is:
    parser.add_option("-f", "--foo" help="set foo option")
                                       ^
-> neither python nor jython from command line seem to be able to import
   optionparser:
    from optparse import optionparser
ImportError: cannot import name optionparser

According to http://docs.python.org/library/optparse.html it's
OptionParser instead. Tried, it works.

http://jythonpodcast.hostjava.net/jythonbook/chapter8.html#scripting-the-filesystem
-> Humm... nice to hear os has so many nice functions. A pointer to a
reference to those functions would be nice
(http://docs.python.org/library/os.html)


Enough for this mail. I'll continue with the good stuff (sql alchemy, django, pylons) later.

Cheers
Andrea

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-dev mailing list
Jython-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-dev