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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Musser, D.R., Stepanov, A.A.: Generic programming. In: Gianni, P. (ed.) ISSAC 1988. LNCS, vol. 358, pp. 13–25. Springer, Heidelberg (1989)
Dos Reis, G., Järvi, J.: What is generic programming? In: Proc. of LCSD (2005)
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)
Stroustrup, B.: The C++ Programming Language, 3rd edn. Addison Wesley (1997)
Microsoft: Generics (C# Programming Guide) (2005), http://msdn.microsoft.com/en-us/library/512aeb7tVS.80.aspx
Oliveira, B.C., Gibbons, J.: Scala for generic programmers. In: WGP, pp. 25–36. ACM (2008)
Meyer, B.: Genericity versus Inheritance. In: OOPSLA, pp. 391–405. ACM (1986)
Austern, M.H.: Generic Programming and the STL: using and extending the C++ Standard Template Library. Addison-Wesley (1998)
Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley (1995)
Fowler, M.: Inversion of Control Containers and the Dependency Injection pattern (2004), http://www.martinfowler.com/articles/injection.html
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)
Cohen, T., Gil, J.: Better Construction with Factories. JOT 6, 103–123 (2007)
Bergel, A., Bettini, L.: Reverse Generics: Parametrization after the Fact. In: Software and Data Technologies. CCIS, vol. 50, pp. 107–123. Springer, Heidelberg (2011)
Axelsen, E.W., Krogdahl, S.: Groovy package templates: supporting reuse and runtime adaption of class hierarchies. In: DLS, pp. 15–26. ACM (2009)
Bergel, A., Bettini, L.: Generics and Reverse Generics for Pharo. In: ICSOFT, pp. 363–372. SciTePress (2012)
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)
Flatt, M., Felleisen, M.: Units: Cool Modules for HOT Languages. In: PLDI, pp. 236–248. ACM (1998)
Bergel, A., Ducasse, S., Nierstrasz, O.: Classbox/J: Controlling the Scope of Change in Java. In: OOPSLA, pp. 177–189. ACM (2005)
Goldberg, A., Robson, D.: Smalltalk 80: the Language and its Implementation. Addison-Wesley (1983)
Lienhard, A.: Bootstrapping Traits. Master’s thesis, University of Bern (2004)
Odersky, M., Wadler, P.: Pizza into Java: Translating theory into practice. In: POPL, pp. 146–159. ACM (1997)
Ghosh, D.: Generics in Java and C++: a comparative model. ACM SIGPLAN Notices 39, 40–47 (2004)
Batov, V.: Java generics and C++ templates. C/C++ Users Journal 22, 16–21 (2004)
Eisenecker, U.W., Czarnecki, K.: Generative Programming: Methods, Tools, and Applications. Addison-Wesley (2000)
Abrahams, D., Gurtovoy, A.: C++ Template Metaprogramming: Concepts, Tools and Techniques from Boost and Beyond. Addison-Wesley (2004)
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)
Duggan, D.: Modular type-based reverse engineering of parameterized types in Java code. In: OOPSLA, pp. 97–113. ACM (1999)
von Dincklage, D., Diwan, A.: Converting Java classes to use generics. In: OOPSLA, pp. 1–14. ACM (2004)
Kiezun, A., Ernst, M.D., Tip, F., Fuhrer, R.M.: Refactoring for Parameterizing Java Classes. In: ICSE, pp. 437–446. IEEE (2007)
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)
Moors, A., Piessens, F., Odersky, M.: Generics of a higher kind. In: OOPSLA, pp. 423–438. ACM (2008)
Odersky, M., Spoon, L., Venners, B.: Programming in Scala. Artima (2008)
Sørensen, F., Axelsen, E.W., Krogdahl, S.: Reuse and combination with package templates. In: MASPEGHI, pp. 1–5. ACM (2010)
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)
Reppy, J., Turon, A.: Metaprogramming with Traits. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 373–398. Springer, Heidelberg (2007)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)