Java Generics AdoptionHow New Features are Introduced, Championed, or IgnoredChris Parnin    Georgia TechChristian BirdMicrosoft ResearchEmerson Murphy-HillNorth Carolina State
Quick refresherRaw Type RList myList= …;String aStringFromMyList = (String)myList.get(0);class List{  Object get(int i){…}}Cast (C)
Quick refresherList myList = …;String aStringFromMyList = (String)myList.get(0);class List<T>{  T get(int i){…}}Generic Type <T>
Quick refresherParameterized Type <P>List<String> myList= …;String aStringFromMyList =         myList.get(0);class List<T>{  T get(int i){…}}static <T> T head(List<T> l){	return l.get(0);};Generic Method <M>
but life is not so simple…
public interface Identifiable<T extends Identifier<? extends What>, What> {    public TgetObjectID();    public Class<? super What> type();}public interface Identifier<T> {    public long getID();    public Class<? super T> type();}interface X <SubjectType extends Identifiable, RelationshipType extendsEnum<RelationshipType> & Related, ObjectType extends Identifiable>{} static class A<    SI extends Identifier<? extends SubjectType>,    OI extends Identifier<? extends ObjectType>,SubjectType extends Identifiable<SI, SubjectType>,RelationshipType extends Enum<RelationshipType> & Related,ObjectType extends Identifiable<? extends OI, ? extends ObjectType>>    implements    X<SubjectType, RelationshipType, ObjectType> {}
public interface Identifiable<T extends Identifier<? extends What>, What> {    public TgetObjectID();    public Class<? super What> type();}public interface Identifier<T> {    public long getID();    public Class<? super T> type();}interface X <SubjectType extends Identifiable, RelationshipType extendsEnum<RelationshipType> & Related, ObjectType extends Identifiable>{} static class A<    SI extends Identifier<? extends SubjectType>,    OI extends Identifier<? extends ObjectType>,SubjectType extends Identifiable<SI, SubjectType>,RelationshipType extends Enum<RelationshipType> & Related,ObjectType extends Identifiable<? extends OI, ? extends ObjectType>>    implements    X<SubjectType, RelationshipType, ObjectType> {}“As I sit and stare in stunned horror at this monster”"Writing generified classes is rocket science"“Probably more time and brainpower was spent fussing with generics than any other single thing”
why are these people so angry?As a community, we often don’t formally evaluate our claims after we put them out into the world.
Outcome?GoslingIdeaGuy Steele DebateJava 5Implement and ReleaseDeveloper Usage1994199820042011
To investigate what happened to generics, let’s look at the claims and complaints madeabout generics
“I suspect we will see a lot of Java 5 code that continues to do things the bad old way as a result and contend with the mish-mash that results” (2005) – lambda the ultimateDid programmers adopt and use generics?
“There seems to be some debateover refactoring to utilize java generics within my current team … a holy war going on about what should and should not be done …” – stackoverflowDid programmers adopt and use generics?Will teammates all agree to use generics?
“Do you want to go back to casting-from-Object in every container access and dealing with the resulting runtime-revealed type errors?” – stackoverflowClassCastExceptionsare rarely seen in bug reports!Caught with local testing before check-ins, etc…Did programmers adopt and use generics?Will teammates all agree to use generics?Does generics reduce runtime errors?Does generics reduce casts?
RQ 1 AdoptionRQ 2CoordinationRQ 3CastsDid programmers adopt and use generics?Will teammates all agree to use generics?Does generics reduce casts?
Study SetupRQ 1 AdoptionRQ 2CoordinationRQ 3CastsLifetime of 20 open-source projects: Before and After generics.<P><M>(C)<T>R500 million LOCEntities of Interest Per CommitDatabase for Analysis
532 developer’s generic usage?RQ 1 AdoptionWe use generic collections!RQ 2CoordinationRQ 3CastsWe use generics methods or classes!No generics!
Developers with higher commit frequency?RQ 1 AdoptionHigher ratio of generics collection usage (42%)RQ 2CoordinationRQ 3CastsBut generic methods or classes stay about the same.
RQ 1 AdoptionRQ 2CoordinationRQ 3CastsNever used generics
RQ 1 AdoptionRQ 2CoordinationRQ 3CastsAnother programmer starts contributing…Then a champion emerges!Then others follow.The champion even migrates old code.
RQ 1 AdoptionRQ 2CoordinationjEditRQ 3CastsCasts (normalized) should decrease with generics.(C)We found no correlationfor jEdit<P>
RQ 1 AdoptionRQ 2CoordinationjEditRQ 3CastsSquirrel-SQLCasts reduced before developers start to introduce generics.(C)(C)<P>We found a strong correlationfor Squirrel-SQL<P>
RQ 1 AdoptionRQ 2CoordinationRQ 3CastsBut, overall, only Squirrel-SQL had a strong correlation, and 6 with moderate correlation.
Other findingsVery little refactoring to generics (typically under 10%)Half of generics instantiated with just one typeGenerics support modest reductions in duplication90% of generic usage is java.util collectionsIDE support has little relation to generic adoption dateGeneric methods are rare!
A MetaphorRegulates DrugsRegulates Programming FeaturesMonitors Adverse ReactionsMonitors Allergic ReactionsMeasures treatment effectivenessMeasures impact and migration costs

Java Generics Adoption: How New Features are Introduced Championed or Ignored

  • 1.
    Java Generics AdoptionHowNew Features are Introduced, Championed, or IgnoredChris Parnin Georgia TechChristian BirdMicrosoft ResearchEmerson Murphy-HillNorth Carolina State
  • 2.
    Quick refresherRaw TypeRList myList= …;String aStringFromMyList = (String)myList.get(0);class List{ Object get(int i){…}}Cast (C)
  • 3.
    Quick refresherList myList= …;String aStringFromMyList = (String)myList.get(0);class List<T>{ T get(int i){…}}Generic Type <T>
  • 4.
    Quick refresherParameterized Type<P>List<String> myList= …;String aStringFromMyList = myList.get(0);class List<T>{ T get(int i){…}}static <T> T head(List<T> l){ return l.get(0);};Generic Method <M>
  • 5.
    but life isnot so simple…
  • 6.
    public interface Identifiable<Textends Identifier<? extends What>, What> { public TgetObjectID(); public Class<? super What> type();}public interface Identifier<T> { public long getID(); public Class<? super T> type();}interface X <SubjectType extends Identifiable, RelationshipType extendsEnum<RelationshipType> & Related, ObjectType extends Identifiable>{} static class A< SI extends Identifier<? extends SubjectType>, OI extends Identifier<? extends ObjectType>,SubjectType extends Identifiable<SI, SubjectType>,RelationshipType extends Enum<RelationshipType> & Related,ObjectType extends Identifiable<? extends OI, ? extends ObjectType>> implements X<SubjectType, RelationshipType, ObjectType> {}
  • 7.
    public interface Identifiable<Textends Identifier<? extends What>, What> { public TgetObjectID(); public Class<? super What> type();}public interface Identifier<T> { public long getID(); public Class<? super T> type();}interface X <SubjectType extends Identifiable, RelationshipType extendsEnum<RelationshipType> & Related, ObjectType extends Identifiable>{} static class A< SI extends Identifier<? extends SubjectType>, OI extends Identifier<? extends ObjectType>,SubjectType extends Identifiable<SI, SubjectType>,RelationshipType extends Enum<RelationshipType> & Related,ObjectType extends Identifiable<? extends OI, ? extends ObjectType>> implements X<SubjectType, RelationshipType, ObjectType> {}“As I sit and stare in stunned horror at this monster”"Writing generified classes is rocket science"“Probably more time and brainpower was spent fussing with generics than any other single thing”
  • 8.
    why are thesepeople so angry?As a community, we often don’t formally evaluate our claims after we put them out into the world.
  • 9.
    Outcome?GoslingIdeaGuy Steele DebateJava5Implement and ReleaseDeveloper Usage1994199820042011
  • 10.
    To investigate whathappened to generics, let’s look at the claims and complaints madeabout generics
  • 11.
    “I suspect wewill see a lot of Java 5 code that continues to do things the bad old way as a result and contend with the mish-mash that results” (2005) – lambda the ultimateDid programmers adopt and use generics?
  • 12.
    “There seems tobe some debateover refactoring to utilize java generics within my current team … a holy war going on about what should and should not be done …” – stackoverflowDid programmers adopt and use generics?Will teammates all agree to use generics?
  • 13.
    “Do you want to goback to casting-from-Object in every container access and dealing with the resulting runtime-revealed type errors?” – stackoverflowClassCastExceptionsare rarely seen in bug reports!Caught with local testing before check-ins, etc…Did programmers adopt and use generics?Will teammates all agree to use generics?Does generics reduce runtime errors?Does generics reduce casts?
  • 14.
    RQ 1 AdoptionRQ2CoordinationRQ 3CastsDid programmers adopt and use generics?Will teammates all agree to use generics?Does generics reduce casts?
  • 15.
    Study SetupRQ 1AdoptionRQ 2CoordinationRQ 3CastsLifetime of 20 open-source projects: Before and After generics.<P><M>(C)<T>R500 million LOCEntities of Interest Per CommitDatabase for Analysis
  • 16.
    532 developer’s genericusage?RQ 1 AdoptionWe use generic collections!RQ 2CoordinationRQ 3CastsWe use generics methods or classes!No generics!
  • 17.
    Developers with highercommit frequency?RQ 1 AdoptionHigher ratio of generics collection usage (42%)RQ 2CoordinationRQ 3CastsBut generic methods or classes stay about the same.
  • 18.
    RQ 1 AdoptionRQ2CoordinationRQ 3CastsNever used generics
  • 19.
    RQ 1 AdoptionRQ2CoordinationRQ 3CastsAnother programmer starts contributing…Then a champion emerges!Then others follow.The champion even migrates old code.
  • 20.
    RQ 1 AdoptionRQ2CoordinationjEditRQ 3CastsCasts (normalized) should decrease with generics.(C)We found no correlationfor jEdit<P>
  • 21.
    RQ 1 AdoptionRQ2CoordinationjEditRQ 3CastsSquirrel-SQLCasts reduced before developers start to introduce generics.(C)(C)<P>We found a strong correlationfor Squirrel-SQL<P>
  • 22.
    RQ 1 AdoptionRQ2CoordinationRQ 3CastsBut, overall, only Squirrel-SQL had a strong correlation, and 6 with moderate correlation.
  • 23.
    Other findingsVery littlerefactoring to generics (typically under 10%)Half of generics instantiated with just one typeGenerics support modest reductions in duplication90% of generic usage is java.util collectionsIDE support has little relation to generic adoption dateGeneric methods are rare!
  • 24.
    A MetaphorRegulates DrugsRegulatesProgramming FeaturesMonitors Adverse ReactionsMonitors Allergic ReactionsMeasures treatment effectivenessMeasures impact and migration costs

Editor's Notes

  • #3 Casts: ugly and runtime exception
  • #5 TODO: move “myList” decl so transition smoother
  • #9 So what happened with generics? To find out why, let’s start at the beginnning…
  • #10 So to investigate what happened to generics, let’s look at the claims and complaints made about generics
  • #11 TODO mention why we think they’re true (repeatedly!)
  • #16 Emphasize historical lookSimplify process diagram
  • #18 Zoom size of each person for contribution amount.Put research question on topFor each question, remind what answer is
  • #20 Some developers stubbornly used “raw” types despite adoption by others in the same project, whereas, in many projects that did use generics, there was a single developer who “championed” the use of generics, by using generics much earlier and in larger amounts than other developers.
  • #21 Casts reduced before developers start to introduce generics.Spearman rank correlation:Only squirrel-sql had a strong correlation6 with moderate correlation.Gradual reveal, starting with one project, starting with 1 lineChange colors to be consistentMention normalization partBe sure to point out parts of graph that support what you say
  • #22 Casts reduced before developers start to introduce generics.Spearman rank correlation:Only squirrel-sql had a strong correlation6 with moderate correlation.Gradual reveal, starting with one project, starting with 1 lineChange colors to be consistentMention normalization partBe sure to point out parts of graph that support what you say
  • #24 Prematuregenerification.
  • #25 Clean up, make as conclusion slide