Why don't people like lisp?

Rainer Deyke rainerd at eldwood.com
Fri Oct 24 17:26:37 EDT 2003


Marcin 'Qrczak' Kowalczyk wrote:
> In C++ you must choose between a local variable for the stream (which
> is equivalent to with-open-file) or dynamically allocated object
> (which is equivalent to open & close, where close is spelled delete).

I can also choose to have the stream reference counted (through
boost::shared_ptr or similar), and I can make it a member variable of an
object (tying the lifetime of the stream to the lifetime of the owning
object).

Now, I *could* write my own reference counting stream wrapper in Python,
together with a with_reference_to_stream HOF.  I could, but it would be
expensive, not only in terms of performnace, but also in terms of syntax and
mental overhead.

> You can't say that you want the C++ way and you don't want explicit
> open & close and with-open-file, because they are equivalent! They
> differ only in syntax details, but the style of usage and limitations
> are the same.

The syntax is actually very significant here.  Python's lack of anonymous
code blocks hurts, but even without this, the C++ syntax is more lightweight
and therefore more managable.  Compare the levels of indentation:

void f()
{
  std::fstream a("a"), b("b");
  do_something(a, b);
  std::fstream c;
  do_something_else(a, b, c);
}

def f():
  with_open_file(a = open("a")):
    with_open_file(b = open("b")):
      do_something(a, b)
      with_open_file(c = open("c")):
         do_something_else(a, b, c)


-- 
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com






More information about the Python-list mailing list