aspose file tools*
The moose likes Java in General and the fly likes Why are Scanner and printf just out now? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why are Scanner and printf just out now?" Watch "Why are Scanner and printf just out now?" New topic
Author

Why are Scanner and printf just out now?

Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I interrupt these practical questions with a philosophical one:

I am coming up to speed on Java 1.5 and I find code using java.util.Scanner and System.out.printf incredibly easier to write and read compared to the convoluted formatting and parsing techniques required by earlier versions of Java.

Since format strings were around since C (really since FORTRAN), why do you think it took so long for Java to add these features?


Mike Gershman
SCJP 1.4, SCWCD in process
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Intermediate forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
Well, printf depends on varargs and autoboxing, and Scanner relies on regular expressions (and they still had to make substantial changes to the regex package to support it). But you're right: they could have added those features long ago if they had wanted to. I think they just didn't want to corrupt their clean-syntaxed, statically-typed language. Both features effectively introduce dynamic typing by using a syntax that looks like line noise.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Without being a philosoph, I may only guess.

For the printf-like function, how they work in 1.5, you need the ellipse (...) and autoboxing.

Adding an rarely used ellipse-feature, only for formatting perhaps seemed not economical, when designing the language.
I can imagine a solution with Object [] instead of ellipse, and don't have a quick answer, why not to use it.
Perhaps because of intensive usage of reflection, which would have been needed, to implement it.
And perhaps in the beginning of Java, everybody expected the commandline to vanish in the haze: Windows promised to make everything right with win95, Linux was a small flower in the corner, java didn't konquer the servermarket, and logging was rarely needed.

Today we see, that windows will never be a stable system, and the linux-folk loves the commandline.
Logging, intensively done on servers, uses a CLI too. So the need for printf is more stable than thought.

Bjarne S. invented (?) cout << for c++ to get rid of printf ("%i", 7); -- with not much luck too. I liked the << operator much more than old printf-functions, but got in touch to outputstreams very early and had to learn both at about the same time.

Another try to explain the history:
The language C is getting out. (ouh - flamewars!)
And the programers have to learn Java now.

But they know every trick about printf, and claimed loudly to want it in java. And the nice people at sun answered: Ok, here you got it!

But there are other formatting-possibilities, we could live with for a long time.

[ September 26, 2004: Message edited by: Stefan Wagner ]
[ September 26, 2004: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stefan Wagner:
Adding an rarely used ellipse-feature, only for formatting perhaps seemed not economical, when designing the language.


Well, it's also a matter of constraint resources, I'd guess. What would you have wanted them to drop in exchange for those features?


I can imagine a solution with Object [] instead of ellipse, and don't have a quick answer, why not to use it.


They actually did so with java.text.MessageFormat.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
Well my two cents..

Think of its history. It was not originally used to teach programming fundamentals. Today, with the popularity in CS1 and APCS the language has had to "simplify" itself. I/O and formatting were good choices in simplification.

Also, as mentioned, going back to C roots.

Still, C# has, I think, a good way for I/O and formatting. Looks like it learned its lesson from Java mistakes.

Mike, email me. We will have a possible position opening again in Spring 05- if you are still interested in teaching.


Author and Instructor, my book
 
 
subject: Why are Scanner and printf just out now?