couldn't resist!
all thanks to Cay Horstmann
http://www.horstmann.com/

The March of Progress1980: 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

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

2008: Scala and Groovy

printf("%10.2f", x)

(Thanks to Will Iverson for the update. He writes: “Note the lack of
semi-colon. Improvement!”)

On 10 September 2010 13:49, Ricky Clarkson <ricky.clark...@gmail.com> wrote:

> Ok, I'll come clean.  The point is that a relatively common Java idiom
> (that I dislike), multiple constructors in a subclass that call an
> equivalent constructor in a superclass cannot be translated as-is to
> Scala, as Scala's secondary constructors (def this..) implicitly call
> the primary constructor.  You will have to change that code quite a
> lot to translate it to Scala, and the interface to it will have
> changed.  paulp found this when trying to automatically translate Java
> to Scala.
>
> The difficulty is not necessarily a bad thing, but I think it's a code
> sample that answers your original question.
>
> Ricky.
>
> --
> Ricky Clarkson
> Java and Scala Programmer, AD Holdings
> +44 1928 706373
> Skype: ricky_clarkson
>
>
>
> On Fri, Sep 10, 2010 at 12:44 PM, Kevin Wright <kev.lee.wri...@gmail.com>
> wrote:
> > Or without the obfuscation :)
> > def countFor(x : Int) = 2
> > def countFor(x : Float) = 3
> >
> > On 10 September 2010 12:27, Ricky Clarkson <ricky.clark...@gmail.com>
> wrote:
> >>
> >> That won't compile, but if I fix the obvious problems then you're left
> >> with a change to which things happen.  When you do new Y(3) in the
> >> original, X's constructor that takes an int will be called.  An
> >> alteration to make this clear follows, but I am trying to point out a
> >> difference that makes converting from (poor) Java to Scala difficult.
> >>
> >> class X {
> >>   public int count;
> >>
> >>   public X(int x) {
> >>     count = 2;
> >>   }
> >>
> >>   public X(float x) {
> >>     count = 3;
> >>   }
> >> }
> >>
> >> class Y extends X {
> >>   public Y(int x) {
> >>       super(x * 2);
> >>   }
> >>
> >>   public Y(float x) {
> >>       super(x * 2);
> >>   }
> >> }
> >>
> >> class YTest {
> >>  public void testY() {
> >>    assert new Y(0.5F).count == 3 && new Y(5).count == 2;
> >>  }
> >> }
> >>
> >> Ricky.
> >>
> >> --
> >> Ricky Clarkson
> >> Java and Scala Programmer, AD Holdings
> >> +44 1928 706373
> >> Skype: ricky_clarkson
> >>
> >>
> >>
> >> On Fri, Sep 10, 2010 at 12:11 PM, Kevin Wright <
> kev.lee.wri...@gmail.com>
> >> wrote:
> >> > easy!  It does absolutely nothing, so the obvious improvement in both
> >> > languages is not to write it at all...
> >> > But if you absolutely must keep the interface (mocking perhaps?) then:
> >> > class X(x: Float) {
> >> >  def this(x2: Int) = this(x2)
> >> > }
> >> > class Y(y: Float) extends X(y) {
> >> >   def this(y2: Int) = this(y2)
> >> > }
> >> >
> >> > On 10 September 2010 12:01, Ricky Clarkson <ricky.clark...@gmail.com>
> >> > wrote:
> >> >>
> >> >> class X {
> >> >>    public X(int x) {
> >> >>    }
> >> >>
> >> >>    public X(float x) {
> >> >>    }
> >> >> }
> >> >>
> >> >> class Y extends X {
> >> >>    public Y(int x) {
> >> >>        super(x * 2);
> >> >>    }
> >> >>
> >> >>    public Y(float x) {
> >> >>        super(x * 2);
> >> >>    }
> >> >> }
> >> >>
> >> >> Ricky.
> >> >>
> >> >> --
> >> >> Ricky Clarkson
> >> >> Java and Scala Programmer, AD Holdings
> >> >> +44 1928 706373
> >> >> Skype: ricky_clarkson
> >> >>
> >> >>
> >> >>
> >> >> On Fri, Sep 10, 2010 at 11:57 AM, Kevin Wright
> >> >> <kev.lee.wri...@gmail.com>
> >> >> wrote:
> >> >> > I'll throw down the gauntlet then...
> >> >> > Can anyone provide an example of Java code that's can't be improved
> >> >> > by
> >> >> > writing it in Scala
> >> >> > Or Scala code that can be improved by writing it in Java (but can't
> >> >> > be
> >> >> > improved by just rewriting within Scala)
> >> >> > By "improve", I mean that the code is better with regards to one
> (or
> >> >> > more)
> >> >> > of the following:
> >> >> > - readability (how quickly can another developer, familiar with the
> >> >> > language, understand the code)
> >> >> > - maintainability (how much work is involved in a simple
> refactoring)
> >> >> > - thread safety
> >> >> > But doesn't sacrifice any of the above qualities.
> >> >> >
> >> >> >
> >> >> > On 10 September 2010 11:45, Steven Herod <steven.he...@gmail.com>
> >> >> > wrote:
> >> >> >>
> >> >> >> This thread would be a lot better, faster and easier to read and
> >> >> >> reply
> >> >> >> to if it were written in Scala.
> >> >> >>
> >> >> >> On Sep 10, 8:42 pm, Ricky Clarkson <ricky.clark...@gmail.com>
> wrote:
> >> >> >> > Ok, conspiracy theory time!
> >> >> >> >
> >> >> >> > Reinier, the initiator of this thread, works on Project Lombok,
> >> >> >> > which
> >> >> >> > uses annotation processing to add language features to Java.
> >> >> >> > Therefore, isn't it in his interest to discourage uptake of
> Scala
> >> >> >> > and
> >> >> >> > Clojure?  Could he be trying to assert that all Scala users are
> >> >> >> > fanboys to try to discourage associating oneself with Scala?
> >> >> >> >
> >> >> >> > Of course, I jest.
> >> >> >> >
> >> >> >> > Ricky.
> >> >> >> >
> >> >> >> > --
> >> >> >> > Ricky Clarkson
> >> >> >> > Java Programmer and Scala Fanboi, AD Holdings
> >> >> >> > +44 1928 706373
> >> >> >> > Skype: ricky_clarkson
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > On Fri, Sep 10, 2010 at 11:28 AM, Wildam Martin
> >> >> >> > <mwil...@gmail.com>
> >> >> >> > wrote:
> >> >> >> > > On Fri, Sep 10, 2010 at 10:44, Kevin Wright
> >> >> >> > > <kev.lee.wri...@gmail.com>
> >> >> >> > > wrote:
> >> >> >> > >> But given the resistance I'm seeing to even small differences
> >> >> >> > >> between
> >> >> >> > >> Java/Scala syntax, I suspect that Clojure will be far too
> >> >> >> > >> radical
> >> >> >> > >> for
> >> >> >> > >> most
> >> >> >> > >> institutionalised Java developers.
> >> >> >> >
> >> >> >> > > Somehow this sounds as Java developers are considered as not
> >> >> >> > > being
> >> >> >> > > very flexible - all the Scala and Clojure or whatever else
> >> >> >> > > JVM-language programmers should remember, that most of them
> >> >> >> > > probably
> >> >> >> > > have been Java developers also for quite a long time.
> >> >> >> >
> >> >> >> > > Anyway, if it continues that way (if you need to address each
> >> >> >> > > single
> >> >> >> > > language-fan-boy begging for not turning a thread into trash)
> I
> >> >> >> > > will
> >> >> >> > > somewhat stop following the javaposse google group.
> >> >> >> > > --
> >> >> >> > > Martin Wildam
> >> >> >> >
> >> >> >> > >http://www.google.com/profiles/mwildam
> >> >> >> >
> >> >> >> > > --
> >> >> >> > > You received this message because you are subscribed to the
> >> >> >> > > Google
> >> >> >> > > Groups "The Java Posse" group.
> >> >> >> > > To post to this group, send email to
> javapo...@googlegroups.com.
> >> >> >> > > To unsubscribe from this group, send email to
> >> >> >> > > javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> >> >> >> > > For more options, visit this group
> >> >> >> > > athttp://groups.google.com/group/javaposse?hl=en.
> >> >> >>
> >> >> >> --
> >> >> >> You received this message because you are subscribed to the Google
> >> >> >> Groups
> >> >> >> "The Java Posse" group.
> >> >> >> To post to this group, send email to javapo...@googlegroups.com.
> >> >> >> To unsubscribe from this group, send email to
> >> >> >> javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> >> >> >> For more options, visit this group at
> >> >> >> http://groups.google.com/group/javaposse?hl=en.
> >> >> >>
> >> >> >
> >> >> >
> >> >> >
> >> >> > --
> >> >> > Kevin Wright
> >> >> >
> >> >> > mail / gtalk / msn : kev.lee.wri...@gmail.com
> >> >> > pulse / skype: kev.lee.wright
> >> >> > twitter: @thecoda
> >> >> >
> >> >> > --
> >> >> > You received this message because you are subscribed to the Google
> >> >> > Groups
> >> >> > "The Java Posse" group.
> >> >> > To post to this group, send email to javapo...@googlegroups.com.
> >> >> > To unsubscribe from this group, send email to
> >> >> > javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> >> >> > For more options, visit this group at
> >> >> > http://groups.google.com/group/javaposse?hl=en.
> >> >> >
> >> >>
> >> >> --
> >> >> You received this message because you are subscribed to the Google
> >> >> Groups
> >> >> "The Java Posse" group.
> >> >> To post to this group, send email to javapo...@googlegroups.com.
> >> >> To unsubscribe from this group, send email to
> >> >> javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> >> >> For more options, visit this group at
> >> >> http://groups.google.com/group/javaposse?hl=en.
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Kevin Wright
> >> >
> >> > mail / gtalk / msn : kev.lee.wri...@gmail.com
> >> > pulse / skype: kev.lee.wright
> >> > twitter: @thecoda
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "The Java Posse" group.
> >> > To post to this group, send email to javapo...@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/javaposse?hl=en.
> >> >
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "The Java Posse" group.
> >> To post to this group, send email to javapo...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> >> For more options, visit this group at
> >> http://groups.google.com/group/javaposse?hl=en.
> >>
> >
> >
> >
> > --
> > Kevin Wright
> >
> > mail / gtalk / msn : kev.lee.wri...@gmail.com
> > pulse / skype: kev.lee.wright
> > twitter: @thecoda
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "The Java Posse" group.
> > To post to this group, send email to javapo...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> > For more options, visit this group at
> > http://groups.google.com/group/javaposse?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to javapo...@googlegroups.com.
> To unsubscribe from this group, send email to
> javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>
>


-- 
Kevin Wright

mail / gtalk / msn : kev.lee.wri...@gmail.com
pulse / skype: kev.lee.wright
twitter: @thecoda

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javapo...@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to