This document summarizes research into how Java developers adopted and used generics after they were introduced in Java 5. The study analyzed over 500 million lines of code from 20 open-source projects before and after generics. It found that adoption was gradual, usually starting with one champion developer introducing generics and then others following. Coordination between developers on using generics was sometimes an issue. The study also analyzed whether generics reduced class casts and only found a strong correlation for one project, with a few others showing moderate reductions. Other findings included little refactoring to generics, most generics using a single type, and 90% of usage being Java collection classes.
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
Java Generics Adoption: A Longitudinal Study of How New Language Features Are Championed and Adopted Over Time
1. Java Generics Adoption How New Features are Introduced, Championed, or Ignored Chris Parnin Georgia Tech Christian Bird Microsoft Research Emerson Murphy-Hill North Carolina State
2. Quick refresher Raw Type R List myList= …; String aStringFromMyList = (String)myList.get(0); class List{ Object get(int i){…} } Cast (C)
3. Quick refresher List myList = …; String aStringFromMyList = (String)myList.get(0); class List<T>{ T get(int i){…} } Generic Type <T>
4. Quick refresher Parameterized 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>
6. 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 extends Enum<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<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 extends Enum<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 these people so angry? As a community, we often don’t formally evaluate our claims after we put them out into the world.
9. Outcome ? Gosling Idea Guy Steele Debate Java 5 Implement and Release Developer Usage 1994 1998 2004 2011
10. To investigate what happened to generics, let’s look at the claims and complaints made about generics
11. “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 ultimate Did programmers adopt and use generics?
12. “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 …” – stackoverflow Did programmers adopt and use generics? Will teammates all agree to use generics?
13. “Do you want to go back to casting-from-Object in every container access and dealing with the resulting runtime-revealed type errors?” – stackoverflow ClassCastExceptionsare 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 Adoption RQ 2 Coordination RQ 3 Casts Did programmers adopt and use generics? Will teammates all agree to use generics? Does generics reduce casts?
15. Study Setup RQ 1 Adoption RQ 2 Coordination RQ 3 Casts Lifetime of 20 open-source projects: Before and After generics. <P><M>(C)<T>R 500 million LOC Entities of Interest Per Commit Database for Analysis
16. 532 developer’s generic usage? RQ 1 Adoption We use generic collections! RQ 2 Coordination RQ 3 Casts We use generics methods or classes! No generics!
17. Developers with higher commit frequency? RQ 1 Adoption Higher ratio of generics collection usage (42%) RQ 2 Coordination RQ 3 Casts But generic methods or classes stay about the same.
18. RQ 1 Adoption RQ 2 Coordination RQ 3 Casts Never used generics
19. RQ 1 Adoption RQ 2 Coordination RQ 3 Casts Another programmer starts contributing… Then a champion emerges! Then others follow. The champion even migrates old code.
20. RQ 1 Adoption RQ 2 Coordination jEdit RQ 3 Casts Casts (normalized) should decrease with generics. (C) We found no correlationfor jEdit <P>
21. RQ 1 Adoption RQ 2 Coordination jEdit RQ 3 Casts Squirrel-SQL Casts reduced before developers start to introduce generics. (C) (C) <P> We found a strong correlationfor Squirrel-SQL <P>
22. RQ 1 Adoption RQ 2 Coordination RQ 3 Casts But, overall, only Squirrel-SQL had a strong correlation, and 6 with moderate correlation.
23. Other findings Very little refactoring to generics (typically under 10%) Half of generics instantiated with just one type Generics support modest reductions in duplication 90% of generic usage is java.util collections IDE support has little relation to generic adoption date Generic methods are rare!
24. A Metaphor Regulates Drugs Regulates Programming Features Monitors Adverse Reactions Monitors Allergic Reactions Measures treatment effectiveness Measures impact and migration costs
Notas do Editor
Casts: ugly and runtime exception
TODO: move “myList” decl so transition smoother
So what happened with generics? To find out why, let’s start at the beginnning…
So to investigate what happened to generics, let’s look at the claims and complaints made about generics
TODO mention why we think they’re true (repeatedly!)
Emphasize historical lookSimplify process diagram
Zoom size of each person for contribution amount.Put research question on topFor each question, remind what answer is
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.
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
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