C#: CS1 Should We Switch ? WG2.4 AUGUST 7,2003 IRA POHL  ALGOL – PL/1 – Pascal – C / C++ / Java / C#  What have we learned from CS1 choices  Neat Features.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
C#: Data Types Based on slides by Joe Hummel. 2 UCN Technology: Computer Science Content: “.NET is designed around the CTS, or Common Type System.
Road Map Introduction to object oriented programming. Classes
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
3. Data Types. 2 Microsoft Objectives “.NET is designed around the CTS, or Common Type System. The CTS is what allows assemblies, written in different.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Abstract Data Types and Encapsulation Concepts
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Java versus C# An introduction to C# and Visual Studio.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Programming in C# Language Overview
Java Unit 9: Arrays Declaring and Processing Arrays.
OOP Languages: Java vs C++
Comparison of OO Programming Languages © Jason Voegele, 2003.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Chapter 11 Abstract Data Types and Encapsulation Concepts.
Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C#.NET.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
1 Programming Language History and Evolution In Text: Chapter 2.
Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications.
ILM Proprietary and Confidential -
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Introduction to C#. Why C#? Develop on the Following Platforms ASP.NET Native Windows Windows 8 / 8.1 Windows Phone WPF Android (Xamarin) iOS (Xamarin)
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Types in programming languages1 What are types, and why do we need them?
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
C Sharp Web & Internet Programming Group Diana, Aren, Jeff, & Adam, Farrin 5/5/20081CS 311.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Object-Oriented Programming Chapter Chapter
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Section 3 - Arrays and Methods. Arrays Array: collection of group of data variables of same type, sharing the same name for convenience - Easy to search.
ISBN Object-Oriented Programming Chapter Chapter
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Session 1 C# Basics.
Introduction to C# By: Abir Ghattas Michel Barakat.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
OOP Basics Classes & Methods (c) IDMS/SQL News
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Copyright 2006 Pearson Addison-Wesley, 2008, 2012 Joey Paquet 1 Concordia University Department of Computer Science and Software Engineering SOEN6441 –
ISBN Chapter 12 Support for Object-Oriented Programming.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Value Types. 2 Objectives Discuss concept of value types –efficiency –memory management –value semantics –boxing –unboxing –simple types Introduce struct.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Programming Language History and Evolution
C# for C++ Programmers 1.
C# — Console Application
Abstract Data Types and Encapsulation Concepts
Java Primer 1: Types, Classes and Operators
Java Review: Reference Types
Programming Language History and Evolution
CS360 Windows Programming
C# In many ways, C# looks similar to Java
Abstract Data Types and Encapsulation Concepts
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

C#: CS1 Should We Switch ? WG2.4 AUGUST 7,2003 IRA POHL  ALGOL – PL/1 – Pascal – C / C++ / Java / C#  What have we learned from CS1 choices  Neat Features of C#  C# vs. Java vs. C++ 

Family of Languages

CS1 through the years  Academic computer science in the 60’s  ALGOL 60 vs. FORTRAN  Confusion at the end of the 60’s  Pl/1, ALGOL W, BASIC, ALGOL 68  Pascal consensus

CS1: mid-80’s through present  C++ becomes a contender: very influential  Complex, but OO starts being dominant  1995: Java phenomena  2000: Java starts achieving majority status  2002: C# – why it will replace Java  (ALGOL W v Pascal – incremental change)

Copyright Ira Pohl ALGOL 60 BLOCKS,TYPE DECLARATION,RECURSION BNF, FOR, CALL BY NAME, PUBLICATION, PROCEDURAL ENCAPSULATION CS IS DOMINATED BY NUMERICAL SCIENCE CHIEF COMPETITION IS FORTRAN

Copyright Ira Pohl TROUBLESPOTS Knuth’s 1967 Trouble spots paper: begin integer a; integer procedure f(x, y); value y, x; integer y, x; a := f := x + 1; integer procedure g(x); integer x; x := g := a + 2; a := 0; outreal(1, a + f(a,g(a))/g(a)) end;

Copyright Ira Pohl OH PASCAL NEED NON NUMERICAL TYPES RECORDS PL1 ALGOL W ALGOL68 PASCAL ALGOL W V. PASCAL V. ALGOL 68 CHEAP, WIDESPREAD, INCREMENTALLY BETTER, BOOKS

Copyright Ira Pohl MODULE AND ADT 1980 PASCAL AND STEPWISE REFINEMENT WEAK LIBRARIES, NON-MODULAR SO UCSD PASCAL, MODULA2, C, ADA SHOULD WIRTH HAVE DEVELOPED PASCAL II

Copyright Ira Pohl OO AND UNIX 1985 LARGER SCALE UNIX PROJECT INFLUENCE STUDENTS WANT JOB SKILLS MAKE AND FILES SMALLTALK OO VISIBILITY INCREASES C, C++, MOULA 2 AND PASCAL, ML

Copyright Ira Pohl JAVA C++ TOO COMPLEX BUT OO NOW DOMINATES C TO PRIMITIVE SCHEME EIFFEL …. NICHE JAVA WORE{WRITE 1 RUN EVERWHERE} APPLETS WEB NO POINTERS PURE OO NEW CONSENSUS

CS1 Requirements  Modern and supports dominant methodology  Pascal: structured programming  C#, C++, Java: OOP  Multi-platform,excellent implementation books  Type safety, assertions, error messages  syntax, runtime  In Wide Use (has yet to happen for C#)

Traditional First C# Program // Hello world in C# // by Olivia Programmer using System; class Hello { public static void Main() { Console.WriteLine("Hello, world!"); } }

“The Alpha Centarians say Hello in C#!”

Make change in C++ // Change in dimes and pennies #include using namespace std; int main() { int price, change, dimes, pennies; cout > price; change = price; // how much change dimes = change / 10; // number of dimes pennies = change % 10; // number of pennies cout << "\n\nThe change is :" << dimes << " dimes "; cout << pennies << " pennies." << endl; }

MakeChange Java by Dissection import tio.*; // use the package tio class MakeChange { public static void main(String[] args) { int price, change, dimes, pennies; System.out.println("type price (0:100):"); price = Console.in.readInt(); change = price; // how much change dimes = change / 10; // number of dimes pennies = change % 10; // number of pennies System.out.print("The change is :"); System.out.print(dimes); System.out.print(" dimes "); System.out.print(pennies); System.out.print(" pennies.\n"); } }

C# by Dissection chapter 1 example using System; class MakeChange { public static void Main() { int price, change, dimes, pennies; // declarations string data; Console.WriteLine("Enter price (0:100):"); data = Console.ReadLine(); price = int.Parse(data); change = price; // how much change dimes = change / 10; // number of dimes pennies = change % 10; // number of pennies Console.Write("\n\nThe change is: " + dimes + " dimes "); Console.WriteLine(pennies + " pennies."); } }

C# version Not much difference from Java In many examples change is a matter of style and naming conventions, such as use of Main Instead of main And Console.WriteLine()

Types: Better than C++ or Java  Simple types  character, integer, floating-point types  Boolean type  Derived types  array, string: aggregates of simple types  Enum, struct (lightweight-object)  Everything derives from object!!!  Safety with initialization rule

The foreach Statement (Arrays only) for (i = 0; i < arrayName.Length; ++i) process arrayName[i]; foreach (T variableName in arrayName) process variableName; static void WriteArray(int[] a, String arrayName) { foreach (int element in a) Console.Write(element + " "); }

Iterator Logic: IEnumerable  foreach is important idea and safer construct than standard for iteration  Later, through use of interface inheritance, student can be taught to properly constructor their own collection class  Can use foreach

Call-By-Reference Improved Over Java  To modify variables passed as parameters, use call-by-reference  Designated by added keyword ref  ref used when declaring formal parameters when passing actual arguments  It is clear that ref variables are changed

Swap Program (1 of 2) class TestSwap { public static void Main() { int numOne = 1, numTwo = 2; Swap(ref numOne, ref numTwo); Console.WriteLine("numOne = " + numOne); Console.WriteLine("numTwo = " + numTwo); }

Swap Program (2 of 2) public static void Swap(ref int x, ref int y) { int temp; Console.WriteLine("x = " + x); Console.WriteLine("y = " + y); temp = x; x = y; y = temp; Console.WriteLine("x = " + x); Console.WriteLine("y = " + y); }

True Higher Dimensional Arrays  Jagged arrays as in C++ and Java  We have a[,,] arrays and appropriate methods and properties

TwoD Program class TwoD { public static void Main() { int[,] data = new int[3,5]; //row x column Console.WriteLine("No. of elements = " + data.Length); for (int i=0; i<data.GetLength(0); ++i) { Console.WriteLine("Row " + i + ": "); for (int j=0; j<data.GetLength(1); ++j) { data[i,j] = i * j; Console.Write(data[i,j] + ", "); } Console.WriteLine(); } } }

Improved Operator Overloading  Associated assignment op implicitly overloaded  Ordinary assignment cannot be overloaded  Overloaded as static methods  Unary operators take single argument of class type  Binary operators take one or both arguments of class type

System.Object  All types inherit form class System.Object including simple native types class Person { ····· public override string ToString() { return (name + ", age is " + age + ", gender is " + gender); }

Object and Un/ Boxing Example bool flag = true, answer; double x = 3.5; object any = flag; // boxing value to // reference type answer = (bool)flag // unboxing any = x; // boxing double value  When method defined for Object such as ToString( ) is called on value type, value is boxed  Works with value types as arguments to Write( ) and WriteLine( )

Property using get and set and value public class Point { public override string ToString() { return String.Format("({0}, {1})", x, y); } public double X // property for manipulating x { get { return x; } set { x = value; } } public double Y // property for manipulating y { get { return y; } set { y = value; } } private double x, y; }

Set and Get The C# language gives a standard rather than an ad hoc scheme for providing access and mutation to underlying state variables. This teaches methodology in a more straightforward way Note the style of using X (capitalized) for the hidden x (lowercase)

Java and C++ Comparisons  As in C#, Java and C++ have constructors  C++ does not have garbage collection and relies on destructors to deallocate memory using delete  In Java, classes include ToString( ), returns a string representation of class  In C#, we can implement ToString( )

Why C# Is Better Than Java  In C#, everything is an object  C# native types to be passed by reference  C# has boxing and unboxing for generic routines  C# foreach & IEnumerator for iterator  C# has true multi-dimensional arrays  C# get and set as access methods for retrieving and changing data members values  C# programmer can readily convert Java code to C#, but not vice versa

Why C# Is Better Than Java  C# get and set to access properties for retrieving and changing data members values  Keeps data hiding with consistent methodology  The C# programmer can readily convert Java code to C#, but not vice versa

Why C# Is Better Than Java  C# has enum as type and struct as lightweight object  C# programmer can use pointers but most label code unsafe  CLR and interoperable code – such as managed C++ and VB

Why C# Is Better Than C++  C++ too complex and unsafe  C++ system-dependent  C++ not Web-ready  C++ does not manage memory  C++ has pointer types

C# and Treatment of Type  Native simple types, such as int, bool, and double are value types  User-defined class types are reference type  string is a reference type  Reference types such as person call a constructor to build instances of types  Otherwise special value null : empty reference value

Final Thoughts  C# nicely improved on Java and C++  C# can be used for everything  sockets, threading, events, sql, …XML  C# by Dissection: a plug  Parallel treatment  Students probably use all 4 languages: C, C++, Java and C#