Class Note for CS 403 at UA-Programming Languages (4)
Class Note for CS 403 at UA-Programming Languages (4)
Popular in Course
Popular in Department
This 12 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Alabama - Tuscaloosa taught by a professor in Fall. Since its upload, it has received 18 views.
Reviews for Class Note for CS 403 at UA-Programming Languages (4)
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
CS 403 10l10l2002 Writin g assign ment 3 du e today Today Reading Assignment forTuesday Chapter 6 Implementing BlockStructured Languages mum as w mum Finish Chapter 5 Pascal Return to Simplicity The First Society in Computing We Will be having a NEEWEiTHUYS ali OdubElZAiZUUZ al7EIEI 2 m in EE119 Julquot uslu mm um meie details auemme upeeminu HackOll Pineiammine Cumpetitiunr Cash prizes Alsui mm uulwhal irs liketu iieeme Vnmll Cornet Ful meie lMu vlslt us alwww aem ene ua edu mum as w mum Association of Computing Machinery Amie Thumaswill be Shaving HEY expeiienees lVl weiemiessness CS Dept Research Colloquium The Design Rationale of Microsoft s Common Language Infrastructure CLI Yahya Mirza Aurora Borealis So ware 11 AM Friday October 11 2002 Houser 108 Reading Quiz 1 Pascai Scanner Diagrams identi er Unsigned iniegei Scanner Diag Unsigned Number Scanner Diag Unsigned Constant j m ugnud rm I39IILHquot r FI 1ll 1 IT Irrealaltrl adentr rm I 1 ll H a Fall 2002 CS 403 Class Notes Page 7 Statement Block r quotquot39 unsigned integer 9 G Ge 395 0 4 quotf39 I list FUNCTION parameter listJ QI type identifier wl m Scanner Diagram Program PROGRAM identifier o identifier o o m Interacting Design Decisions Two design decisions Wirth made 1 The type of an array includes the details of the dimensions of the array A 1100 array is not the same type as a 160 array A 1100 array is not the same type as a 099 array 2 Pascal enforces strong typing So you can t pass an actual parameter of one type using a formal parameter of another type Fall 2002 CS 403 Class Notes Page 11 Strong Typing and Arrays Assume a function designed to compute some value of an array sum mean std deviation You can t use that function on both these arrays X array 1100 of real Y array 099 of real You must write a different version for every different type of array you have What major principle does this violate Fall 2002 CS 403 Class Notes Page 12 Strong Typing amp Arrays Solution Define a conformant array schema that can be used to specify a formal parameter function sum x array lwb upb integer of real real Now we can call sum on several different arrays We can write the code like this fori lwb to upb do This solves the array parameter problem but what s the tradeoff mzmzc lcbssllutns p 13 Exercise Suppose you had to implement strings as arrays of characters but didn t have the conformant array schema that solved the problem of passing different array types How could you implement strings in Pascal Operations you would need Assignment Concatenation Substn39ng operations nd insert delete Groups of 34 Work 5 minutes then report mzmzc lcbssllutns p m Record Heterogeneous Data Allows grouping of various types of data in a single element Similarto an object butthere are no builtin operations except access to the individual elements ofthe record mzmz c 0330255 um p l Variant Records Sometimes one part of the record depends on another part Consider an employee Name SSN address other stuff Pay Hourly salaried commission enumerated type Hourly amp salaried probably have a single real Commission has a base salary then a commission scale could be several scales Sales lt 1000 9 2 4 for boss son Sales lt 5000 9 3 6 for boss son Sales gt 5000 9 4 8 for boss son Variant part of the record based on Pay mzmzc mcmmm p 15 Variant records Security Problem lfthe program tries to access the scale of a salaried person there s probably some other type of information there ltwill probably be garbage if it is read accordin to the wron format address 39 m enum Hourly rate Salary rate Base rate Step1 Step2 Step3 etc mzmzc mcmmm p m Pascal s Data Structures You would thinkthatthe best source forthe functionality amp features of a software product including a language would be the people who use it But those people can t think outside the box so they come up with old ways So when you re designing a new language or a new interface you need to ask and watch out for what they really need not what they thinkthey want mzmz c 0030255 um p I Responsible Design Principle Do not Q users what they want Find out what they need This is a major principle in HumanComputer Interface design mzmzc lcbssllutns p e19 Pascal s Pointer Types Earliest pointers were just addresses Whatever bit pattern was at that address was assumed to be the right type This leads to random numbers etc In Pascal strong typing is still enforced An integer pointer can t point to a real or a character etc Called typed pointers or pointer binding This means that a pointer variable must contain type information notjust an address Which Principle does this obey mzmz c 0330255 um p an Type Equivalence When are two types equivalent Early Pascal talks about expressions amp variables with identical type Structural equivalence both types have the same structure the same arrangement of sub units arrays records whatever Note that some types are anonymous Name equivalence both variablesexpressions have the same type name More restrictive Simpler to implement ISO Standard Pascal 9 Name equivalence mzmz c 0330255 um Type Equivalence But Whatabout subranges Can we assign a variable that is a subrange of integer to an integer variable What about the other way Strict Name equivalence wouldn t allow either Structural equivalence would allow it Pascal allows an exception to Name equivalence for this case mm c 0330255 um p 54 Design Name Structures Six name binding mechanisms Constant bindings Type bindings Variable bindings Procedure amp function bindings Implicit enumeration bindings Label bindings 53915935 mm c 0330255 um p Constants Aid readability amp maintainability const ltnamegt ltconstantgt Pascal defines several implicitly ie Maxlnt Their value is reduced because in many places Pascal demands a constant not an expression 80 you can t use const ArraySize 100 varA array 0 ArraySize 1 of real mm c 0330255 um p Blocks Procedures Pascal s block is the entire body ofa procedure orfunction It does declare variables constants etc It can t be nested although a procedure or function may be nested in other procedures or functions to any level Pascal s beginend statement is similar to Algol60 s compound statement No variables etc can be declared Simpler name structures More complicated memory structures mzmz c 0330255 um p as 55 Design Control Structures Very Structured Programming intensive Forloop is simpler than Algol While loop has pretest amp posttest variants Midtest requires a GOTO mzmz c 0330255 um p as Case statement is improved Similarto FORTRAN s computed GOTO but much simplerto use Each case clause has a constant label then the code You can put labels togetherto execute the same code Cases can be out oforder Some versions of Pascal included an otherwise case to handle anything not specifically included mzmz c 0330255 um p Parameters Pass by reference amp Pass by value included But original draft of Pascal had Pass as constant instead of Pass by value Any statementthat tries an assignmentto a constant will be flagged as an error by the compiler So the compiler can choose pass by value or reference Whichever is most efficient However aliasing can cause problems here mzmz c 0330255 um p 22 Procedures as Parameters Procedures and functions can be passed as parameters themselves function checkfun function f real x real real But in the original version of Pascal when you pass a function f you only specify the return type not the number and type offs parameters It is impossible forthe compilerto determine if the parameters used are correct mzmz c 0330255 um p e29 Procedures as Parameters It is impossible forthe compilerto determine if the parameters used are correct ISO Pascal corrected this function checkfun function fy real real x real real What are the costs of this additional security mzmz c 0330255 um p u 10 56 Evaluation amp Epilog Pascal met its goals a great teaching language Reliability Simplicity Ef ciency Wirth include features that were well understood and to leave outthose that were still untried and unimplemented proved to be the most successful single guideline Wirth said the second guideline was to publish the definition after the implementation was complete not before mzmzc lcbssllutns p a Criticism of Pascal Most criticisms came from trying things the language was not designed to do ie separate compilation Important lesson The most successful software will always be stretched to fit situations the designer did not plan for Implication Successful software generates more bug reports and change requests than bad software It is used more and users try to make it do more things mzmz c 0330255 um p e2 Evolution of Pascal Extended to do Concurrent programming Support verification Write Operating Systems As Pascal was largely modeled on Algol so most later languages were modeled after Pascal Ada Modula 2 by V rth mzmz c 0330255 um p 11 Third Generation Characteristics Simplicity amp efficiency a retreat from the excessive complexity of the 2 d generation Data structures less machinelike more applicationlike sets records enumerations and they can be nested Name structures can be nested but have new binding and scopedefining constructs Control structures are simplified and more application oriented ie case mzmz c 0330255 um p a End of class Read chapter 6 for Tuesday Check web page for Forum notices mzmz c 0330255 um p as 12
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'