Teaching notes:

 

Programming Concepts and Methods for Enhanced Student Learning

 

 

Tong-Chun Xu

The King's University College

9125 - 50 Street

Edmonton, Alberta, Canada

T6B 2H3

(780) 465-8326

FAX:  (780) 465-3534

tong.xu@kingsu.ab.ca

http://www.kingsu.ca

 

Abstract

 

Several important computing concepts and methodology, especially those pertaining to programming languages, are not sufficiently delivered in many current computing science texts. This paper examines some specific concepts and methods of teaching that could strengthen the ability of students to use programming languages.

 

1.        A student’s understanding of the evolution of programming languages is greatly enhanced by showing the correlation between technological advancements and the emergence of certain programming languages.

 

2.        The use of UML allows students to visually present outcomes of OO analysis and plan the process of code implementation in a well-organized manner. In addition, proficiency in writing language programs from UML and creating UML diagrams from language programs improves students’ understanding of programming methodology.

 

3.        Aliasing is the use of several different identifiers to refer one object and sometimes is considered to be a problematic feature in programming language analysis and practice. In many current texts, aliasing is explained only in association with C, C++, and Java. However, aliasing also occurs in Lisp (among other languages) and has unfamiliar consequences. In C#, aliasing not only occurs in references but also in namespace. Negative and positive aspects of aliasing in programming languages are reviewed.

 

 

Key words

 

Dynamically Linked Library  (DLL), object-oriented (OO) designs/analysis/programming, aliasing, chips, forward/reversed engineering, Integrated Circuit, Nanochips, transistor, Unified Modelling Language (UML)

 

1.             Effects of Technological Advances on the Development of Programming Languages

 

The sophistication of programming languages is dependent on the technology available (see Fig. 1). During the First Generation of modern computers (1945-1956), vacuum tubes and magnetic drums limited communication between computers to operating instructions, resulting in only machine languages being available. The introduction of transistors in the Second Generation allowed computers to become relatively more compact and efficient. It also provided the means for the development of FORTAN, ALGL, LISP and SNOBOL. The Third Generation saw the introduction of integrated circuits, which promised and delivered computers with much more memory and computing capacity. This lead to the emergence of a new concept: data abstraction. Jack Kilby’s development of the integrated circuit (for which he won the Nobel Prize in 2000) made operating systems possible. The replacement of integrated circuits with small computer chips in 1971 lifted previous restrictions on memory and speed. Computing programs were increasingly larger and more complex. This lead to the need for saving existing work. Thus, object-oriented programming (OOP) languages, e.g. C++ and Java, were developed. Inheritance enables software reusability, which saves time in development and encourages using previously proven high-quality software components. Based on molecular scale technology, nanochips mass storage devices of higher density, greater speed and lower cost than any currently available. This may have significant impact on the languages used in information technology (IT), such as wireless/optical Multimedia Communications.

 

 

2.             Implementation of Design in UML

 

SIMULA 67, the first language providing limited support for data abstraction, was the root of the object-oriented programming (OOP) languages. Unified Modelling Language (UML) is a system of communication among software developers and is implemented in programming languages. The natural steps in an OOP is:

 

1.        examine the problem statements and objects

2.        identify corresponding classes for all objects

3.        identify attributes, analyse possible states and activities, operations, and collaboration among objects

4.        present the outcomes by  UML so implementation can begin

 

A good example showing how these natural steps are carried out is found in the Object-Oriented Elevator Simulator (Deitel and Deitel, 1998, 2002, and 2003). As a teaching resource, Deitel and Deitel (2003) have recently removed an intangible class (ElevatorModel) in the case study “Elevator Simulation”, making the case directly receivable through the senses.

 

The proficiency in using UML to present design and document programs, as well as implementing UML are very important parts of the OO programming. Appropriate examples/exercises in teaching students how to combine existing components instead of starting from the very beginning to make new products are badly needed. 

 

The following example in Java is designed for use as an assignment or part of an exam. The purpose of this assignment is to

 

1.        Enhance proficiency in implementing UML (forward engineering), and

2.        examine some concepts such as aggregation, composition, and static variables. 

3.        transform the perceptual stage of cognition into rational knowledge

 

A Combination of Four (see Fig. 2, http://turing.kingsu.ca/~tong/WCCCE/aggregation1/)

 

The definitions of the following classes are provided:

l                     Clock Animation

l                     JLitst Test

l                     Walking People, and

l                     The Game of Queens

 

Make a product in Java by implementing the UML Diagram in Fig. 3.

Specifications are requested as follows:

 

1.        The user may control the pace of a person’s walking by clicking a color in the JList Test. Each selection of color defines a pace of walking: the lowest pace is associated with the color Black while the fastest, Yellow.

 

  1. Clicking the “next solution” button in the game of queens results in a small increment in the pace of walking. It may also trigger the corresponding background color of the clock. In other words, after clicking the button:

 

l                     the green background appears when the pace of walking is below the color of Green.

l                     the orange background appears when the pace of walking is between the colors of Green and Red,

l                     the red background will appears when the pace is defined by selection of the color of Red, White and Yellow. 

l                     In an extreme scenario where the pace is too fast, warning words may appear on the clock: “ Beyond the speed limit !!!”

  

 

3.             Aliases

 

Aliasing is the use of two or more distinct referencing methods or names for the same memory cell. Aliasing in languages like C/C++, cause not only a hindrance to readability or a collision when pass-by-reference  (Sebesta, 2002, see Fig. 4), but also the dangling reference (Dattatri, 2000, see Fig.5).  The syntax in creating aliasing in both Java and C# as well as the consequences are the same.  For example, the following code instantiated an object time from the user-defined class Time1 and then introduces an alias AliasTime:

 

Time1 time = new Time1();  // calls Time1 constructor

      Time1 AliasTime = time;

Later the programmer deletes this object by

                time = null;

Consequently, the garbage collector will not collect this object since another reference AliasTime has not yet been assigned with the null.

 

The .NET Framework supporting C# performs garbage collection in a similar way to Java, that is when the garbage collector executes, it locates only objects for which the application has no references (Deteil. et al, 2003).

 To accommodate multiple languages in the MS Visual Studio .NET, aliasing occurs in a Dynamically Linked Library (DLL) procedure.

 

Aliasing in Lisp has different effects from C/C++. Graham (1997) demonstrated the following scenario ( see Fig. 6): two variables (X and Y) set to the same list. Hence, aliasing occurs. However, the two variables refer differently after one pop was made on X. This is because the location in memory associated with the variable x does not contain the list itself, but a pointer to it. When we assign the same value to y, Lisp copies the pointer, not the list.  In Lisp, you can use rplaca, rplacd to change a structure. Once a structure is changed, all the names that refer to it have the changed value.“ (Jia You, 2003, personal communication)

 

 

4.         Discussion

 

After completion of the assignment (Fig2, 3) students could be asked to do some reversed engineering work, e.g. providing other UML diagrams, such as State Chart, and Sequence Diagram.

 

Appropriate documentation should be emphasised in association with labs, assignments, and projects. A template could be made beforehand.

 

The following assignments/labs were successfully completed by my students before the work on “A Combination of Four” (Fir.2).

 

1.        A clock with pendulum in Java ( e.g. http://turing.kingsu.ca/~tong/WCCCE/Clock1/)

2.        8 queens in Java and/or C++

3.        Combination of the classes Person and myClock.

 

The UML is a graphical notation for expressing OO designs. The official UML standard is managed by the Object Management Group which is a consortium of companies (www.omg.org). In the example of A Combination of Four (Fig. 2, 3), the class MyClock aggregates (Braude, E. 2002) the classes ListTest, Queens, and Person.

Although the classes, as well as some of their attributes, operations, and relationships are clearly indicated in the UML (Fig. 3), students must figure out how to manipulate or access the data members of one class by the methods of another class. After students successfully complete this work, they may confirm the following points.

 

l                     The methods in the aggregated classes (e.g. ListTest) may only manipulate the public and static data members  of the aggregator (MyClock).

l                     The methods in the aggregated classes may only use the static methods in the aggregator class.

l                     The methods in the aggrefator class (MyClock) may have access to and alter the public data members of an instance of the aggregated class.

l                     The methods in the aggregator class may use any public methods of its aggregated classes.  

 

 

Lam (2003) indicated an exampe of namespace aliasing in C#.

 

using Channels = System.Runtime.Remoting.Channels;

 

Lam (2003) also adds that it is beneficial if “you have namespace conflicts and need to disambiguate your type references, or if you're from the school of thought that says that you must always use fully qualified type names, but don't want to obscure your code with giant namespace references.”

On the whole, negative and positive aspects of aliasing in programming languages should be reviewed.

 

 

Acknowledgement

 

The author thanks Dr. David Lyder for useful discussions and reading of the manuscript, as well as the two anonymous reviewers who provided valuable feedbacks.

 

  

Reference:

 

Braude, E. 2002. Software Design, From Programming to Architecture. John Wiley & Sons, Inc. pp.550

Budd, T. 1997.An Introduction to Object-Oriented Programming (2nd Edition). Addison-Wesley. Don Mills, Ontario. pp.452.

Dattatri, Kayshav. 2002. C++ Effective object-Oriented Software Construction (2nd Edition). Prentice Hall

Deitel, H.M.  & Deitel, P.J. (1997, 1998, 2002, 2003). Java How to Program. Introducing OOD with the UML and Design Patterns (up to 5th edition). Prentice Hall. New Jersey.

Deitel, H.M., Deteil, P.J., Listfield, J., Nieto, T.R., Yaeger, C., and Zlatkina, M. (2002). C# How To Program. Prentice Hall, Upper Saddle River. pp.1568

Graham, P. 1997.ANSI Common Lisp. Prentice Hall. Toronto. pp.432.

Lam, J. 2003. http://www.iunknown.com/Weblog/CoolCfeaturespotted.html

Sebesta, R. W.,2002. Concepts of Programming Languages. (5th Edition) Addison Wesley. Toronto.

 

 

Figure 1. Genealogy of common high-level programming languages in association with 5 generations of modern computers. (Modified by T. Xu & R. Salomons from Sebesta, 2002,  p. 39).

 

 

 

 

 

 

 

 

Figure 2. A Combination of Four.

Figure 3. Class diagram for the Web Clock.

 

 

 

Figure 4. The collisions when pass-by-reference

 

Figure 5. The dangling reference

 

 

 

 

 

 

 

Figure 6. Aliasing in Clisp. Interpreter used: LispWorks® Personal Edition, Xanalys software tools