1.4 Principles of programming Flashcards
What are meta languages and why are they preferable to using natural English
meta language - a language which describes the syntax of another language (e.g. BNF, syntax diagram)
They are preferable to natural languages as they are unambiguous (sentence has one meaning) which is good for the computer as it needs to know precisely what it is being asked to do when running the program
define syntax
rules of a particular programming language
do bnf questions
do syntax diagram questions
why do programming languages need to be unambiguous and compare to natural language
programming languages need to be unambiguous because:
-computers have to know exactly what it is being asked to do
this is unlike natural languages which are ambiguous
what is a programming paradigm and describe the various paradigms
programming paradigm - a fundamental structure and approach of a programming language
Types:
Procedural languages - (e.g. C++) written as an ordered set of instructions in a sequence that the computer follows strictly i.e. actions/calculations/selection/iteration/procedure calls in order
Non-procedural languages - (e.g. PROLOG) allows programmers to specify the results they want without having to solve the problem. The program is written as a list of facts and rules. Used for making AI like expert systems.
Event-Driven programming - (e.g. sensors monitoring heat) more often part of a visual programming language, rather than one main subroutine that runs and calls other subroutines, subroutines are written to react to events that occur e.g. button press
Visual Programming - (e.g. visual basic) allows rapid, easy development of professional-looking applications which reduces the need for typical programming
Mark-up languages - (e.g. HTML) not really a programming paradigm, but are a key part of web programming. They add commands to a text document to add further meaning to the text or to structure it (e.g. titles)
Object-oriented programming - ability to combine data and the procedures that use the data into one object, makes the program easier to maintain and understand as the object complexity can be hidden from the program.
NOT MUTUALLY EXCLUSIVE - CAN BE MULTIPLE (e.g.visual basic event driven, visual and object oriented)
Define inheritance
easy to re-use objects in other programs and if necessary create new objects that inherit from other objects without having to recode.
Inheritance enables new objects to take on the properties of existing objects
It is when a new class is created that is based on another class
It can take on the methods and attributes of the parent class
what are the features of a low level language
e.g. assembly language which is usually specific to the type of processor on which the program needs to run
programmers have to write the software in a ‘computer-centric’ way, interacting directly with registers, memory locations, etc.
one low level instruction translates into one machine code instruction, therefore will run faster. They are also programs smaller in size.
Slower and more difficult to program
Uses more cryptic and harder to understand references to memory locations and sections of code (i.e. contains no self-documenting identifiers)
time to convert to machine code (using an assembler) is negligible so can run immediately
what are the features of a high level language
e.g. Java, Python, VB which is available on many different computer architectures.
a compiler translates the source code into machine code
Programmer works in a more ‘human-centric’ way, not requiring direct access to the internal registers of the processor. Closer to spoken english semantics
One line of code translates into many lines of machine code, compiler will generally not translate into as few machine code instructions as a hand-crafted low level program
Easier to program and programs that translate into hundreds of machine code instructions can be rapidly created.
has self-documenting identifiers
requires compilation before code can be run for the first time
easier to create modules that can be re-used and accessed by other parts of the program
allow the use of powerful commands that can perform quite complex tasks
what is standardisation, why is it useful to standardise computer languages and explain the difficulties of doing to
Most languages started out standardised e.g. basic -> then different companies added extra functions and commands to produce various different variants -> e.g. Quick Basic, BBC basic, Visual Basic, etc.
Difficult to agree standards as it takes time, languages need to develop and evolve new features as computers become more powerful and new tech appears
Programming in a popular language is a good idea-> compilers available for many different systems -> companies fan more easily create different versions of their software for different operating systems
Makes it easier for companies to employ programmers that are already skilled in a particular language (programmers are in demand)
define class
is used in object-oriented programming
A template defining methods and attributes used to make objects
define object
The definition of an object is known as a class
is used in object-oriented programming
Are created for things that the program needs to manage e.g. student as an object
Contains:
-data fields (attributes) about the object, such as StockID, Description, etc.
-subroutines/procedures that can be performed on the object e.g. Addstock, DisplayQuantitySold, etc.
define attributes
is used in object-oriented programming
Data fields about the object e.g. stockID, Description, etc.
define methods
Subroutines/procedures that can be performed on the object
E.g. addstock, displayquantitysold
what are the advantages of the object-oriented paradigm
Classes can be reused in future programs and objects can be created that inherit attributes and methods from another object but also gains its own methods such as Add_Exam_Scores
E.g.
Class student inherits from person Method Input_Exam_Results (exam, grade)
End method
..more methods
End class
Private attributes cannot be inherited still however protected can be
Ability to combine data and procedures that use the data together in one object is more intuitive
Encapsulation makes the program easier to maintain and understand (complexity is hidden from program/people that use it)
Abstraction is similar to encapsulation but it means that we allow access only where necessary to the encapsulated data via public or protected methods/attributes
Inheritance: easy to reuse objects in other programs and if necessary create new objects that inherit from other objects without having to recode
E.g. gears in a car are encapsulated (hidden), Abstraction is provided via a gearstick to allow the driver to change gears
In visual languages, new custom controls can be created, inheriting all the methods and attributes of a normal listbox
what does an object consist of?
-Data fields
-Subroutines/Procedure