Download presentation
Presentation is loading. Please wait.
1
Microsoft Courses 20031 Introductory Programming with C# Judith Bishop University of Pretoria, South Africa Visiting TU-Berlin
2
Microsoft Courses 20032 Talk 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
3
Microsoft Courses 20033 Featuring … Syntax and semantics descriptions Early use of libraries Independent GUI specifications Debugging New
4
Microsoft Courses 20034 Focus 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)
5
Microsoft Courses 20035 Changing 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
6
Microsoft Courses 20036 A 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?
7
Microsoft Courses 20037 Where 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
8
Microsoft Courses 20038 What 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
9
Microsoft Courses 20039 An 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
10
Microsoft Courses 200310 What 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
11
Microsoft Courses 200311 What 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
12
Microsoft Courses 200312 What 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
13
Microsoft Courses 200313 C# 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
14
Microsoft Courses 200314 Volunteers on a C# course in Africa Do it in C# Naturally!
15
Microsoft Courses 200315 From 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(); } }}
16
Microsoft Courses 200316 Syntax forms in C#C Fixed words and symbols Items to fill in public string Course { get {return course;} }
17
Microsoft Courses 200317 Also for libraries
18
Microsoft Courses 200318 Visual Studio Help
19
Microsoft Courses 200319 Concepts for simple oops
20
Microsoft Courses 200320 Example 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
21
Microsoft Courses 200321 GUIs 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
22
Microsoft Courses 200322 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] Where GUIs are going Views
23
Microsoft Courses 200323 … 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]
24
Microsoft Courses 200324 VS.NET Common Language Runtime System System.Data (ADO.NET) System.Xml System.Drawing System.Web (ASP.NET) System.WinForms SDK Tools Rotor CLI Implementation C# JScript Platform Abstraction System.WinForms
25
Microsoft Courses 200325 Views 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
Microsoft Courses 200326
27
Microsoft Courses 200327 Example in WinForms show.Click += new EventHandler(ActionPerformed); hide.Click += new EventHandler(ActionPerformed); } public 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
28
Microsoft Courses 200328 GUI building today GUI Builder Add Listeners Handlers widget rendering in the OS Visual Studio C# Windows widget calls in a language Application
29
Microsoft Courses 200329 A GUI using XML Application Handlers widget rendering in the OS Control Engine Add Listeners GUI XML Spec GUI XML Spec
30
Microsoft Courses 200330 Example in Views Views.Form f = new Views.Form(@" <PictureBox Name=pic Image='C:Jacarandas.jpg' Height=175/> " ); string c; for (;;) { c = f.GetControl(); PictureBox pb = f["pic"]; switch (c) { case ”Show" : pb.Show(); break; } case ”Hide" : pb.Hide(); break; } No pixel positioning No generated code Separation of concerns XML C#
31
Microsoft Courses 200331 Views.Form v = new Form (@" "); int luckyNumber = int.Parse(v.GetText("Number")); Random r = new Random (luckyNumber); for( ; ; ) { string s = v.GetControl( ); if (s==null) 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")); } Example 2
32
Microsoft Courses 200332 Other Views examples Calculator –Compare with text version –Separation of concerns –Internationalization PhotoAlbum –Fun with pictures
33
Microsoft Courses 200333 Debugging 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
34
Microsoft Courses 200334 Oops in C# Structs and classes Well defined collection library –Array class –Sorted lists –BitArray –Queue, Stack, Hashtable Polymorphism and extensibility –Interfaces and inheritance
35
Microsoft Courses 200335 Example - 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
36
Microsoft Courses 200336 Assessment 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
37
Microsoft Courses 200337 References Peter Drayton, Ben Albahari, Ted Neward, C# in a Nutshell, O’Reilly, 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.comwww.devhood.com http://www.cs.up.ac.za/rotor -- for the Views project http://www.cs.up.ac.za/rotor
38
Microsoft Courses 200338 Motivation 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
39
Microsoft Courses 200339 The Views Notation form: controlGroup controlGroup: controlList | controlList controlList:{ control } textItemList: { text } control:controlGroup | | | textItemList | radioButtonList | | radioButtonList:{ }
40
Microsoft Courses 200340 Handler methods 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 Essentially five kinds of methods: construct close getControl get put PLUS … direct access
41
Microsoft Courses 200341 Handler methods 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 Essentially five kinds of methods: construct close getControl get put PLUS … direct access
42
Microsoft Courses 200342 Object orientation Extension, polymorphism Delegation M M M A BC F() -- calls M M M M M I A B C M D D1(P) D2(Q) D3(R) F(D1) -- calls P via M P QR AB Interfaces Inheritance Delegates C
43
Microsoft Courses 200343 GUI building today GUI Builder Add Listeners Handlers widget rendering in the OS Visual Studio C# Windows widget calls in a language Application
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.