Week 2 Resit Flashcards
Relative costs of development vs maintenance?
Maintaining and managing software and its evolution represents more than 90% of the total cost of software
What is a monoloithic program?
Software architecture where all components of an application are tightly integrated into a single codebase, making it a unified and indivsible unit.Tightly linked to the imperative core of Java, consisting of types, values, variables, expressions, assignment, selection, repetition, and allows the expression of every computation.
What is a quantified expression? What are quantifiers?
an expression that involves quantifiers
logical constructs that indicate the extent of the variables in a logical statement
Describe all quantifiers and how they are denoted:
\forall\exists\sum\product\max\min\num_of
What is a procedure in java?
a method or a function ways of wrapping up solutions
Methods vs Functions
Methods have return type void and are used as statements, whilst functions have return type non-void and are used as expressions.
What are parameters? What are arguments?
Parameters are variables in a function or method definition that represent the input values the function expects.
Arguments are the actual values or expressions passed to a function or method when it is called, filling in the parameters.
What is aliasing?
the situation where two or more variables refer to the same object or memory location, allowing changes through one variable to be reflected in the other
Local vs global variables?
Local variables are declared within a specific block and have limited scope, while global variables, in the context of Java, typically refer to class-level variables accessible throughout the class.
Steps in Divide,Conquer and Rule
- Split the problem into subproblems that are each to be solved by a given method (Divide)
- Solve subproblems independently (Conquer).
- Combine subproblem solutions into a total solution (Rule).
Format of a Method Contract:
@param param_name description_of_param@return what_function_returns@pre {@code … precondition}@modifies name_of_modified_var@post {@code … postcondition}@throws some_exception if condition
\old(v) refers to the value of var v at the start of function
\return or \result refers to the value returned by the function
Purposes of a contract
- clearly delineate modules- acts as an interface between user and provider of solution- specifies which problem is solved by pre and post condition- relates invocation and implementation to contract, but not each other directly, as this leads to complexity and errors
Are the preconditions and postconditions concerns or benefits for the users and providers of the solution?
Preconditions are a concern for the users, whilst they are a benefit for the provider.Moreover, postconditions are a benefit for the user, and a concern for the provider.
Test-driven development (TDD)
software development approach where tests are written before the actual code, guiding the development process by ensuring that the code meets the specified requirements and functions correctly
Steps in TDD
- Gather and analyse the requirements to realise.
- Decide which requirement to develop next and what class and method it concerns.
- Specify the module informally in source code, using natural language.
- Specify the module formally, by providing its interface and contract.
- Design and implement a test case; document their motivation in the source code.
- Design and implement module features intended to make the test case pass.
- Test the new module implementation and fix any defects found.
- Where relevant, improve the structure of the code, preserving correcntess by running all test cases again.
- Repeat from step 5, until the entire module has been implemented and tested.
- If, after delivery, a defect is reported for the module in vivo, then first add a test case to defect that defect in vitro and only then repair the defect.
Manual vs automated testing
Manual testing is tedious, time-consuming, and error prone.
Automated tests are more convenenient, faster, and more reliable. Separate code, offer ability to rerun tests and report on results.
Abstraction
simplifying complex systems by focusing on essential properties and hiding unnecessary details, allowing developers to work with high-level concepts and models
How to abstract a monolithic solution:
separate 1 method into multiple parametrising methodusing auxiliary functions
Dependence diagrams
Arrow from box A to box B means A depends on BThus, when code of B changes, code of A may also have to changeCode of A can change without affecting the code of BWhen reusing code of A, also code of/like B is neededWhen reusing code of B, code of A is not neededEach method and variable(s) gets a block in the diagram
Decomposition
process of breaking down a complex system or software application into smaller, more manageable parts or components
Modularisation
structuring a software system into distinct, independent modules or components, each responsible for a specific set of functionalities
Advantages of Divide and Conquer, Decomposition, and Modularisation
Enable solutions of more complex problems
Organise communication about solution domain
Facilitate parallel construction by a team
Improve ability to plan work and track progress
Improve verifiability (allow early review of design, unit testing of separate components, stepwise integration)
Improve maintainability as changes affect fewer componentsImprove possibilities for reuse
Disadvantages of Divide and Conquer, Decomposition, and Modularisation:
Top-level divisions are hard to make, can have big consequences, and need experience and experimenting
Separation often brings overhead and depends on implementation facilities
The result looks bigger but it has explicit structure
Functions cannot be specified/designed/implemented in isolation, but need to be considered in related groups (e.g., classes)
Functional decomposition aims to maximise cohesion. What is cohesion?
the degree to which the elements within a module or component work together to achieve a common purposeHigh cohesion suggests that the elements (functions, classes, etc.) within a module are closely related and focused on a single task, promoting better maintainability and understanding of code, while low cohesion indicates that the elements may not be strongly related, potentially leading to a less maintainable and modular design.
Functional decomposition also aims to minimise coupling. What is coupling?
the degree of dependence or connection between different modules or components in a software systemLow Coupling: Modules are independent, and changes in one module are less likely to affect others. This promotes a more flexible and maintainable systemHigh Coupling: Modules are strongly interconnected, and changes in one module may have a significant impact on others. This can lead to a less flexible and more challenging-to-maintain system
What is the Single Responsibility Principle
Each function should solve a single well-defined problem
Don’t repeat yourself Principle
Each problem should be solved only in one place
Further guidelines for functional decomposition
If specification is difficult to provide, then something is wrong.Specify the right level of data abstraction.Limit the size of the interface, i.e., the number of parameters.Do not pass unnecessary data.Possibly combine parameters.Avoid code duplication.Copy-Paste-Edit is a bad way to reuse code.Use parameters to unify similar code.Functions should have a small/simple/clear implementation:No more than a few dozen linesNested control structures should invite further subdivisionCyclomatic complexity is a good metricCheckstyle measures this and warns when too highRefactoring if it is above 8