On Wed, May 6, 2009 at 7:11 PM, Sebastian Himberger <
sebastian.himber...@googlemail.com> wrote:

>
> H Viktori,
>
> regarding this code:
>
> *case class Person(var name : String)*
>
> So does Scala generate/impy a sensible hashCode and equals
> implementation or why are they omitted in your Scala example? I'm a
> total Scala newby so I would be glad to be enlightened.


Greetings Sebastian,
Sensibility is debatable, but yes, Scala will generate that for you.
(Leaving that up to the application developer has historically been humorous
at best.)

Best regards,
Viktor


>
>
> Thanks a lot,
> Sebastian
>
> On 6 Mai, 10:22, Viktor Klang <viktor.kl...@gmail.com> wrote:
> > On Wed, May 6, 2009 at 3:37 AM, Alexey Zinger <inline_f...@yahoo.com>
> wrote:
> >
> > > This is gonna be about verbosity of generics, isn't it?
> >
> > Hi Alexey!
> >
> > The switch to Java 5 certainly added alot of cruft for API developers
> with
> > regards to the addition of Generics.
> > But this is not about Generics, this is about all the small things adding
> up
> > - turning Java into a boilerplatey language when building
> abstractions/APIs.
> >
> > When I switched from Java to Scala, I suddenly noticed a rather striking
> > difference: In Java there's alot of "supporting" code; and in Scala,
> there
> > is alot less.
> > This means that you spend less time writing code, and more time thinking
> > about the solution.
> >
> > Compare:
> >
> > Scala:
> >
> > *case class Person(var name : String)*
> >
> > Java:
> >
> > *public class Person
> > {
> >     public Person(String name)
> >     {
> >         super();
> >         this.name = name;
> >     }
> >
> >     private String name;
> >
> >     public String getName()
> >     {
> >         return name;
> >     }
> >
> >     public void setName(String name)
> >     {
> >         this.name = name;
> >     }
> >
> >     @Override
> >     public int hashCode()
> >     {
> >         final int prime = 31;
> >         int result = 1;
> >         result = prime * result + ((name == null) ? 0 : name.hashCode());
> >         return result;
> >     }
> >
> >     @Override
> >     public boolean equals(Object obj)
> >     {
> >         if (this == obj)
> >             return true;
> >         if (obj == null)
> >             return false;
> >         if (getClass() != obj.getClass())
> >             return false;
> >         Person other = (Person) obj;
> >         if (name == null)
> >         {
> >             if (other.name != null)
> >                 return false;
> >         }
> >         else if (!name.equals(other.name))
> >             return false;
> >         return true;
> >     }}
> >
> > *
> >
> > While the above is just a trivial example, it would think it accentuates
> my
> > point.
> >
> > I spent a couple of hours the day before yesterday rewriting an event
> > dispatch API in Java, trying to expose the most clean consumer interface
> as
> > possible, and I really felt I had to jump through hoops in order to be
> able
> > to do just that. But when written in Scala, not only was the resulting
> API
> > code about 30% of the LoC, but it also exposed a _cleaner_ interface.
> >
> > That's when the question to write libraries in Scala to be consumed by
> Java
> > application code.
> > Hence this thread.
> >
> > Viktor
> >
> >
> >
> >
> >
> > > Alexey
> >
> > > --- On Tue, 5/5/09, Dave Watson <davidgrillwat...@gmail.com> wrote:
> >
> > > > From: Dave Watson <davidgrillwat...@gmail.com>
> > > > Subject: [The Java Posse] Re: Java as API language, its days
> numbered?
> > > > To: "The Java Posse" <javaposse@googlegroups.com>
> > > > Date: Tuesday, May 5, 2009, 9:10 PM
> > > > What does this mean, exactly? Can you elaborate more about
> > > > the 85% of
> > > > your code that is boilerplate?
> >
> > > > Not trying to argue, I'm just very puzzled by what this
> > > > might mean....
> >
> > > > On May 5, 5:27 pm, Viktor Klang
> > > > <viktor.kl...@gmail.com> wrote:
> > > > > Greetings posse,
> >
> > > > > having spent more than half a decade writing API:s in
> > > > Java I feel that since
> > > > > Java 5 was introduced, more and more time has to be
> > > > spent writing
> > > > > boilerplate API code to try to save the API consumers
> > > > from jumping through
> > > > > hoops in order to get stuff done. Because we all want
> > > > easily consumable
> > > > > libraries, don't we?
> >
> > > > > Having jumped onto the Scala bandwagon about 1½ years
> > > > ago I feel like the
> > > > > ratio of business end code of Java is appro 15% while
> > > > in Scala it's more
> > > > > like 65%
> >
> > > > > <observation>You can most likely substitute
> > > > "Scala" in the text below with
> > > > > any non-Java JVM language</observation>
> >
> > > > > With Scala getting more and more cleaner to be
> > > > consumed by Java code, isn't
> > > > > there plenty of good reasons to switch to Scala for
> > > > library code, while
> > > > > letting the application developers stay i Java-land?
> >
> > > > > --
> > > > > Viktor Klang
> > > > > Known from the Internet
> >
> > --
> > Viktor Klang
> > Senior Systems Analyst
> >
>


-- 
Viktor Klang
Senior Systems Analyst

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javaposse@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