Python development time is faster.

George Sakkis george.sakkis at
Mon Nov 13 16:51:58 CET 2006

Steven Bethard wrote:

> A simple example from document indexing.  Using Java Lucene to index
> some documents, you'd write code something like::
>      Analyzer analyzer = new StandardAnalyzer()
>      IndexWriter writer = new IndexWriter(store_dir, analyzer, true)
>      for (Value value: values) {
>          Document document = Document()
>          Field title = new Field("title", value.title,
>                                  Field.Store.YES,
>                                  Field.Index.TOKENIZED)
>          Field text = new Field("text", value.text,
>                                 Field.Store.YES,
>                                 Field.Index.TOKENIZED)
>          document.add(title)
>          document.add(text)
>      }
> Why is this code so verbose?  Because the Lucene Java APIs don't like
> useful defaults. So for example, even though StandardAnalyzer is
> supposedly *Standard*, there's no IndexWriter constructor that includes
> it automatically. Similarly, if you create a Field with a string name
> and value (as above), you must specify both a Field.Store and a
> Field.Index - there's no way to let them default to something reasonable.
> Compare this to Python code. Unfortunately, PyLucene wraps the Lucene
> APIs pretty directly, but I've wrapped PyLucene with my own wrapper that
> adds useful defaults (and takes advantages of things like Python's
> **kwargs).  Here's what the same code looks like with my Python wrapper
> to Lucene::
>      writer = IndexWriter(store_dir)
>      for value in values:
>          document = Document(title=value.title, text=value.text)out two
>          writer.addDocument(document)
>      writer.close()
> Gee, and I wonder why it took me so much longer to write things in Java. ;-)

Oh, the memories... I went down the same road about two years ago,
though I didn't know about PyLucene at the time and wrapped in jython
the parts of Lucene I used... never bothered to deal with java's
verbosity after that. It's a pity that jython resembles abandon-ware
these days, when jRuby showed up pretty recently and is gaining in
penetration with the java crowd. It will be a non-trivial loss for
python if it is left behind in the JVM world (at least if the latter is
not swallowed by the .NET dark forces, which doesn't seem to happen any
time soon ;-).


More information about the Python-list mailing list