Ada95- A brief History.ppt
《Ada95- A brief History.ppt》由会员分享,可在线阅读,更多相关《Ada95- A brief History.ppt(63页珍藏版)》请在麦多课文档分享上搜索。
1、ada-typesI- 1,Ada95: A brief History,1975-1979: strawman-steelman requirements, Pascal is base 1981 : Green wins, becomes preliminary Ada 1983 : ANSI Standard, first validated compiler 1987 : ISO Standard 1990-1994 : Revision Process 1995 : ANSI - ISO Ada 95 Standard 1995 : First validated GNAT comp
2、iler,ada-typesI- 2,Design principles,Software Engineering: programming in the large Readability over writability Rigorous standard for portability Precise semantics Built-in concurrency Strong-Typing: all unsafe code is explicit,ada-typesI- 3,Ada, C+ and Java,Big languages winstrong typing : Ada, C+
3、, JavaGenerics : Ada C+Concurrency : Ada JavaPackages: Ada C+ and JavaAhead of its time in designOut of step in implementationBetween language generations,ada-typesI- 4,Key Goals,Readability : between COBOL and APLstrong typing : compile, dont debugProgramming in the large: package itException Handl
4、ing: Murphy is always rightData abstraction : apples are not orangesObject orientation : Dispatch and inheritTasking : walk, chew gum, etc.Generic units : the easiest reuse is to copyInterfacing : play well with others,ada-typesI- 5,The canonical example,with Text_Io; use Text_Io; procedure example
5、is beginPut_Line (“easier than we thought!”); end;,ada-typesI- 6,A small package,Package Math_Functions isfunction Sqrt (X : Float) return Float;function Exp (Base : Float; Exponent : Float) return Float; end Math_Functions;,ada-typesI- 7,Using the package,with Math_Functions; with Gnat_IO; use Gnat
6、_IO; procedure Example2 isVal : Float; beginget (Val);put (“Sqrt (“); put (Val); put (“) = “);put (Math_Functions.Sqrt (Val);new_line; end;,ada-typesI- 8,Implementing the package,Package body Math_Functions isEpsilon : constant := 1.0e-7;function Sqrt (X : Float) return Float isResult : Float := X /
7、 2.0;beginwhile abs (Result * Result - X ) Epsilon loopResult := 0.5 * (X / Result + Result);end loop;return Result;end Sqrt;. end Math_Functions;,ada-typesI- 9,Abstraction at its best: enumeration types,Trivial Implementation: literals are mapped into successive integersVery common abstraction: lis
8、t of names, propertiesExpressive of real-world domain, hides machine representation type suit is (hearts, diamonds, spades, clubs) ; type direction is (east, west, north, south, lost);Order of list implies that spades hearts, etc.,ada-typesI- 10,Enumeration types and strong typing,type Fruit is (App
9、le, Orange, Grape, Apricot);type Vendor is (Apple, IBM, Compaq);My_PC : Vendor;Dessert : Fruit;My_PC := Apple;Dessert := Apple;Dessert := My_PC; - ERROR,ada-typesI- 11,Built-in enumeration types,type Boolean is (False, True);type Character is (. - full ASCII.- not expressible in Adatype Wide_Charact
10、er is ( - Unicode, or ISO646,ada-typesI- 12,Array Types,Index is typed:type weekday is (Mon, Tue, Wed, Thu, Fri);type workhours is array (Weekday) of integer;Predefined array:type String is array (Positive range ) of Character;,ada-typesI- 13,Record Types,conventional named fields:type Buffer is rec
11、ordsize : Positive;contents : String (1 100);end record;B1 : Buffer; - can use B1, B1.size, B1.contents (10).,ada-typesI- 14,Access Types,Typed pointers, for type safety and to minimize aliasing:type Handle is access Buffer;Ptr : Handle := new Buffer;Ptr.all is a Buffer.Can write Ptr.size, Ptr.conte
12、nts, etc.,ada-typesI- 15,Abstraction mechanisms,Packages Private types Objects and Inheritance Classes, polymorphism, dynamic dispatching Generic units Concurrency : tasks and protected types,ada-typesI- 16,Packages,A related set of types, constants, and subprogramsSeparate declaration (interface) a
13、nd implementationSupports privacy and data hidingThe single most important idea in software engineering,ada-typesI- 17,A package for stacks,package Stacks istype Stack is private;procedure Push (It : Character; On : in out Stack);procedure Pop (It : Character; From : in out Stack);function Empty (S
14、: Stack) return Boolean; privatetype Stack is recordtop : Integer := 0;contents : String (1 80) := (others = *);end record;end Stacks;,ada-typesI- 18,Object-oriented Programming,Type extension Inheritance and overriding Run-time dispatching Polymorphism Class-wide programming Abstract types and subp
15、rograms,ada-typesI- 19,Type Extension,Mechanism to define new types by enrichment:type Point is tagged recordX_Coord, Y_Coord : Integer;end record;type Pixel is new Point with recordR, G, B : Integer;end record;,ada-typesI- 20,Inheritance,A type has primitive operations: operations that involve the
16、type as a parameter or a returned value. A type extension inherits the primitive operations of its parent. A primitive operation can be redefined and overridden for a descendant type.,ada-typesI- 21,Polymorphism,A class is a family of types with the same ancestor. An object of the class is identifie
17、d at run-time by its tag. Dynamic dispatching uses the tag of the object to determine the operation that applies. A classwide operation applies uniformly to all member of the class:procedure Examine (Thing : in out TClass);,ada-typesI- 22,Generic Units,The basic tool for software reuse. Parameters c
18、an be types, objects, subprograms, packages. Akin to C+ templates. Absence from Java is incomprehensible,ada-typesI- 23,A Generic Package,Generictype T is private; package Stacks istype Stack is private;procedure Push (Thing : T ; On : in out Stack); privatetype Arr is array (1 100) of T;type stack
19、is recordTop : Integer := 100;contents : Arr;end record; end Stacks;,ada-typesI- 24,A Generic Subprogram,Generictype T is private;type Arr is array (Integer range ) of T;with function “ (X, Y : T) return Boolean; procedure Sort (Table : in out Arr);,ada-typesI- 25,The Type Model,Types and Subtypes D
20、eclarations and their scope Objects, constants and variables Scalar types Array types Record types Access types,ada-typesI- 26,Types and Subtypes,A type is a set of values and a group of operations A type declaration specifies static properties of objects A subtype declaration specifies dynamic prop
21、erties of values. Types with different names are distinct and incompatible: name equivalence everywhere, instead of structural equivalence. Subtypes of the same base type are compatible.,ada-typesI- 27,Compile-time vs. run-time,Type properties are enforced by the compiler:x : integer := false; - pro
22、gram rejectedx : positive := f (z); - if f returns an integer, need to check value at run-time,ada-typesI- 28,Built-in subtypes,type Integer is - implementation defined subtype Positive is integer range 1 IntegerLast; - useful attribute subtype Natural is integer range 0 IntegerLast; X : integer :=
23、500; Y : Positive := 2 * X; Z : Natural := - Y; - legal, raises constraint error,ada-typesI- 29,Declarations and Scope,Declarations are elaborated in order Entities become visible at the end of their declaration (usually) Block structure allows arbitrary nesting of declarative regions. Declarations
24、can appear in subprograms packages blocks .,ada-typesI- 30,Blocks,DeclareX : Integer := F (5);Y : Integer := 2 * X;Z : Integer := Y * Z; - Error: prematureX : Float ; - Error: duplicate begindeclareX : Float := Float (Y); - hides outer X beginPut_Line (FloatImage (X);end;end;,ada-typesI- 31,Variable
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ADA95ABRIEFHISTORYPPT
