Title: Introductory Programming with C
1Introductory Programmingwith C
- Judith Bishop
- University of Pretoria, South Africa
- Visiting TU-Berlin
2Talk overview
- Introduction
- Who, why, when, how, with what?
- Syntax and semantics
- for you and your students
- A tour through some lessons
- Early concepts
- Our approach to GUIs
- Debugging
- Advanced concepts
- Assessment
- Quizzes, exercises, laboratories, exams
- References
3Featuring
- Syntax and semantics descriptions
- Early use of libraries
- Independent GUI specifications
- Debugging
New
4Focus on C
- Designed by Anders Hejlsberg, Scott Wiltamuth and
Peter Golde - To b the main development medium for future
Microsoft products - Origins in C, Java, Delphi, Modula-2, Smalltalk
- Heljsberg was the chief architect behind Turbo
Pascal and Delphi - Standardised by Ecma and ISO
- Free (to us)
5Changing languages
- Major movements worldwide
- To Pascal in 1970s and 1980s
- To Java in 1990s
- Caused by advances in technology
- Data structures, oops, internet computing
- Foundation for later courses
- Desire to be "ahead of the pack"
- Inhibitors to change
- Lack of teaching resources
- Computing resources required by new technology
- Investment in current language
- Uncertainty over the measure of improvement
6A first programming course
- Typically 40-50 lectures
- 10-14 laboratories
- Take home assignments
- Project
- Questions
- where does it start?
- where does it end?
- what is the place of libraries?
- what is the order of topics?
- what should be included/left out?
- what do I need to run the language?
7Where does it start and end?
- Most institutions assume "no background"
- most students have more than that
- use of computers is almost universal now
- students can interact with GUIs
- Strong desire to have "objects first"
- but what is second?
- what do objects assume?
- With or without GUIs?
- huge tension between need to program
realistically and the number of concepts required
to express GUIs - Advanced topics can be left to other courses
- networking and databases - NetCentric Computing
- generics and overloading - Data Structures
8What about libraries?
- Libraries cannot be ignored,
- More in the libraries than in the language!
- Without them, examples will be too constrained
- Students can be on a "need to know basis", BUT
they need to know the structure and organisation
of libraries - This knowledge transcends languages
- Early use of libraries introduces many
fundamental concepts in a controlled manner, e.g. - variables vs properties
- instance vs static
- constructors
- parameters
9An order of topics
- Introduction to computers, languages and
compiling 2 - Using types 5
- Defining types 5
- Data structures and control structures 5
- Views System 4
- Input and output with files 4
- Debugging 3
- Collections 5
- Extensibility and polymorphism 5
- Extra topics 2
Half way
10What to include?
- If a feature is covered, cover it completely,
albeit over time in a spiral fashion - Include
- images as data types - adds to the fun
- GUIs - for realism
- formatting and unicode - promotes
internationalisation - serialization - makes for serious programs
- exception handling - makes for robust programs
- foreach loop - so neat and powerful
- collections - enhance object-orientation
11What to exclude?
- What to exclude depends on
- length of course
- interface with other courses
- A suggestion
- threads - in Operating Systems
- networking - for Netcentric Computing
- graphics and delegates - to introduce non-Views
GUIs - operator overloading, other upcoming features
(e.g. generics), - in Data Structures - Notes
- Topics that were in a Java introductory course
might not be in a C version (applets) - NOTE some institutions will start with
Netcentric Computing - interesting approach
12What resources do I need?
- Microsoft Academic Alliance, plus
- Option 1 (Student)
- a PC
- C compiler
- Any simple editor
- Option 2 (Lecturer)
- a PC with lots of memory
- Visual Studio
- Option 3 (Researcher)
- PC or Mac, Windows or Linux
- Rotor
- Any simple editor
13C Concisely
- First year programming text book, Oct 2003
- Pearson, 2004
- Incorporates Views
- Reviewed by Microsoft
- Contents on the Views website
- http//csharp.cs.uvic.ca
14Volunteers on a C course in Africa
Do it in C Naturally!
15From the ECMA C Specification
- 8.7.4 Properties
- A property is a member that provides access to a
characteristic of an object or a class. Examples
of properties include the length of a string, the
size of a font, the caption of a window, the name
of a customer,and so on. Properties are a natural
extension of fields. Both are named members with
associated types, and the syntax for accessing
fields and properties is the same. However,
unlike fields, properties do not denote storage
locations. Instead, properties have accessors
that specify the statements to be executed when
their values are read or written. - Properties are defined with property
declarations. The first part of a property
declaration looks quite similar to a field
declaration. The second part includes a get
accessor and/or a set accessor. In the example
below, the Button class defines a Caption
property. - public class Button
- private string caption
- public string Caption
- get
- return caption
-
- set
- caption value
- Repaint()
-
16Syntax forms in CC
Fixed words and symbols
Items to fill in
public string Course get return course
17Also for libraries
18Visual Studio Help
19Concepts for simple oops
20Example sequence from early lessons
- Example 2.5 (page 45) - Meeting times
- Creates objects of type DateTime and accesses
their properties and methods - Example 2.6 (page 47) - Dates in different
formats - Further example of DateTime methods, customising
output - Example 2.7 (page 49) - Time with reading
- Introduces input using Console and the Parse
methods of a type - Example 3.4 (page 83) - Table of meeting times
- Using a loop to create different times
- Examples 3.2 and 3.3 (page 75) - The shuttle bus
- Defining a type from scratch and using it in a
program
21GUIs
- Current approaches do not emphasise independent
principles - OPTIONS
- Create GUIs by hand
- error prone
- takes too much time
- Use a GUI builder
- dumps code in the program
- hides principles
22Where GUIs are going
- The reality of a
- single cross-language,
- cross-platform
- GUI interface programming model
- is in sight, based on an
- XML description language
- supported by
- fast native runtimes.
- Russel Jones, DevX, Nov 2002
23 and more recently
- Supporting many GUIs
- isn't just a simple process
- of including one set of libraries or another
- it's often a frustrating and error-prone exercise
- in writing GUI-specific code.
- Russel Jones, DevX, Aug 2003
24Rotor CLI Implementation
VS.NET
System.Web (ASP.NET)
System.WinForms
System.WinForms
System.Drawing
System.Data (ADO.NET)
System.Xml
SDK Tools
System
Common Language Runtime
Platform Abstraction
25Views
- Views is a Vendor Independent Extensible
Windowing System - Developed by Nigel Horspool and Judith Bishop
with help from students in 2002-2003 - Provides an XML-based specification notation for
defining GUIs, and an execution engine for
handling event listening and dispatching back to
the program - It was supported under the Microsoft Rotor RFP
Program - It is distributed from the C Concisely book
website
26(No Transcript)
27Example in WinForms
show.Click new
EventHandler(ActionPerformed) hide.Click new
EventHandler(ActionPerformed) p
ublic void ActionPerformed(Object src,
EventArgs args) if (src
show) pic.Show() else if (src hide)
pic.Hide() i
- Embedded in 115 lines of generated code - do
not touch - Unexplained classes and unused objects here
28GUI building today
29A GUI using XML
30Example in Views
XML
Views.Form f new Views.Form(_at_"ltFormgt
ltverticalgt lthorizontalgt ltButton
NameShow/gt ltButton NameHide/gt
lt/horizontalgt ltPictureBox Namepic
Image'CJacarandas.jpg' Height175/gt
lt/verticalgt lt/Formgt" )
string c for () c f.GetControl()
PictureBox pb f"pic" switch (c) case
Show" pb.Show() break case
Hide" pb.Hide() break
C
- No pixel positioning
- No generated code
- Separation of concerns
31Example 2
Views.Form v new Form (_at_"ltform Text Luckygt
ltverticalgt ltTextBox name Number Text
'13'/gt ltButton name Start/gt
ltListBox name Day Width 270/gt
lt/verticalgt lt/formgt") int luckyNumber
int.Parse(v.GetText("Number")) Random r
new Random (luckyNumber) for( )
string s v.GetControl( ) if (snull)
break DateTime luckyDate new
DateTime(DateTime.Now.Year, r.Next(3,12),
r.Next(1,30)) v.PutText("Day", "Your
lucky day will be "
luckyDate.DayOfWeek " " luckyDate.ToString("M"
))
32Other Views examples
- Calculator
- Compare with text version
- Separation of concerns
- Internationalization
- PhotoAlbum
- Fun with pictures
33Debugging
- Principles - types of errors
- syntactic
- semantic
- runtime
- Exception handling
- Robust code
- simple logic
- validity checks - also with Assert
- tracing statements
- Debugger programs
- Text based, or
- GUI, with or without Visual Studio
34Oops in C
- Structs and classes
- Well defined collection library
- Array class
- Sorted lists
- BitArray
- Queue, Stack, Hashtable
- Polymorphism and extensibility
- Interfaces and inheritance
35Example - Access control
- Page 318
- Students, staff, posgrads and tutors have
different rules for access to a building. The
rules are implemented at the start of each year. - Polymorphic collection over IAccess
- Classic simple data update example
- Can be much extended e.g. for
- serialisation
- images
36Assessment
- Quizzes
- available online on the website
- Exercises
- at the end of each chapter - answers will be
provided to lecturers - Practicals
- worksheets are being devised based on the book
- Exam questions
- samples will also be provided
- Watch for the CD
37References
- Peter Drayton, Ben Albahari, Ted Neward, C in a
Nutshell, OReilly, 2002 - Troelsen, Andrew C and the .NET platform A!
press 2001 - Damien Watkins, Mark Hammond and Brad Abrams,
Programming in the .NET environment, Microsoft
.NET Development Series, Addison Wesley, 2002 - Not many text books yet, but many trade books
- Visual Studio help files
- DevHood tutorials -- see http//www.devhood.com
- http//www.cs.up.ac.za/rotor -- for the Views
project
38Motivation for a different approach
- Forward looking
- Move to platform independent GUI systems
- Integration of XML into languages (cf XEN)
- Technical
- Rotor does not have a GUI capability
- Interesting challenges in Reflection, RegEx etc
- Educational
- Dissatisfaction with method-oriented or drag and
drop GUIs - Separation of concerns
39The Views Notation
form ltformgt controlGroup lt/formgt controlGroup lt
verticalgt controlList lt/verticalgt
lthorizontalgt controlList lt/horizontalgt controlList
control textItemList ltitemgt text lt/itemgt
control controlGroup ltButton/gt
ltCheckBox/gt ltCheckedListBoxgt textItemList
lt/CheckedListBoxgt ltDomainUpDowngt textItemList
lt/DomainUpDowngt ltGroupBoxgt radioButtonList
lt/GroupBoxgt ltLabel/gt ltListBox/gt
ltOpenFileDialog/gt ltSaveFileDialog/gt
ltPictureBox/gt ltTextBox/gt ltProgressBar/gt
ltTrackBar/gt radioButtonList ltRadioButton/gt
40Handler methods
Essentially five kinds of methods construct clo
se getControl get put PLUS direct access
Form(string spec,params) The constructor. void
CloseGUI( ) Terminates the execution thread
string GetControl( ) Waits for the user to
perform an action string GetText(string
name) Returns the value of the Text
attribute int GetValue(string name) Returns the
Value attribute from TrackBar, ProgressBar and
CheckBox int GetValue(string name, int index)
Returns the status of CheckBox at position
index void PutText(string name, string
s) Displays the string in a TextBox or ListBox
control. void PutValue(string name, int
v) Sets an integer value associated with a
ProgressBar or CheckBox
41Handler methods
Essentially five kinds of methods construct clo
se getControl get put PLUS direct access
Form(string spec,params) The constructor. void
CloseGUI( ) Terminates the execution thread
string GetControl( ) Waits for the user to
perform an action string GetText(string
name) Returns the value of the Text
attribute int GetValue(string name) Returns the
Value attribute from TrackBar, ProgressBar and
CheckBox int GetValue(string name, int index)
Returns the status of CheckBox at position
index void PutText(string name, string
s) Displays the string in a TextBox or ListBox
control. void PutValue(string name, int
v) Sets an integer value associated with a
ProgressBar or CheckBox
42Object orientation
- Extension, polymorphism
- Delegation
C
Delegates
Interfaces
Inheritance
43GUI building today