Re: [Clojure-contrib] Re: #55: clojure.contrib.sql expects *err* to be a PrintWriter Ticket updated

6 views
Skip to first unread message

Stephen C. Gilardi

unread,
Jan 1, 2010, 4:57:55 PM1/1/10
to cloju...@googlegroups.com
On Dec 31, 2009, at 6:22 PM, Richard Newman wrote:

> Ticket alert by Richard Newman in space Clojure Contrib
> #55: clojure.contrib.sql expects *err* to be a PrintWriter

I think *err* should be required to be bound to a PrintWriter: it's intended for human readable messages and stack traces. Throwable includes a method for printing the current stack trace to a PrintWriter. It seems wasteful and cumbersome to me for users of *err* to have to wrap it to make it useful for those purposes.

There is some precedent for this in the Java standard streams: System/err (at least as a default on my system) is a java.io.PrintStream. If it were defined more recently than "in the beginning" it would likely be a java.io.PrintWriter, and if it were defined even more recently the class of the object it references would likely be required to implement an appropriate Interface.

When I wrote the patch that added *err* to Clojure, I chose PrintWriter as the default on purpose:

http://groups.google.com/group/clojure/browse_thread/thread/f2742a94f8031d82

I also intended that being bound to a PrintWriter be a requirement, but it appears I didn't give it a doc string to specify that.

If we relax the current de facto requirement that *err* be a PrintWriter, clojure.main/repl-caught's implementation will also need to change to something less straightforward.

I'm in favor of:

- requiring that *err* be bound to a PrintWriter so all code can depend on being able to .println and print stack traces to it without wrapping it, and
- documenting *err* to reflect that requirement, and
- fixing clojure's swank rather than changing c.c.sql.

Thoughts?

--Steve

Richard Newman

unread,
Jan 1, 2010, 5:45:34 PM1/1/10
to cloju...@googlegroups.com
> I'm in favor of:
>
> - requiring that *err* be bound to a PrintWriter so all code can
> depend on being able to .println and print stack traces to it
> without wrapping it, and
> - documenting *err* to reflect that requirement, and
> - fixing clojure's swank rather than changing c.c.sql.
>
> Thoughts?

Works for me. I'd add to that list:

* Considering normalizing these constraints for *out*, also. On my
machine, *out* is an OutputStreamWriter, not a kind of PrintWriter.
* Adding the appropriate type annotations to libraries such as
c.c.sql, which currently use reflection every time they print update
counts.

Is there any downside to wrapping a StringWriter in a PrintWriter?

Reply all
Reply to author
Forward
0 new messages