1/70
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
What meant by the term IDE (integrated development environment)?
A (single) program used for developing programs made from a number of components
What is an IDE?
An integrated development environment (IDE) is a software that helps programmers write, compile, and test their programs.
Entering a program in an IDE
- add line numbers
- automatically indent code
- auto-complete commands
- comment or un-comment a region
Debugging Facilities
- Set a breakpoint in the program which will cause the program to stop on that line
- set a watch on a variable so that it's value is displayed every time it changes
- step through a program one line at a time
- trace the execution of a program - for example display a message every time a particular statement is executed or subroutine is called
Features found in an IDE that will help programmers find any bugs in their code
- debugging tools
- code can be examined while it is running
- step through code
- insertion of a breakpoint
- autocomplete - which will predict the variable / built-in functions
- colour coding - to be able to distinguish between the different parts of each statement
- auto indent - to automatically indent code when selection/iterative statements have been used
What is an algorithm?
A sequence of instructions that can be followed to solve a problem e.g. recipe for a cake, knitting a jumper, directions from a to b
What is pseudocode?
Used to work out steps in a program before sitting down to write the code
What is an identifier?
A name e.g. score, that points to a memory location
What is an assignment?
Assigning a value to the memory location
Naming variables
- descriptive and clear
- use camel case
- avoid ambiguity
- consistency matters
- reverse keywords
- short and sweet
The value of a variable...
Can be changed while the program is running
The value of a constant...
Never changes
What is a nested if statement?
an if statement within an if statement.
The second condition is only checked if the first condition is true
Complex Boolean expressions
AND = returns true if both conditions are true
OR = returns true if either of the conditions are true
NOT = a true expression becomes false and vise versa
If....then...endif
If the condition is true then one or more statements are executed
If...then...else...endif
Often alternative statements need to be executed if the given condition is not met
If...then...elseif...else...endif
Use multiple if...then...else statements to evaluate more than one condition
Switch/case...endswitch
A switch/case statement is the logical equivalent of the if....then...else...endif statement
- it is used to make it easier to code multiple condition checks
- some languages do not have a switch/case statement
What does iteration mean?
repetition
What is iteration?
a sequence of instructions being repeated multiple times
What is branching?
Decides which code is run/only runs code once
While...endwhile loop
The condition is tested upon entry to the loop, it is possible that the instructions inside the loop might not be executed at all if the entry condition is not met
Do...until loop
The statements in the loop are executed before the condition is evaluated
For...next loop
- The for...next loop is termed 'definite iteration', and is used to repeat a block of instructions a specified number of times
- uses a counter variable which is automatically incremented each time through the loop
- optionally, a step value can be specified to make the counter increase or decrease by any integer
Nested for... next loop
Useful for looping through grids in two-dimensional arrays, which will be covered later
What is a function?
A subroutine that can be called to perform a task or operation and aways returns a value. They can be called in an expression or be assigned to a variable
What is a procedure?
A subroutine that can be called by simply writing its name in the code
Difference between functions and procedures
Functions return a value, procedures dont
What is a subroutine?
A named block of code containing a set of instructions
Passing arguments
Arguments in parentheses are used to pass data to a subroutine
Define the term parameter
- (A description of) an item of data
That is passed to a subroutine (when it is called)
- It is used as a variable within the
subroutine
Parameters appear in...
Subroutine definitions
Arguments appear in...
Subroutine calls
What is passing by value?
A copy of the value is passed to the subroutine and discarded at the end, therefore, Its value outside of the subroutine will be unaffected/unchanged
What is passing by reference?
The address of the parameter is given to the subroutine so the value of the parameter will be updated (changed) at the given address
What is scope?
The section of code in which the variable is available
What is the scope of a local variable?
The subroutine in which it is declared
What is a local variable?
A variable that is declared within a function and cannot be accessed by statements that are outside of the function
What is a global variable?
A variable that is defined in the main program and can be used In any subroutine called from the main program
Describe the use of local variables
- Defined within one module...
... accessible only in that module
- Can be used as parameters
- Data is lost at end of module
- Same variable name can be used in
other modules without overwriting
values/causing errors
- Can overwrite global variables (with the
same name)
Advantages of local variables
•The subroutines will be independent of a particular program and can be re-used in different programs
•There is no chance of accidentally changing a variable in the main program that is used in a subroutine or vice versa
•Keep your subroutines self-contained!
•Pass as arguments any values that are needed
Disadvantages of local variables
- Repeatedly creating and destroying local variables within a loop or recursive function can incur unnecessary memory overhead
- excessive use of local variables within deeply nested blocks can lead to code clutter and reduce code readability
Advantages of global variables
- Only need to be declared once
- you don't need to keep passing the parameters between the different modules
Disadvantages of global variables
- They are always stored in memory while the program is running which can use up memory
- makes the program difficult to maintain as it's difficult to understand where variables are changed in the program
What is modular programming?
A programming technique used to split large, complex programs into smaller, self contained modules
Advantages of modular programming
- Programs are more easily and quickly written
- Large programs are broken down into subtasks that are easier to program and manage
- Each module can be individually tested
- Modules can be re-used several times in a program
- Large programs are much easier to debug and maintain
What is a procedural programming language?
A high level language which gives a series of instructions in a logical order
What is recursion?
A programming technique in which a method calls itself.
The essential characteristics of a recursive routine?
- a stopping condition/base case (when met, means the routine will not call itself)
- for input values other than the stopping condition, the routine must call itself
- the stopping condition must be reached after a finite number of calls
Recursive vs iterative
- a recursive routine can cause a 'stack overflow' error
- a recursive routine has fewer lines of code
- a recursive routine is easier to follow
- an iterative routine is faster than a recursive routine
What is a class?
A blueprint for an object. It defines what an object will look like (it's properties/attributes) and what it can do (it's methods)
Three main sections of a class
- Class name
- Attributes
- Methods
Attributes are normally set as...
Private
Methods are usually declared as...
Public
What is encapsulation?
The bundling of data with the methods that operate on and restrict direct access to it
What does encapsulation do?
Wraps the attributes and methods in the class definition, hiding details of the implementation from the user
What does data hiding mean?
A programmer who defines an object in a class cannot directly access or change an attribute of the object, it has to be done via a getter or setter method
What is an object?
an instance (example/case) of a class
What is a constructor?
A method used to create a new object in a class
What is instantiation?
Creating new objects from a class
What is inheritance?
Allows a class to inherit the properties and behaviours of another class
Inheritance can...
Quickly and easily reuse code from a class and extend its attributes and methods without effecting the original code
Subclass
Uses superclass as a basis, but include some more functionality specific to enemies
Over-riding
When a method is redefined in the subclass with the same name and same arguments
What is aggregation?
The ability to store one object inside of another object
Benefits of OOP
- once you define a class, it becomes very easy to reuse that class and create hundreds of objects of that class
- unnecessary details can be abstracted away from in the implementation of the methods (I.e you don't need to know a method works to be able to use it)
- code reuse
- encapsulation reduces code complexity
- easier to modify and maintain
What is polymorphism?
The ability of a programming language to process objects differently depending on their class
Two types of polymorphism
Static and dynamic
Static Polymorphism
Allows you to implement multiple methods of the same name but with different parameters - within the same class (this process is known as overloading)
Dynamic polymorphism
Runtime polymorphism - multiple methods can be defined with the same name and signature in the subclass and superclass. The call to an overridden method are resolved at runtime
Static VS dynamic polymorphism