• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why are Scanner and printf just out now?

 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic