1.4 principles of programming Flashcards
what is a class (IN OOP)
a template defining methods and attributes used to make objects
inheritance
when a new class is created that is based on another class and it can take the methods and attributes of the parent
protected
only be accessed by methods in the class and these can be inherited (#)
private
can only be accessed by methods in the class but these can’t be inherited
why is BNF preferable to ordinary English when defining the syntax of a computer language
it is unambiguious
what is the purpose of BNF
is used to describe (unambiguously) the syntax of a programming language
explain the purpose of programming paradigm
- a programming paradigm is the structure and approach of a programming language
- many different types which are all aimed at solving different programming problems
- these programming languages include sequence commands such as print and input and iteration constructs such as IF and While (unsure on this point)
examples:
procedural
object-oriented
what is a procedural language
- they are executed sequentially and are composed as a series of programming commands and constructs executed on after the other
- it is a imperative language because the programmer controls the flow and state of the computer programming
when are procedural languages used
- when implementing algorithms as they are programmed linearly, they are not suitable for GUI based problems given the event driven nature of these applications
- they are used in traditional programming based o algorithms or a logical step by step process for solving a problem
- used in large (complicated) programs where similar operations may be carried out at varying stages of the program execution
-could be used to write a wide range of programs, such as business applications, stock control, payroll
examples of procedural language
C and Pascal
what is an event driven program
- a form of object-oriented programming which contains objects such as buttons, combo boxes and lists to create a GUI
- uses event listeners to listen for events such as Click or Hover Over to which code can be attached and executes when a specific event occurs
advantage of event driven programming
very effective when an application needs rapid development of a GUI
what is an example of multi-paradigm languages and the advantage of them
- very versatile and can be used in many different ways
example : python
what do compliers translate and what do they do
- high level language into machine code
- they produce a standalone executable file or package
advantages of compliers
- can be executed without the need for the computer to be installed on the destination machine
-the complied application can be distributed to any machine with the OS it was targeted at and it can run multiple times
-protection - source code is not distributed to the end user
disadvantages of compliers
-target a specific platform (eg. IOS or Windows) once complied for this platform, the executable can only be run on that platform
- cannot be complied if they have any errors throughout the source code - this can be difficult to debug without the use of an IDE
examples of complied languages
Java
C++
what do interpreters translate
-one line of the high level source code into machine code line by line
- each line of machine code is executed before the next is translated
-each time the program runs, the code needs to be interpreted again
what must you have to run an interpreted application
the source code
this means the intellectual property is difficult to manage
advantages of interpreters
- crashes at a specific line, meaning it can be easier to de bug
- code can be distributed to machine different OS and platforms, as long as they have installed an appropriate interpreter
do the one about many lines of machine code
explain the ambiguities in natural language syntax
- can be defined as the spoken and written words humans use to communicate with one another
- words can be ambiguous (one word can have more than one meaning) eg ) break
explain the ambiguities in computer language syntax
- can be defined as a set of rules that program statements must follow
- must be unambiguous
- each program statement must have a specific purpose (for example, the break statement must force the program to leave the construct and nothing else.
what would the problem be if there was ambiguity in computer language syntax
- it would be impossible to translate into machine code
describe ambiguity
- is an uncertainty of meaning in which different interpretations are possible
why must high level languages be unambiguious
so there is only one way to interpret each program statement and therefore enable accurate translation into machine code
what are the difficulties programmers have had to overcome to create a natural language interface
- two words that sound the same (homonyms)
- dialect / accents
-use of proper nouns
-words from other languages in common use
-voice patterns
describe the differences between high level and low level languages
high level:
- closer to the semantics of spoken languages
- each line of high level language translates in to multiple lines of machine code
- identifiers can be long and meaningful
-they allow the use of powerful commands that perform quite complex tasks
- allows the creation of modules that can be re-used and accessed by other parts of the program
low level:
- ideal when the execution speed is critical (eg. boot strap loader)
- less resource intensive than high level language programs
- requires less time for translation into machine code
- generally results in smaller executable programs (no more machine code than necessary)
situations where low level is used
- device drivers - low level languages must be used to directly access memory addresses to fully control hardware
- embedded software - software that runs on simple devices using simple microprocessors such as washing machines and microwaves will need direct access to the hardware
- real-time software - simulators or fly by wire systems that require precise processing, timings or accuracy could potentially benefit from using a low-level language
- assembly language can produce more compact code which can be important when placing on a chip
why is it useful to standardise computer languages
- program written in a certain language on one computer/environment is likely to run easily on a different computer/environment
- programmer familiar with the language on one computer/environment is likely to be able to adapt easily to working on a different computer/environment
why is it difficult to standardise
- different manufactures / developers approaching problem differently - may not be keen to share for commercial reasons
describe the advantages and disadvantages of an object oriented paradigm
advantages:
- improved productivity when developing software due to the flexible and extendable nature of the OOP
- software is easier to maintain as OOP is modular and reusable
- development is faster due to the reusable code and libraries
- development is cheaper
- software can be tested more easily making it more high quality
- software is easier to design and model as the real word
disadvantages:
- OOP is difficult and not as ‘logical’ to some developers, it is to create application in
- software can become larger - more code than procedural programs
- OOP programs can run slower than procedural programs as there is more code to execute
- OOP cannot be used for all types of software application such as machine learning and AI
- OOP can be difficult to debug
what is meant by object and what its relationship with class (in OOP)
- a data field that has unique attributes and behaviours
- an object is in the instance of a class
what is meant by the tern method and what is its relationship with object
- a method is a programmed behaviour/sub routine that is included un an object of a class
- a method an only be access data within its own object
explain the concept of inheritance
- inheritance enables new object to take on the properties of existing objects
- a superclass is used as the basis for inheritance. A class that inherits from a superclass is called a subclass
- inheritance defines relationships between classes and organises classes into groups
- inheritance enables classes that are similar to existing classes to be created by indicating differences rather than starting again and thereby allows code to be organised and re-used effectively.
what are the fundamental concepts of object-oriented programming
- inheritance
- abstraction
- encapsulation
- polymorphism
- object hierarchy
describe OOP
- uses objects and classes
- applies the principles of encapsulation, inheritance and polymorphism to aid programming
- enables production of buttons (useful in a visual environment)
- a class defines the methods properties for a group of similar objects
- once an object is created, knowledge of its implementation is not necessary for its use
-objects control how other objects interact with themselves, which prevents other kinds of errors (for example, a programmer can not set the width of a window to -500)
- in event driven languages, the programmer places objects on the form (eg. Vb)
- an event initiates a sequence of code to be executed
-objects created using OOP languages can be easily reused in other programs
what is encapsulation
- technical implementation is hidden within the object
- makes the program easier to maintain and understand as the object complexity can be hidden from the program/people that use it
- for example, the gears in a car are encapsulated
what is polymorphism
- a form of overloading which allows us to create general object structures which can be used with a wider range of data types
- it allows a derived class to provide its own version of a method from the superclass
describe the advantages of using a procedural language to write a program based on an algorithm
- supports a logical step-by-step process
- allows the programmer to define precisely each step when performing a task
- provides close control over the underlying operation of the hardware
- enables similar operations to be carried out at varying stages of the program execution
what is the nature of a procedural language
- they obey ordered instructions
- they carry out actions and calculations
- provides the programmer a way to define precisely each step when performing a task
- allows tight control over the underlying operation of the hardware
what is the nature of a non procedural language
- allows programmers to specify the results they want without specifying how to solve the problem
- are to do with the rules/ making quires/ facts
- the order of facts and rules is unimportant
- the computer can process these facts and rules so as to find the solution to a problem (answers queries)
when are non procedural languages used
- in database interrogation where retrieving answers are more important than the exact steps required to calculate the result
- AI (for example Expert Systems), grammar checking and language translation applications
- PROLOG
explain the features of the mark-up language programming paradigm
- add commands, or mark up, to text document to offer meaning to the text
- the commands give instructions to the program reading the file on how to interpret / format / and display the text
- the developer is free to create their own tags and specify their own meaning to them
- mark up languages are commonly combined with other languages, such as JavaScript with HTML
example 1 :
- one of the most common mark-up language is HTML
- the commands are opened ( for example <h1> ) so that any text that follows will have that format applied to it
- the commands are then ended using a forward slash inside the tag (for example </h1>)
example 2 :
- XML (extensible mark up language) is another mark up language that is commonly used in web applications
- is used for structuring and marking up data for storage rather than information for display
disadvantages of procedural languages
- not ideal for writing GUI based systems , which are not best expressed in a linear algorithm
- due to their complexity, very large programs would be more likely to be developed using an OOP paradigms
features of a traditional procedural language
- text based, no form or design tools
- program starts running ‘Main Procedure’ and calls other procedures from there
- no problem if developing simple text-based user interfaces
- more difficult if designing graphical user interfaces
disadvantage of an event driven application and why
- difficult to debug because there are multiple starting points depending on the event that occurs
explain the features of visual programming languages
- allows graphics user interfaces to be developed rapidly
- easy creation of GUI objects such as forms, buttons and textboxes etc
- rapid development of professional- looking applications
- reduced the need for traditional programming
- programming is event driven
examples:
- scratch
- vb
- c#
advantages of OOP
- the ability to combine data and the procedures that use the data together in one object is a much more intuitive way of thinking about a problem (this can make design easier in the real world)
what is abstraction
- we allow access only where necessary to the encapsulated data via public or protected methods/attributes
- example: provide abstraction via a gear stick to allow the driver to change gears
what is a meta language
- a language which describes the syntax of another language
-an unambigiuous computer language
- example: BNF and syntax diagrams
what is an object
a particular instance of a class
what is an attribute
a property of characteristic of an entity
what is instantiation
the realisation of a predefined object