1.4 principles of programming Flashcards

1
Q

what is a class (IN OOP)

A

a template defining methods and attributes used to make objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

inheritance

A

when a new class is created that is based on another class and it can take the methods and attributes of the parent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

protected

A

only be accessed by methods in the class and these can be inherited (#)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

private

A

can only be accessed by methods in the class but these can’t be inherited

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

why is BNF preferable to ordinary English when defining the syntax of a computer language

A

it is unambiguious

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is the purpose of BNF

A

is used to describe (unambiguously) the syntax of a programming language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

explain the purpose of programming paradigm

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is a procedural language

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

when are procedural languages used

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

examples of procedural language

A

C and Pascal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is an event driven program

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

advantage of event driven programming

A

very effective when an application needs rapid development of a GUI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is an example of multi-paradigm languages and the advantage of them

A
  • very versatile and can be used in many different ways
    example : python
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what do compliers translate and what do they do

A
  • high level language into machine code
  • they produce a standalone executable file or package
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

advantages of compliers

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

disadvantages of compliers

A

-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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

examples of complied languages

A

Java
C++

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

what do interpreters translate

A

-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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

what must you have to run an interpreted application

A

the source code
this means the intellectual property is difficult to manage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

advantages of interpreters

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

do the one about many lines of machine code

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

explain the ambiguities in natural language syntax

A
  • 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
23
Q

explain the ambiguities in computer language syntax

A
  • 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.
24
Q

what would the problem be if there was ambiguity in computer language syntax

A
  • it would be impossible to translate into machine code
25
Q

describe ambiguity

A
  • is an uncertainty of meaning in which different interpretations are possible
26
Q

why must high level languages be unambiguious

A

so there is only one way to interpret each program statement and therefore enable accurate translation into machine code

27
Q

what are the difficulties programmers have had to overcome to create a natural language interface

A
  • two words that sound the same (homonyms)
  • dialect / accents
    -use of proper nouns
    -words from other languages in common use
    -voice patterns
28
Q

describe the differences between high level and low level languages

A

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)

29
Q

situations where low level is used

A
  • 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
30
Q

why is it useful to standardise computer languages

A
  • 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
31
Q

why is it difficult to standardise

A
  • different manufactures / developers approaching problem differently - may not be keen to share for commercial reasons
32
Q

describe the advantages and disadvantages of an object oriented paradigm

A

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

33
Q

what is meant by object and what its relationship with class (in OOP)

A
  • a data field that has unique attributes and behaviours
  • an object is in the instance of a class
34
Q

what is meant by the tern method and what is its relationship with object

A
  • 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
35
Q

explain the concept of inheritance

A
  • 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.
36
Q

what are the fundamental concepts of object-oriented programming

A
  • inheritance
  • abstraction
  • encapsulation
  • polymorphism
  • object hierarchy
37
Q

describe OOP

A
  • 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

38
Q

what is encapsulation

A
  • 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
39
Q

what is polymorphism

A
  • 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
40
Q

describe the advantages of using a procedural language to write a program based on an algorithm

A
  • 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
41
Q

what is the nature of a procedural language

A
  • 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
42
Q

what is the nature of a non procedural language

A
  • 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)
43
Q

when are non procedural languages used

A
  • 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
44
Q

explain the features of the mark-up language programming paradigm

A
  • 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

45
Q

disadvantages of procedural languages

A
  • 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
46
Q

features of a traditional procedural language

A
  • 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
47
Q

disadvantage of an event driven application and why

A
  • difficult to debug because there are multiple starting points depending on the event that occurs
48
Q

explain the features of visual programming languages

A
  • 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#

49
Q

advantages of OOP

A
  • 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)
50
Q

what is abstraction

A
  • 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
51
Q

what is a meta language

A
  • a language which describes the syntax of another language

-an unambigiuous computer language

  • example: BNF and syntax diagrams
52
Q

what is an object

A

a particular instance of a class

53
Q

what is an attribute

A

a property of characteristic of an entity

54
Q

what is instantiation

A

the realisation of a predefined object