This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Scala - Teaching O-O

Yann Régis-Gianas, lecturer/assistant professor at the University of Paris Diderot - Paris 7, has chosen Scala and the Simply Scala web site to help him teach the Advanced Object Oriented course this fall. Here he explains why.

The aim, he says, is to guide students to a deeper understanding of the object-oriented paradigm. He explains that Scala offers modern answers to many of the underlying issues, the problems of decomposition, modularity and correctness, for example. Scala features allow students to practically explore both the object oriented and functional approaches to problems.

The teaching challenge is to present the concepts in such a way that the student gets a real feel for the O-O benefits, the trade-offs and what are the key questions to ask.

  • How does an object oriented programmer decompose problems? What is this thinking process good for? What are its limits/drawbacks?
  • Why is the modular object oriented approach famous for its scalability? What are the pros and cons of class-based programming with respect to modularity? What are the design patterns and modern programming mechanisms that help working around these problems? How to write reusable generic components?
  • How do you move from safety to functional correctness? How to get static guarantees about O-O components? What does a modern type system prove? How to write a hoare-like specification that is suited for OO programs? How to prove or, at least dynamically check, them?

It is important that students can test their understanding quickly without wasting time on setting up their PC with a complete IDE. Simply Scala provides a nice solution, not only allowing the students to create and run small Scala programs directly from a browser but also providing a Scala tutorial and reference. A nice way to learn Scala, but the majority of his course participants are French speaking so Yann joined forces with Anthony Bagwell, the Simply Scala site creator to provide a French version of the on-line Scala tutorial.

He says it is not long before students understand the basic concepts and are ready to use Scala's advanced features to appreciate the benefits of functional decomposition, bounded polymorphism and a rich type system.

  • They quickly grasp when the OO approach is not as relevant and see when a functional decomposition would be better to deal with a specific problem. In Scala the program can be express as a function composition. The students soon become aware of the benefits of referential transparency. Scala's distinction between 'val' and 'var' is a first step in that direction.
  • The mixin composition mechanism as well as the higher-order bounded polymorphism of Scala are a must-know to write modular reusable components. Yann says that the fact that most of the standard design patterns are made redundant in Scala is probably an excellent indicator that it is a good replacement candidate for Java.
  • Scala's rich type system is strong enough to embed GADTs, some form of dependently typed programming and type classes and provides a great laboratory for students to experiment with type-level encoding of functional properties. Furthermore, there are some neat unit testing frameworks in Scala. Not only are they good to know and but also allow behaviour driven development to be explored.

Yann says that "Scala provides a excellent teaching language for object orientated concepts and Simply Scala a great place for students to get started, and all in French too!"

Re: Scala - Teaching O-O

Its a very good decision to go for Scala as a teaching language even for the OOP class. I think that mixture of OOP and Functional features will be of great help to grab both concepts at the same time using a programming language that implements both paradigms so well. 


I have posted 2 Scala examples using OOP in my blog.
The first one is a simple OO Hello World:
carlosqt.blogspot.com/2010/07/oo-hello-world-scala.html

and the second one is a more elaborated program which intend to show the OO Basics of the Language:
carlosqt.blogspot.com/2010/10/scala-basics-by-example.html

using the following structure:  

  •  Class  
  •    Fields or Attributes  
  •    Properties  
  •    Constructor  
  •    Overloaded Constructor  
  •    Method 1  
  •    "if-then-else" statement  
  •    Method 2  
  •    "for" statement  
  •    Overloaded Method 2.1  
  •    "while" statement  
  •    Overloaded Method 2.2  
  •    "match" statement  
  •  
  •  Console Program  
  •    Define object of type Greet  
  •    Instantiate Greet. Call Constructor  
  •    Call Set Properties  
  •    Call Method 2  
  •    Call Method 2.1 and Get Properties  
  •    Call Method 2.2  
  •    Stop and exit


Same stuff for F# if you/your students want to compare:
carlosqt.blogspot.com/2010/06/oo-hello-world-f.html
carlosqt.blogspot.com/2010/10/f-basics-by-example.html

 

And the same for other 18 languages targeting the .NET and JavaVM that support OOP and Functional paradigms which could be of interest for your students :)

 

Re: Scala - Teaching O-O

Hi !

 

I am also teaching programming (at the University of Applied Science Western Switzerland) and we will offer an advanced programming course next year with Scala as programming language. This course will discuss not only functional programming but how a multi-paradigm language such as Scala can offer several advantages for real-world applications.

As I am teaching both in french and german, I just wanted to thank you for the work on the translation of the Simply Scala site, which will be helpful for the students !

Cheers,

Pierre-André Mudry

 

 

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland