{ JSL } phone +44 (0)
|
|
- Isabella Lynch
- 5 years ago
- Views:
Transcription
1 1 JSL Uncommon C# Authoring Consulting Crafting Designing Mentoring Training Jon Jagger JSL phone +44 (0) mobile +44 (0) C#
2 2 JSL Definite Assignment 12.3 Definite Assignment A variable shall be definitely assigned at each location where its value is obtained. The occurrence of a variable in an expression is considered to obtain the value of the variable, except when: The variable is the left operand of a simple assignment. The variable is passed as an output parameter. The variable is a struct type variable and occurs as the left operand of a member access. static void Main() int value; unsafe int * ptr = &value; Console.WriteLine(value);
3 3 JSL 2 Conformance The text in this International Standard that specifies requirements is considered normative. Normative text is further broken down into required and conditional categories. Conditionally normative text specifies a feature and its requirements where the feature is optional. Conformance 7 General Description all of clause 27 with the exception of the beginning is conditionally normative; 27 Unsafe code An implementation that does not support unsafe code is required to diagnose any usage of the unsafe keyword. The remainder of this clause, including all of its subclauses, is conditionally normative.
4 4 JSL 27.2 Pointer Types In an unsafe context several constructs are available for operating on pointers: Spot the bug The unary * operator can be used to perform pointer indirection (27.5.1) The -> operator can be used to access a member of a struct through a pointer (27.5.2) The [] operator can be used to index a pointer (27.5.3) The ==,!=, <, >, <=, and => operators can be used to compare pointers (27.5.7) The stackalloc operator can be used to allocate memory from the call stack (27.7) The fixed statement can be used to temporarily fix a variable so its address can be obtained (27.6)
5 5 JSL Protected access for instance members Protected access public public class class A protected protected int int x; x; static static void void F(A F(A a, a, B b) b) a.x a.x = 1; 1; // // Ok Ok b.x b.x = 1; 1; // // Ok Ok public public class class B : A static static void void F(A F(A a, a, B b) b) a.x a.x = 1; 1; // // Error Error b.x b.x = 1; 1; // // Ok Ok
6 6 JSL namespace pitfall Namespace lookup is inside outside Widget not in Company.Other.Framework.Tests Widget not in Company.Other.Framework Widget not in Company.Other Widget IS in Company namespace namespace Company.Widget.Framework public public class class Widget Widget using using Company.Widget.Framework; namespace namespace Company.Other.Framework.Tests [TestFixture] [TestFixture] public public class class FubarTests FubarTests [Test] [Test] public public void void SomeTest() SomeTest() Widget Widget w = new new Widget(); Widget();......
7 7 JSL Guidelines avoid namespace-class class name clashes prefer a namespace prefix style namespace namespace Company.WidgetFramework public public class class Widget Widget Solution using using Company.WidgetFramework; namespace namespace Tests.Company.OtherFramework [TestFixture] [TestFixture] public public class class FubarTests FubarTests [Test] [Test] public public void void SomeTest() SomeTest() Widget Widget w = new new Widget(); Widget();......
8 8 JSL Default top-level class access is internal visible only inside the assembly Default access using using NUnit.Framework; namespace Company.WidgetLibTests [TestFixture] class class WidgetTests [Test] public void void SomeTest() //... //... Question: Does the test pass or fail?
9 9 JSL Make sure test classes are public Otherwise NUnit won't see them! Default pitfall using using NUnit.Framework; namespace Company.WidgetLibTests [TestFixture] public class class WidgetTests [Test] public void void SomeTest() //... //... Question: What else should you do?
10 10 JSL Check if [TestFixture]'d[ classes are internal Testing the tests [TestFixture] [TestFixture] public public class class InternalFixtureTests InternalFixtureTests [Test] [Test] public public void void AccidentalNonPublicTestFixture() AccidentalNonPublicTestFixture() Type Type tfa tfa = = typeof(testfixtureattribute); typeof(testfixtureattribute); Assembly Assembly self self = = this.gettype().module.assembly; this.gettype().module.assembly; foreach foreach (Type (Type type type in in self.gettypes()) self.gettypes()) object[] object[] attributes attributes = = type.getcustomattributes(tfa, type.getcustomattributes(tfa, false); false); if if (attributes (attributes!=!= null null && && attributes.length attributes.length > > 0 0 && && type.isnotpublic) type.isnotpublic) Assert.Fail(type.ToString() Assert.Fail(type.ToString() + + " " is is not not public!"); public!");
11 11 JSL What's this? Generic ambiguity F(G<A, B>(7)); A call to F with two arguments: G < A B > (7) viz redundant parentheses A call to F with one argument: G < A,B > (7) Two type parameters: A,B One regular argument: 7
12 12 JSL Operators and punctuators right-shift: > > >>== tokenization right-shift-assignment: > >= delegate void void D(); D(); class class C static void void F<T>() static D d = F<F<int>>; static void void Main() bool bool b = F<F<int>>==d; Compile-time error
13 13 JSL String literals When two or more string literals that are equivalent according to the string equality operator, appear in the same assembly, these string literals refer to the same string instance. String Interning Unfortunate example of over-specification Implementation!= specification Serves no useful purpose for C# users String reference equality does not mean strings are necessarily in the same assembly
14 14 JSL Hex Escape Sequence Character Literals A hex-escape escape-sequence sequence character literal has 1, 2, 3, or 4 hex-digits hexadecimal-escape-sequence: \x hex-digit hex-digit? hex-digit? hex-digit? s1 s1 = "\x7scotland"; // // BEL Scotland s2 s2 = "\x7england"; // // ~ ngland Advice: use unicode-escapes escapes
15 15 JSL are inadvisable in some places using using Integer = int; int; // // compile-time error error using using Integer = System.Int32; // // ok ok keywords Type Type ti ti = Type.GetType("int"); // // runtime failure Type Type ti ti = Type.GetType("System.Int32"); // // ok ok Type Type ti ti = typeof(int); // // better extern unsafe static void void Process(int length, S * array); // // ok ok extern unsafe static void void Process(Int32 length, S * array); // // better
16 16 JSL Properties are not variables public public struct struct Point Point private private int int x, x, y; y; public public int int X get get set set public public struct struct Rectangle Rectangle private private Point Point topleft; topleft; public public Point Point TopLeft TopLeft get get set set Properties class class App App static static void void Main() Main() Rectangle Rectangle r = new new Rectangle(); Rectangle(); r.topleft.x r.topleft.x = 42; 42; // // compile-time compile-time error error
17 17 JSL Calling a method on a readonly struct? The method is called on a copy of the struct! readonly + struct struct struct Mile Mile public public void void Add(Mile Add(Mile rhs) rhs) value value += += rhs.value; rhs.value; private private int int value; value; class class Trap Trap public public void void Ouch(Mile Ouch(Mile more) more) distance.add(more); private private readonly readonly Mile Mile distance; distance;
18 18 JSL Solution Make struct immutable rely on assignment readonly struct struct struct Mile Mile public public Mile(int Mile(int value) value) this.value this.value = value; value; public public static static Mile Mile operator+ operator+ Add(Mile Add(Mile lhs, lhs, Mile Mile rhs) rhs) return return new new Mile(lhs.value Mile(lhs.value + rhs.value); rhs.value); private private readonly readonly int int value; value; class class Trap Trap public public void void Ooops(Mile Ooops(Mile more) more) distance distance += += more; more; // // compile-time compile-time error error private private readonly readonly Mile Mile distance; distance;
19 19 JSL Checked pitfall public public class class Eg Eg public public void void Ok(int Ok(int x) x) x *= *= 2; 2; public public class class Eg Eg public public void void AlsoOk(int AlsoOk(int x) x) checked checked x *= *= 2; 2; public public class class Eg Eg public public void void NotOk(int NotOk(int x) x) checked(x checked(x *= *= 2); 2); public public class class Eg Eg public public void void OkAgain(int OkAgain(int x) x) x = checked(x checked(x * 2); 2);
20 20 JSL Checking noses The checked and unchecked statements The checked statement causes all expressions in the block to be evaluated in a checked context, and the unchecked statement causes all expressions in the block to be evaluated in an unchecked context. The checked and unchecked statements are precisely equivalent to the checked and unchecked operators ( ) except that they operate on blocks instead of expressions. checked checked int int value; value; value value = unchecked(checked(f() * G()) G()) + 42); 42);
21 21 JSL Constant expressions Must be evaluated at compile time And, by default, are checked public class class Eg Eg public virtual void void Method() const const int int factor = 0; 0; int int count; if if (factor!=!= 0) 0) count count *= *= 5 / factor;......
22 22 JSL Invariant meaning Invariant meaning in blocks For each occurrence of a given identifier as a simple-name in an expression or declarator, every other occurrence of the same identifier as a simple-name in an expression or declarator within the immediately enclosing block or switch-block shall refer to the same entity. class class Example void void F() F() if if (true) int int v = 42; 42; int int v = 1; 1;
23 23 JSL In retrospect a poor choice Default == unsealed public /*unsealed*/ class class Vulnerable ~Vulnerable() public /*unsealed*/ class class Vulnerable protected override void void Finalize() public class class Attacker : Vulnerable ~Attacker() for(;;);
24 24 JSL Guidelines Don't rely on defaults Make type and member access explicit Classes: static, sealed, abstract, or /*unsealed*/ Solutions public /*unsealed*/ class class DoesntCompile protected sealed override ~Vulnerable() public sealed class class Best Best ~Best()......
25 25 JSL virtual first implementation virtual: C#!= C++ public abstract class class Middle public virtual void void Foo() Foo() public sealed class class Bottom : Middle public virtual void void Foo() Foo() >Warning: Bottom.Foo() hides inherited member Middle.Foo()
26 26 JSL override another implementation public abstract class class Middle public virtual void void Foo() Foo() Solution public sealed class class Bottom : Middle public override void void Foo() Foo()......
27 27 JSL ref/out overloading too easy to forget the ref/out Overload pitfall - 1 public sealed class class Dodgy Dodgy public void void Foo(Wibble value) public void void Foo(ref Wibble value) public void void Bar(Wibble value) public void void Bar(out Wibble value)......
28 28 JSL Better conversion pitfall Overload pitfall - 2 public sealed class class A public static implicit operator B(A B(A from) from) public sealed class class B public sealed class class App App static void void Method(A a, a, B b) b) static void void Method(B b, b, A a) a) static void void Main() A a = new new A(); A(); Method(a, null); // // ambiguous
29 29 JSL Overload pitfall Method invocations The set of candidate methods for the method invocation is constructed. For each method F associated with the method group M: The set of candidate methods is reduced to contain only methods from the most derived types: public class class Base Base public virtual void void Method(int value) public class class Derived : Base Base public void void Method(double value) public override void void Method(int value) public class class Demo Demo public static void void Main() Derived d = new new Derived(); d.method(42);
30 30 JSL Guidelines Don't mix overloading and overriding Don't overload solely on ref/out Reference conversions inheritance Overloading does not happen in CIL Overload
31 31 JSL A class is implicitly convertible to an interface Only if it actually realizes the interface Conversion Oddity interface interface IWibble IWibble class class Alpha Alpha : IWibble IWibble class class Beta Beta public public static static implicit implicit operator operator Alpha(Beta Alpha(Beta from) from) return return new new Beta(); Beta(); class class App App static static void void Main() Main() Beta Beta b = new new Beta(); Beta(); IWibble IWibble iw iw = (IWibble)b; (IWibble)b; // // cast-required cast-required
32 32 JSL Reference type equality operators Every class type C implicitly provides the following predefined reference type equality operators: Hidden boxing? bool operator ==(C x, C y); bool operator!=(c x, C y); there are special rules for determining when a reference type equality operator is applicable. struct S S s1,s2; if if (s1 == == s2)...
33 33 JSL Addition operator string operator +(string x, string y); string operator +(string x, object y); string operator +(object x, string y); Hidden boxing message = "Answer==" + 42; message = operator+("answer==", (object)42); message = "Answer==" + 42.ToString();
34 34 JSL How to tell if a struct instance is boxed? Boxing Trick interface IBoxable bool bool? IsBoxed(); unsafe struct Eg Eg : IBoxable public Eg(int value) fixed fixed (Eg (Eg * ptr ptr = &this) this.address = ptr; ptr; public bool bool? IsBoxed() if if (address == == null) null) return null; null; else else fixed(eg * ptr ptr = &this) return ptr ptr!=!= address; private readonly Eg Eg * address;
35 35 JSL The lock statement A lock statement of the form lock lock (x) (x) is precisely equivalent to: object obj obj = x; x; System.Threading.Enter(obj); // // comment: weak weak spot spot here... try try finally System.Threading.Exit(obj); Q: What happens if a Thread.Abort occurs at the comment? A: The call to System.Threading.Exit is bypassed!
36 36 JSL Event Thread Unsafely The C# 1.0 Standard contained this example Ooops public delegate void void EventHandler(object sender, EventArgs e); e); public class class Button : Control public event event EventHandler Click; protected void void OnClick(EventArgs e) e) if if (Click!=!= null) null) Click(this, e); e);
37 37 JSL Event Thread safely The C# 2.0 Standard the example is now Much better public delegate void void EventHandler(object sender, EventArgs e); e); public class class Button : Control public event event EventHandler Click; protected void void OnClick(EventArgs e) e) EventHandler toraise = Click; if if (toraise!=!= null) null) toraise(this, e); e);
38 38 JSL The C# 1.0 Standard said this Field like events In order to be thread safe, the addition and removal operations are done while holding the lock on the containing object for an instance event, or the type object for a static event. Event Locking public delegate void void D(); D(); class class X public event event D Ev; Ev; class class X private D Ev; Ev; public event event D Ev Ev add add lock(this) Ev Ev += += value; remove lock(this) Ev Ev -= -= value;
39 39 JSL The C# 2.0 Standard says this Field like events The addition and removal operations on all instance events of a class shall be done while holding the lock on an object uniquely associated with the containing object. Event Locking public delegate void void D(); D(); class class X public event event D Ev; Ev; class class X private readonly object key key = new new object(); private D Ev; Ev; public event event D Ev Ev add add lock( key) Ev Ev += += value; remove lock( key) Ev Ev -= -= value;?
40 40 JSL Events inside structs? Event Locking? Field like events The addition and removal operations on all instance events of a class shall be done while holding the lock on an object uniquely associated with the containing object. public delegate void void D(); D(); struct S public event event D Ev; Ev; struct S private D Ev; Ev; public event event D Ev Ev add add Ev Ev += += value; remove Ev Ev -= -= value;
41 41 JSL Captured Variables delegate void void F(); F(); class class CapturedPitfall static void void Main() F[] F[] array array = new new F[5]; F[5]; for for (int (int at at = 0; 0; at at!=!= 5; 5; at++) at++) array[at] = delegate Console.Write(at); ; ; for for (int (int cat cat = 0; 0; cat cat!=!= 5; 5; cat++) array[cat](); 55555
42 42 JSL Captured Variables delegate void void F(); F(); class class CapturedPerLoop static void void Main() F[] F[] array array = new new F[5]; F[5]; for for (int (int at at = 0; 0; at at!=!= 5; 5; at++) at++) int int value value = at; at; array[at] = delegate Console.Write(value); ; ; for for (int (int at at = 0; 0; at at!=!= 5; 5; at++) at++) array[at](); 01234
43 43 JSL Captured Variables Local variable shared between threads! using using System.Threading; class class Demo Demo static void void Main() int int i = 0; 0; ThreadStart t1 t1 = delegate for for (;;) (;;) Thread.Sleep(102); i++; i++; ; ; ThreadStart t2 t2 = delegate for(;;) Thread.Sleep(500); System.Console.Write("0 ", ", i); i); ; ; new new Thread(t1).Start(); new new Thread(t2).Start();
44 44 JSL Not all exceptions are managed Exceptions class class Vulnerable static void void Main() try try // // catch catch (Exception error) // // clean-up code. code. could could result in in // // security hole hole if if not not run. run. // // Ooops Ooops
45 45 JSL C# 1.0 General catch clause Exceptions class class Vulnerable static void void Main() try try // // catch catch (Exception error) CleanUp(); catch catch CleanUp();
46 46 JSL CLR 2.0 Unmanaged exception RuntimeWrappedException Exceptions class class Vulnerable static void void Main() try try // // catch catch (Exception error) CleanUp(); catch catch // // new new compiler warning // // now now unreachable...
47 47 JSL Spot the bug Garbage Collection using using System.Threading; class class App App static static void void Main() Main() bool bool firstinstance; firstinstance; Mutex Mutex key key = new new Mutex(@"Global\App", out out firstinstance); firstinstance); if if (firstinstance) (firstinstance) // // we're we're the the only only instance instance running running // // else else // // another another instance instance detected detected // //......
48 48 JSL One solution Delayed Collection using using System.Threading; class class App App static static void void Main() Main() bool bool firstinstance; firstinstance; using using (new (new out out firstinstance)) firstinstance)) if if (firstinstance) (firstinstance) // // we're we're the the only only instance instance running running // // else else // // another another instance instance detected detected // //......
49 49 JSL That's all Folks! Any Questions? Authoring Consulting Crafting Designing Mentoring Training Jon Jagger JSL phone +44 (0) mobile +44 (0) C#
50 50 JSL What's this? 1.D 1 an int literal. the member access operator D the field/property called D or 1.D? 1. a double literal* D a double type suffix confirming 1. as a double
51 51 JSL portions of this presentation are from the forthcoming book Annotated C# Standard by Jon Jagger, Nigel Perry, Peter Sestoft published by Morgan Kaufmann copyright 200? Elsevier Inc Plug
52 52 JSL Absence, defaults, forbidden, compulsory Access Modifiers public interface IX IX void void M(); M(); public class class X : IX IX public static operator static X() X() ~X() ~X() void void IX.M() public not allowed public required Static constructor not callable Finalizer not callable Explicit Impl. not callable*
53 53 JSL Uninitialized variables Invocation expressions For an invocation expression expr of the form: primary-expression(arg 1, arg 2,, arg N ) For each argument arg i, the definite assignment state of v after arg i is determined by the normal expression rules, ignoring any ref or out modifiers. public class class Eg Eg static void void Method(out int int x, x, int int y) y) Console.WriteLine(y); x = 42; 42; static void void Main() int int x; x; Method(out x, x, x); x);
Table of Contents Preface Bare Necessities... 17
Table of Contents Preface... 13 What this book is about?... 13 Who is this book for?... 14 What to read next?... 14 Personages... 14 Style conventions... 15 More information... 15 Bare Necessities... 17
More informationC#: framework overview and in-the-small features
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer
More informationIntroduce C# as Object Oriented programming language. Explain, tokens,
Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation
More information.Net Technologies. Components of.net Framework
.Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.
More informationIntroduction to C# Applications
1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationOutline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor
Outline EDAF50 C++ Programming 4. Classes Sven Gestegård Robertz Computer Science, LTH 2018 1 Classes the pointer this const for objects and members Copying objects friend inline 4. Classes 2/1 User-dened
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationC#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations
, 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationHierarchical inheritance: Contains one base class and multiple derived classes of the same base class.
1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationC # Language Specification
C # Language Specification Copyright Microsoft Corporation 1999-2001. All Rights Reserved. Please send corrections, comments, and other feedback to sharp@microsoft.com Notice 1999-2001 Microsoft Corporation.
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More information3. Basic Concepts. 3.1 Application Startup
3.1 Application Startup An assembly that has an entry point is called an application. When an application runs, a new application domain is created. Several different instantiations of an application may
More informationAppendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.
A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler
More informationContents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix
PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationInstantiation of Template class
Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationLanguage Specification
# Language Specification File: C# Language Specification.doc Last saved: 5/7/2001 Version 0.28 Copyright? Microsoft Corporation 1999-2000. All Rights Reserved. Please send corrections, comments, and other
More informationAxivion Bauhaus Suite Technical Factsheet AUTOSAR
Version 6.9.1 upwards Axivion Bauhaus Suite Technical Factsheet AUTOSAR Version 6.9.1 upwards Contents 1. C++... 2 1. Autosar C++14 Guidelines (AUTOSAR 17.03)... 2 2. Autosar C++14 Guidelines (AUTOSAR
More informationTokens, Expressions and Control Structures
3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type
More informationLecture Topics. Administrivia
ECE498SL Lec. Notes L8PA Lecture Topics overloading pitfalls of overloading & conversions matching an overloaded call miscellany new & delete variable declarations extensibility: philosophy vs. reality
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationObject-Oriented Programming
Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object
More informationAxivion Bauhaus Suite Technical Factsheet MISRA
MISRA Contents 1. C... 2 1. Misra C 2004... 2 2. Misra C 2012 (including Amendment 1). 10 3. Misra C 2012 Directives... 18 2. C++... 19 4. Misra C++ 2008... 19 1 / 31 1. C 1. Misra C 2004 MISRA Rule Severity
More informationIEEE LANGUAGE REFERENCE MANUAL Std P1076a /D3
LANGUAGE REFERENCE MANUAL Std P1076a-1999 2000/D3 Clause 10 Scope and visibility The rules defining the scope of declarations and the rules defining which identifiers are visible at various points in the
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More informationCPSC 427a: Object-Oriented Programming
CPSC 427a: Object-Oriented Programming Michael J. Fischer Lecture 16 November 1, 2012 CPSC 427a, Lecture 16 1/29 Unicode Characters and PS7 Name Visibility CPSC 427a, Lecture 16 2/29 Unicode Characters
More informationPOLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE
Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public
More information10. Functions (Part 2)
10.1 Overloaded functions 10. Functions (Part 2) In C++, two different functions can have the same name if their parameters are different; either because they have a different number of parameters, or
More informationPOLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors
POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual
More informationC# Language Specification
Standard ECMA- December 00 Standardizing Information and Communication Systems C# Language Specification. Phone: +.0.00 - Fax: +.0.0 - URL: http://www.ecma.ch - Internet: helpdesk@ecma.ch Brief history
More informationObject-Oriented Programming in C# (VS 2015)
Object-Oriented Programming in C# (VS 2015) This thorough and comprehensive 5-day course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes
More informationCS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)
CS/B.TECH/CSE(New)/SEM-5/CS-504D/2013-14 2013 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers
More informationOperators and Expressions
Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions
More informationC++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017
C++\CLI Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017 Comparison of Object Models Standard C++ Object Model All objects share a rich memory model: Static, stack, and heap Rich object life-time
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationMicrosoft. Microsoft Visual C# Step by Step. John Sharp
Microsoft Microsoft Visual C#- 2010 Step by Step John Sharp Table of Contents Acknowledgments Introduction xvii xix Part I Introducing Microsoft Visual C# and Microsoft Visual Studio 2010 1 Welcome to
More informationIncreases Program Structure which results in greater reliability. Polymorphism
UNIT 4 C++ Inheritance What is Inheritance? Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the
More informationProgramming Languages Third Edition. Chapter 7 Basic Semantics
Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol
More informationIntroduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language
Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup starting in 1979 based on C Introduction to C++ also
More informationModern Programming Languages. Lecture Java Programming Language. An Introduction
Modern Programming Languages Lecture 27-30 Java Programming Language An Introduction 107 Java was developed at Sun in the early 1990s and is based on C++. It looks very similar to C++ but it is significantly
More informationMicrosoft Visual C# Step by Step. John Sharp
Microsoft Visual C# 2013 Step by Step John Sharp Introduction xix PART I INTRODUCING MICROSOFT VISUAL C# AND MICROSOFT VISUAL STUDIO 2013 Chapter 1 Welcome to C# 3 Beginning programming with the Visual
More informationISO/IEC INTERNATIONAL STANDARD. Information technology Programming languages C# Technologies de l'information Langages de programmation C#
INTERNATIONAL STANDARD ISO/IEC 23270 Second edition 2006-09-01 Information technology Programming languages C# Technologies de l'information Langages de programmation C# Reference number ISO/IEC 2006 This
More informationAbsolute C++ Walter Savitch
Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationIntroduction to C++ with content from
Introduction to C++ with content from www.cplusplus.com 2 Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup
More informationJava and C# in Depth
Chair of Software Engineering Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exercise Session Week 4 Chair of Software Engineering Don t forget to form project groups by tomorrow (March
More informationregister lock_guard(mtx_); string_view s = register to_string(42); We propose register-expression to grant the temporary objects scope lifetimes.
Doc. no. P0577R0 Date 2017-02-02 Reply-to Zhihao Yuan < zy@miator.net > Audience Evolution Working Group Keep that Temporary! Motivation Introduction Design Decisions What It Is Register expression is
More informationOperator Dot Wording
2016-10-16 Operator Dot Wording Bjarne Stroustrup (bs@ms.com) Gabriel Dos Reis (gdr@microsoft.com) Abstract This is the proposed wording for allowing a user-defined operator dot (operator.()) for specifying
More informationStream Computing using Brook+
Stream Computing using Brook+ School of Electrical Engineering and Computer Science University of Central Florida Slides courtesy of P. Bhaniramka Outline Overview of Brook+ Brook+ Software Architecture
More informationArgument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.
Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar
More informationConcurrent Programming in the D Programming Language. by Walter Bright Digital Mars
Concurrent Programming in the D Programming Language by Walter Bright Digital Mars Introduction What is sequential consistency across threads? What are the problems with it? D features that mitigate those
More informationQUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?
QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationThe Decaf language 1
The Decaf language 1 In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance
More informationObject-Oriented Programming in C# (VS 2012)
Object-Oriented Programming in C# (VS 2012) This thorough and comprehensive course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes the C#
More informationThe Decaf Language. 1 Lexical considerations
The Decaf Language In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance
More informationPoints To Remember for SCJP
Points To Remember for SCJP www.techfaq360.com The datatype in a switch statement must be convertible to int, i.e., only byte, short, char and int can be used in a switch statement, and the range of the
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and
More informationChapter 17 vector and Free Store. Bjarne Stroustrup
Chapter 17 vector and Free Store Bjarne Stroustrup www.stroustrup.com/programming Overview Vector revisited How are they implemented? Pointers and free store Allocation (new) Access Arrays and subscripting:
More informationPage 1. Stuff. Last Time. Today. Safety-Critical Systems MISRA-C. Terminology. Interrupts Inline assembly Intrinsics
Stuff Last Time Homework due next week Lab due two weeks from today Questions? Interrupts Inline assembly Intrinsics Today Safety-Critical Systems MISRA-C Subset of C language for critical systems System
More informationCS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification
CS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification Written by Julie Zelenski and updated by Jerry Cain and Keith Schwarz. In this course, we will write a compiler for a simple object oriented
More informationDecaf Language Reference Manual
Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented
More informationCSCE 314 Programming Languages. Type System
CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be
More informationWhat are the characteristics of Object Oriented programming language?
What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is
More informationJAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 2 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA
More informationCS304 Object Oriented Programming Final Term
1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing
More informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED
More informationCSE 307: Principles of Programming Languages
CSE 307: Principles of Programming Languages Variables and Constants R. Sekar 1 / 22 Topics 2 / 22 Variables and Constants Variables are stored in memory, whereas constants need not be. Value of variables
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationIntroduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.
Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and
More informationThe SPL Programming Language Reference Manual
The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming
More informationC++ (Non for C Programmer) (BT307) 40 Hours
C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular
More informationUpcoming Features in C# Mads Torgersen, MSFT
Upcoming Features in C# Mads Torgersen, MSFT This document describes language features currently planned for C# 6, the next version of C#. All of these are implemented and available in VS 2015 Preview.
More informationC++ Coding Standards. 101 Rules, Guidelines, and Best Practices. Herb Sutter Andrei Alexandrescu. Boston. 'Y.'YAddison-Wesley
C++ Coding Standards 101 Rules, Guidelines, and Best Practices Herb Sutter Andrei Alexandrescu 'Y.'YAddison-Wesley Boston Contents Prefaee xi Organizational and Poliey Issues 1 o. Don't sweat the small
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More informationPES INSTITUTE OF TECHNOLOGY
Seventh Semester B.E. IA Test-I, 2014 USN 1 P E I S PES INSTITUTE OF TECHNOLOGY C# solution set for T1 Answer any 5 of the Following Questions 1) What is.net? With a neat diagram explain the important
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching
More informationJava Fundamentals (II)
Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class
More informationInterview Questions of C++
Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationGetting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32
Contents 1 2 3 Contents Getting started 7 Introducing C# 8 Installing Visual Studio 10 Exploring the IDE 12 Starting a Console project 14 Writing your first program 16 Following the rules 18 Summary 20
More informationMISRA-C. Subset of the C language for critical systems
MISRA-C Subset of the C language for critical systems SAFETY-CRITICAL SYSTEMS System is safety-critical if people might die due to software bugs Examples Automobile stability / traction control Medical
More information2 ADT Programming User-defined abstract data types
Preview 2 ADT Programming User-defined abstract data types user-defined data types in C++: classes constructors and destructors const accessor functions, and inline functions special initialization construct
More informationFriendship in Service of Testing
Friendship in Service of Testing Gábor Márton, martongabesz@gmail.com Zoltán Porkoláb, gsd@elte.hu 1 / 47 Agenda Introduction, principals Case study Making the example better Vision 2 / 47 Functional Programming
More informationThis tutorial has been prepared for the beginners to help them understand basics of c# Programming.
About thetutorial C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its.net initiative led by Anders Hejlsberg. This tutorial covers basic C# programming
More informationAP Computer Science Chapter 10 Implementing and Using Classes Study Guide
AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationBasic Types, Variables, Literals, Constants
Basic Types, Variables, Literals, Constants What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet) But some machines had 7, or 9, or... A word is the basic
More informationM.C.A. (CRCS) (Sem.-IV) Examination May-2014 Paper: CCA Net Framework and C# Faculty Code: 003 Subject Code:
1~lljm3 003-007403 M.C.A. (CRCS) (Sem.-IV) Examination May-2014 Paper: CCA-4003 -.Net Framework and C# Faculty Code: 003 Subject Code: 007403 Time: 2'1z Hours] [Total Marks: 70 I. Attempt the following
More informationAnatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?
Anatomy of a Compiler Program (character stream) Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Semantic Analysis Parse Tree Intermediate Code Generator Intermediate Code Optimizer Code Generator
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions
More information