Flashcards
PLC notes
Cards in this deck (39)
- 1What is a SAFE programming language?No unpredictable behaviour!
TYPE SAFETY, MEMORY SAFETY
Ideally a programming error should lead to an INVALID PROGRAM, so that it will be discovered at compile time not during execution causing damage. - 2Why do we study PLs?-increased ability to learn new PLs
- improved background for choosing a PL
-increased capacity to express programming ideas
-increased ability to design new languages - 3Purpose of PLs?-To interact with us
-To interact with other computers
-To monitor and control mechanical devices
-To manipulate some data - 4PLs should:Represent structured data in computer memory
Perform basic operations on the data
Access IO devices, react to events
Carry out specified actions in some order, depending on the data - 5Desirable attributes for PLs:Expressive
Concise
Safe
Easy to read
Execute efficiently
Support reuse of code via abstraction
Easy to learn
Have good standard libraries - 6What is meant by concise PL? (e.g. HASKELL)No need to write LOTS of boring set-up code and datatypes defined in a straight forward manner.
- 7Easy to read PL (Python) Easy to learnCode is developed jointly by a team, someone else is usually responsible for maintaining the code so it should be easy to read.
Should be able to learn the PL competently within a few months. - 8Execute efficiently PLIf there is an efficient solution, writing it in our language should give us an efficient program.
- 9PL - supporting reuse of code via abstraction - (Java abstract class and inheritance.)When two data structures or activities are similar we should now need to write two descriptions for them, write ONE that can be applied to both cases.
- 10Safe language - JavaNo pointers (dangling pointers/overwriting bits in memory). Java has TYPE SAFETY.
- 11Imperative PLs (Java, C, Ada, PHP, Python)A machine in which there is one or more active entities, (threads) that manipulate data in data store. Programs define the structure of the data - tell the computer what to do step-by-step.
- 12Functional PLs (Haskell)The program and it's data are one and the same thing. To computer means to transform the program (ie data) according to some rules.
Pure functional languages have NO SIDE EFFECTS. - 13Logical PLs (Prolog)Computer is a semi-intelligent agent and a program is a bunch of knowledge
- 14Signed and unsigned integersSigned integers include negative numbers, e.g. -128...127
Unsigned numbers only positive 0...255
Once it reaches the upper limit it is brought back into range, eg. 128 + 128 = 0
128 + 129 = 1 - 15Integer overflowWhen the result of an operation gives an out of range result, this is overflow.
- 16Floating point roundingWhen the result of an operation requires more MANTISSA bits than available, extra bits are truncated, result is ROUNDED
- 17Floating point overflowWhen the exponent does not fit in the available space - can either round to +/- infinity
(very large positive/negative number) - 18Floating point underflowWhen a number is so close to 0, the exponent is a very large negative number. Rounds down to 0.
- 19tiny + huge = huge (rounding) tiny * tiny = 0 (underflow) huge * huge = infinity (overflow) tiny * huge = 1 -huge * huge = -infinity (overflow)ding
- 20Primitive ValuesBooleans
Characters
Symbolic Values - 21C - primitive valuesBoolean 0 = false, all other numbers = true
Characters simplest form using type 'char'
printf = format primitive types as strings
scanf = parse strings that represent primitive values
Symbolic values (define enumerated type) - typedef enum {DETACHED, TERRACE} HouseCategory; - 22Java - primitive valuesBooleans - boolean type
Characters -supports unicode characters
String conversions - toString() method, no general parsing mechanism - Scanner is one option.
Symbolic values - TYPE SAFE enumerated types
e.g enum HouseCategory { DETATCHED, TERRACE} - 23Haskell - primitive valuesDedicated enumerated types = Bool, char
String conversions = show (converts to string) reads (attempts to parse string, if NULL, returns empty string)
Symbolic values = define enum type:
data HouseCategory = DETACHED | TERRACED - 24Recordsfix the number, names and types of record components
- 25TuplesFix the number and types of tuple components.
- 26Union typeDescribe several variants of record structure.
- 27Variable name Variable typeThe identifier used in the program
a classifying type restricting the values - 28Variable scopeThe portion of the program where you can refer to the variable using it's name
- 29Variable lifetimezero, one or more periods of time during execution when a piece of memory exists for storing a value of this variable
- 30Variable referenceThe address of a piece of memory where a value of the variable is stored, either one ref per lifetime or a relative reference that applies to multiple lifetimes.
- 31ProcedureSubprograms whose main purpose is to change the values of some
external memory or variables and/or work with IO devices. - 32Function (pure function)Subprograms whose main purpose is to create and return a single
(perhaps composite) value.
(pure functions have no side effects) - 33Expressionsan expression is anything that can be evaluated to produce a value (does not modify state)
- 34CommandModifies the program state
Internal state = values of all program variables with a current lifetime
External state = I/O devices - 35Parameter passing - COPY PARAMETER PASSINGUsually, the value computed by the actual parameter is copied at the start
of the call to the formal parameter. Sometimes, when the call is finishing, the value
of the formal parameter is copied to the actual parameter - 36Copy in (value parameter)When the subprogram is called, the parameter (a local variable) is assigned the value given by the actual parameter. The parameter can then be used like any
other local variable. Any updates of the
parameter value inside the subprogram have no effect outside the subprogram - 37Copy-out parameter (result parameter)When the subprogram is called, the parameter (local variable) is not initialised. It must be assigned a value during the execution. When subprogram finishes, actual parameter is assigned the final value of the formal parameter.
A copy-out parameter transfers a value in the opposite direction than a copy-in
parameter. Transfer happens at the end of the subprogram call. - 38Copy-in-copy-out (value-result parameter)A combination of the above. The actual parameter must be a variable or another assignable entity (a memory reference). Formal parameter initialised by an assignment from the actual parameter and when the call is finished, the actual
parameter is assigned the final value of the formal parameter. - 39Reference parameter passingThe actual parameter expression has to be a single variable. The actual parameter variable becomes the formal parameter during the call. The parameter’s value is stored in the calling context and no copying of values occurs. Any access within the subprogram to the parameter results in reading from or writing to the actual parameter variable
Information
- Description
- Flashcards on PLC notes, created by Jessica Morgan on 07/02/2020.
- Created by
- Jessica Morgan
- Views
- 0
- Rating