Programming Techniques Flashcards
What are the 5 common features of an IDE?
Common features of IDEs include:
a. Stepping allowing you to monitor the effect of each individual line of code by executing a single line at a time
b. Variable watch which is sometimes used to pinpoint errors, this is a useful feature to observe how the contents of a variable change in real-time through the execution of a program.
c. Breakpoint IDEs which allows users to set a point in the program at which the program will stop, helping to pinpoint where an error is occurring.
d. Source code editor which aims to make the coding process easier by providing features such as autocompletion of words, indentation, syntax highlighting and automatic bracket completion.
e. Debugging tools: IDEs also provide run-time detection of errors with a guide as to where in the code they are likely to have occurred through line numbers and highlighting
Why local variables can’t be accessed by other subroutines?
Local variables have limited scope and can thus only be accessed within the block of code in which they are defined
- What is a scope?
Scope refers to the section of code where the variable is available
What are the benefits of using local variables?
It is considered good practice to use local variables in subroutines so they different parts of the code are self-contained and not affected by referencing variables with the same name outside of the blocks of code.
What is the use of global variables?
Global variables can be used anywhere in the main body, hence variables declared in the main body are by default global.
Cons of using global variables?
Cons: they can be overwritten and edited unintentionally, they require memory as they are never deleted until the program ends
Which will take precedence a global or a local variable?
A local variable will always take precedence over a global one
How do you implement modular programming?
Modular programming is a programming technique used to split large, complex programs into smaller, self-contained modules that can be split within a team, making a problem easier to understand and approach, simplifying the process of testing and maintenance by isolating each module.
Pros of implementing modular programming?
Pros: modules that are tested can be reused
What in common do procedures and functions have?
Procedures and functions are named block of codes that perform a certain task
What differs procedures from functions?
Procedures do not have to return a value or can return multiple values, functions must return one single value. Procedures are usually given data as parameters, while functions make use of local variables
What are the 2 ways that parameters are passed into a subroutine?
When parameters are passed in a subroutine, they are passed byVal or byRef
Describe what happens when passing a parameter by Val?
Passing a parameter byVal means that it is treated as a local variable, a copy of the value is passed to the subroutine and then discarded at the end, so the value outside of the subroutine is not affected
Describe what happens when passing a parameter by Ref?
Passing a parameter byRef means that the address of the parameter is passed into subroutine, hence the value will be updated at the given address
What is an IDE?
An Integrated Development Environment, or IDE, is a program which provides a set of tools to make it easier for programmers to write, develop and debug code.