[Home] [By Thread] [By Date] [Recent Entries]


Robin Berjon wrote:

> But now I'm writing in my platform's default encoding. That might have 
> been tolerable in the 80s when the folks who came up with this 
> ridiculous API were sharpening their text-munging fu on ASCII, but those 
> benighted days are thankfully over, in no little part thanks to XML's 
> arrival.
> 

You're right. In reality I'd write something like this:

Writer out = new OutputStreamWriter(new FileOutputStream("file.txt"), 
"UTF-8");

It's still one line, though a longish one. Perhaps I'd even break it 
into two lines. But I'd have to do similar things in Perl or Python if I 
wanted to handle character sets sensibly there too.

The real difference is that Java assumes you want to do the right thing 
with full error handling, appropriate character set support, and more by 
default. It's a language designed for professional applications that 
cross the t's and dot the i's.

Perl et al. assume you want to write quick and dirty throwaway hacks. 
It's a difference in focus. Of course, you can write professional apps 
in Perl or quick and dirty hacks in Java, but you work against the 
language when you do that. Pick the language that's appropriate to your 
task.

>   open my $fileHandle, ">utf-8", "filename.txt" or die "Error opening 
> file: $!";

Perfect example. The entire app shuts down because you couldn't open one 
file. I can make a Java program shut down in one line too, but it's not 
the natural thing to do in an end user facing application or a reliable 
library.

-- 
Elliotte Rusty Harold  elharo@m...
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member