Principles of Programming Flashcards
Procedural Languag
Procedural (imperative languages)
- run sequentially
- series of command run in order
- functions and procedures carry out actions and calculation
- used in traditional programming
- obey ordered instructions
- allows tight control over hardware
- used in programs where the same procedures are used throughout the program
Event Driven
Event Driven
- sit in a loop waiting for user to perform an action/event. When one occurs, a function (known as a listener) will run to process that action.
Programming Paradigms
A programming paradigm is the fundamental structure and approach/method of a programming language.
Visual Language
Visual Language
- use of user interfaces and images to create programming languages rather than just text.
- eliminating the need to remember the syntax of a language, developers can spend more time considering the logic of a problem.
- not ideal for larger or more advanced programs.
- great for starting to learn code.
Mark Up Language
Mark Up Language
- add commands (mark-up) to text files to give meaning to them
- commands specify how images, text and other elements usually found on a webpage are to be presented.
- commands give instructions to the program reading the file on how to interpret and display the text
- common mark up language is HTML
- commands in HTML are tags surrounded by chevrons
- commands are ended using a forward slash inside the tag
- XML (eXtensible mark-up language) is another mark up language that is commonly used in web application
- XML is used for structuring and marking up data for storage rather than information display
- Developer creates own tags and specify their meaning
- Markup languages are commonly combined with other languages such as JavaScript with HTML
Object Orientated
Object Orientated
- develop code based on objects and classes
Objects ~ each object is a computer representation of a real-world thing. A library program,
for example, might contain millions of ‘book’ objects.
Classes — each class is a template for an object, specifying attributes (variables) and methods
that belong to each object. The library program would likely contain only one ‘book’ class,
from which many ‘book’ objects would be created.
Methods - subroutines that belong to a particular class, and that can be run on any
object created from that class. The ‘book’ class, for instance, might have a method
called ‘borrow’.
- Uses objects and classes - include both data and associated processing
- Encapsulation — technical implementation is hidden within the object
- Inheritance — is the means by which properties and methods from a class are
copied to another class - Polymorphism — a form of overloading which allows us to create general object
structures which can be used with a wider range of data types - Enables production of buttons / icons etc. - useful in a visual environment
- A class defines the methods properties (data) 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 interacts with themselves, preventing other kinds of errors, e.g. a programmer cannot set the width of a window to -500
- In some languages, the programmer places objects on forms. These are event-driven languages
- An event, e.g. click a command button, initiates a sequence of code to be executed
- Objects created using object oriented languages can easily be reused in other programs…
Class Diagrams
Attributes/Methods
- (+), Public
- (#), Protected
- (-), Private
Public:
- When you declare a method (function) or a property (variable) as public, those methods and properties can be accessed by:
- The same class that declared it.
- The classes that inherit the above declared class.
- Any foreign elements outside this class can also access those things.
Protected:
- When you declare a method (function) or a property (variable) as protected, those methods and properties can be accessed by:
- The same class that declared it.
- The classes that inherit the above declared class.
- Outsider members cannot access those variables. “Outsiders” in the sense that they are not object instances of the declared class itself.
Private:
- When you declare a method (function) or a property (variable) as private, those methods and properties
can be accessed by:
- The same class that declared it.
- Outsider members cannot access those variables. Outsiders in the sense that they are not object instances of the declared class itself and even the classes that inherit the declared class.
Encapsulation
Encapsulation
- Encapsulation is the concept that attributes of an object are protected and can only be accessed or altered via the methods provided by the class. This improves security as it allows you to protect and make safe the data associated with each object.
- keyword private to show that the following attribute or method is only accessible
from inside the class. Method of class must be used
High and Low Level Code
High-Level
- one high level instruction translates to multiple lines of machine code
- does not give direct access to registers or other CPU features
- instructions to not reflect the design of the processor
Low-level
- each line of code translates to a single line of machine code
- allows developer to manipulate CPU and registers directly
- Instructions are directly linked with instruction set of CPU and are based on the design of the CPU