Skip to main content

Generic Programming in Pharo

  • Conference paper
Software and Data Technologies (ICSOFT 2012)

Part of the book series: Communications in Computer and Information Science ((CCIS,volume 411))

Included in the following conference series:

Abstract

Dynamically typed object-oriented languages have been left out of the scope of generic programming: in a dynamically typed setting, the need for generic programming has been less prominent since no restriction applies over the kind of elements a collection may contain. However, when creating an object, the class name is hardcoded in the program, and this makes the object instantiation process hard to abstract from.

In this paper, we describe our implementation of generic programming in Pharo, a Smalltalk dialect, showing how programmers can benefit from generic programming even in a dynamically typed language. Furthermore, we enhance the expressiveness of generic programming with reverse generics, a mechanism for automatically deriving new generic code starting from existing non-generic one.

As a case study, we show how we used generics and reverse generics in Pharo to reuse unit test cases and to identify a number of bugs and anomalies in the stream class hierarchy.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Musser, D.R., Stepanov, A.A.: Generic programming. In: Gianni, P. (ed.) ISSAC 1988. LNCS, vol. 358, pp. 13–25. Springer, Heidelberg (1989)

    Chapter  Google Scholar 

  2. Dos Reis, G., Järvi, J.: What is generic programming? In: Proc. of LCSD (2005)

    Google Scholar 

  3. Bracha, G., Odersky, M., Stoutamire, D., Wadler, P.: Making the future safe for the past: adding genericity to the Java programming language. In: OOPSLA, pp. 183–200. ACM (1998)

    Google Scholar 

  4. Stroustrup, B.: The C++ Programming Language, 3rd edn. Addison Wesley (1997)

    Google Scholar 

  5. Microsoft: Generics (C# Programming Guide) (2005), http://msdn.microsoft.com/en-us/library/512aeb7tVS.80.aspx

  6. Oliveira, B.C., Gibbons, J.: Scala for generic programmers. In: WGP, pp. 25–36. ACM (2008)

    Google Scholar 

  7. Meyer, B.: Genericity versus Inheritance. In: OOPSLA, pp. 391–405. ACM (1986)

    Google Scholar 

  8. Austern, M.H.: Generic Programming and the STL: using and extending the C++ Standard Template Library. Addison-Wesley (1998)

    Google Scholar 

  9. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley (1995)

    Google Scholar 

  10. Fowler, M.: Inversion of Control Containers and the Dependency Injection pattern (2004), http://www.martinfowler.com/articles/injection.html

  11. Bracha, G., von der Ahé, P., Bykov, V., Kashai, Y., Maddox, W., Miranda, E.: Modules as Objects in Newspeak. In: D’Hondt, T. (ed.) ECOOP 2010. LNCS, vol. 6183, pp. 405–428. Springer, Heidelberg (2010)

    Chapter  Google Scholar 

  12. Cohen, T., Gil, J.: Better Construction with Factories. JOT 6, 103–123 (2007)

    Article  Google Scholar 

  13. Bergel, A., Bettini, L.: Reverse Generics: Parametrization after the Fact. In: Software and Data Technologies. CCIS, vol. 50, pp. 107–123. Springer, Heidelberg (2011)

    Chapter  Google Scholar 

  14. Axelsen, E.W., Krogdahl, S.: Groovy package templates: supporting reuse and runtime adaption of class hierarchies. In: DLS, pp. 15–26. ACM (2009)

    Google Scholar 

  15. Bergel, A., Bettini, L.: Generics and Reverse Generics for Pharo. In: ICSOFT, pp. 363–372. SciTePress (2012)

    Google Scholar 

  16. Ducasse, S., Pollet, D., Bergel, A., Cassou, D.: Reusing and Composing Tests with Traits. In: Oriol, M., Meyer, B. (eds.) TOOLS EUROPE 2009. LNCS, vol. 33, pp. 252–271. Springer, Heidelberg (1975)

    Google Scholar 

  17. Flatt, M., Felleisen, M.: Units: Cool Modules for HOT Languages. In: PLDI, pp. 236–248. ACM (1998)

    Google Scholar 

  18. Bergel, A., Ducasse, S., Nierstrasz, O.: Classbox/J: Controlling the Scope of Change in Java. In: OOPSLA, pp. 177–189. ACM (2005)

    Google Scholar 

  19. Goldberg, A., Robson, D.: Smalltalk 80: the Language and its Implementation. Addison-Wesley (1983)

    Google Scholar 

  20. Lienhard, A.: Bootstrapping Traits. Master’s thesis, University of Bern (2004)

    Google Scholar 

  21. Odersky, M., Wadler, P.: Pizza into Java: Translating theory into practice. In: POPL, pp. 146–159. ACM (1997)

    Google Scholar 

  22. Ghosh, D.: Generics in Java and C++: a comparative model. ACM SIGPLAN Notices 39, 40–47 (2004)

    Article  Google Scholar 

  23. Batov, V.: Java generics and C++ templates. C/C++ Users Journal 22, 16–21 (2004)

    Google Scholar 

  24. Eisenecker, U.W., Czarnecki, K.: Generative Programming: Methods, Tools, and Applications. Addison-Wesley (2000)

    Google Scholar 

  25. Abrahams, D., Gurtovoy, A.: C++ Template Metaprogramming: Concepts, Tools and Techniques from Boost and Beyond. Addison-Wesley (2004)

    Google Scholar 

  26. Kapur, D., Musser, D.R., Stepanov, A.A.: Tecton: A Language for Manipulating Generic Objects. In: Staunstrup, J. (ed.) Program Specification 1981. LNCS, vol. 134, pp. 402–414. Springer, Heidelberg (1982)

    Chapter  Google Scholar 

  27. Duggan, D.: Modular type-based reverse engineering of parameterized types in Java code. In: OOPSLA, pp. 97–113. ACM (1999)

    Google Scholar 

  28. von Dincklage, D., Diwan, A.: Converting Java classes to use generics. In: OOPSLA, pp. 1–14. ACM (2004)

    Google Scholar 

  29. Kiezun, A., Ernst, M.D., Tip, F., Fuhrer, R.M.: Refactoring for Parameterizing Java Classes. In: ICSE, pp. 437–446. IEEE (2007)

    Google Scholar 

  30. Weiss, R., Simonis, V.: Exploring template template parameters. In: Bjørner, D., Broy, M., Zamulin, A.V. (eds.) PSI 2001. LNCS, vol. 2244, pp. 500–510. Springer, Heidelberg (2001)

    Chapter  Google Scholar 

  31. Moors, A., Piessens, F., Odersky, M.: Generics of a higher kind. In: OOPSLA, pp. 423–438. ACM (2008)

    Google Scholar 

  32. Odersky, M., Spoon, L., Venners, B.: Programming in Scala. Artima (2008)

    Google Scholar 

  33. Sørensen, F., Axelsen, E.W., Krogdahl, S.: Reuse and combination with package templates. In: MASPEGHI, pp. 1–5. ACM (2010)

    Google Scholar 

  34. Ducasse, S., Nierstrasz, O., Schärli, N., Wuyts, R., Black, A.P.: Traits: A Mechanism for fine-grained Reuse. ACM TOPLAS 28, 331–388 (2006)

    Article  Google Scholar 

  35. Reppy, J., Turon, A.: Metaprogramming with Traits. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 373–398. Springer, Heidelberg (2007)

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2013 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Bergel, A., Bettini, L. (2013). Generic Programming in Pharo. In: Cordeiro, J., Hammoudi, S., van Sinderen, M. (eds) Software and Data Technologies. ICSOFT 2012. Communications in Computer and Information Science, vol 411. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-45404-2_5

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-45404-2_5

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-45403-5

  • Online ISBN: 978-3-642-45404-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics