March of Progress

I posted this long time ago in another incarnation of the blog, but I figured it is worth revisiting again. The original was found on Cay Horstmann’s homepage.

1980: C

printf("%10.2f", x);

1988: C++

cout << setw(10) << setprecision(2) << showpoint << x;

1996: Java

java.text.NumberFormat formatter
= java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i < 10; i++)
System.out.print(' ');
System.out.print(s);

2004: Java 5.0

System.out.printf("%10.2f", x);

Funny but true. mrgreen

Related Posts:

  • The Joys of Backup over USB
  • My First Adsense Check
  • Plan B? There is no plan B!
  • The Watchmen: Movie
  • Finally - a fweakin flyin CAR!
  • Ammend the DMCA
  • Dollar Bill Ruler
  • Installation Wizards are not allways User Friendly
  • RIAA Sues LimeWire
  • Loading Startup Applications… Please Wait…

  • 6 Responses to “March of Progress”

    1. Gravatar StarHawk UNITED STATES Says: Reply to this comment

      Gotta admit that’s pretty funny. I’m a C programmer mostly so can’t help but wonder why people try to reinvent the wheel. Of course I am also well aware of the faults of printf, and actually kinda like cout. However I have serious problems with the 1996 Java code example. I was actually trying to learn Java at about that time. Lots of fun, huh.
      And thanks for the link to Cay Horstmann’s homepage. I love some of his quotes. haha.
      Our great democracies still tend to think that a stupid man is more likely to be honest than a clever man, and our politicians take advantage of this prejudice by pretending to be even more stupid than nature made them.” Bertrand Russell

      Posted using Mozilla Firefox Mozilla Firefox 1.0.7 on Windows Windows 2000
    2. Gravatar Luke UNITED STATES Says: Reply to this comment

      I thin the Java example is a little over exaggerated to make the joke work. But yes, some simple things require many lines of Java to implement. But it does make sense in an enterprisey kind of way.

      Once you set up that NumberFormat object you can just pass it around and reuse it. And if the format changes, you just go back and modify the 2 initialization lines instead of hunting down the 350 printf statements in your code.

      Java 5.0 cuts down on the verbosity a little, and reintroduces introduces many old-new features into the language. It’s a step in a right direction.

      Oh, and that is the best quote evar! lol

      Posted using Mozilla Firefox Mozilla Firefox 1.0.8 on Ubuntu Linux Ubuntu Linux
    3. Gravatar StarHawk UNITED STATES Says: Reply to this comment

      I like Java don’t get me wrong there. I actually like all the C derived languages. And yes I’m slowly but surely getting used to the OO paradigm. I certainly understand why Java and the other OO langs “make sense in an enterprisey kind of way.” The beauty and danger of C is that it allows ya to do whatever ya want to do, good or bad. “hunting down the 350 printf statements in your code” would be a great example of poor coding not a fault of C. There are ways of dealing with this situation. Both good and bad ways. Bad being macros, good being keeping the print statement in a function, or use a formatting string defined in a header file. I adore C because mostly I’m a glutton for punishment, what can I say. But I do try to keep my code readable and follow some kinda rational pseudo-object oriented coding paradigm. )

      Posted using Mozilla Firefox Mozilla Firefox 1.0.7 on Windows Windows 2000
    4. Gravatar Luke UNITED STATES Says: Reply to this comment

      Yeah, definitely - C can be very structured and reliable when it wants to. I actually have great respect for C programmers because of the fact that they will often need to deal with stuff like memory deallocation, array bounds and etc… Working in Java I blisfully ignore all these things, because the language does them for me.

      So whenever I do need to write some C I susually forget to do all that stuff and get slammed for it when someone reviews my code. Force of habbit. P

      The 350 printf statements was a bad example, but you know what I mean. I totally agree this is not a feature of the language. Bad programmers will keep producing bad code regardless of the language or environment you put them in. )

      Posted using Mozilla Firefox Mozilla Firefox 1.0.8 on Ubuntu Linux Ubuntu Linux
    5. Gravatar Dan UNITED STATES Says: Reply to this comment

      Somewhat related, as programming jokes go.

      Posted using Mozilla Firefox Mozilla Firefox 1.5.0.6 on Windows Windows XP
    6. Gravatar Luke UNITED STATES Says: Reply to this comment

      Hehe… Oldie but goodie. I love how the college senior code snippet is in lisp. )

      Posted using Mozilla Firefox Mozilla Firefox 1.5.0.6 on Windows Windows XP

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]