Comp 1312 Programming 1 Flashcards
What does an f string do?
An f string tells python to sub in all the variables, placed inside the curly brackets into the string
What are the concepts for quality code?
Duplication
Coupling
Cohesion
What is duplication?
An indicator of bad design where code has been copied, harder to maintain.
What is coupling?
Links between separate modules of a program
We aim for loose coupling.
What is loose coupling?
Understanding one item without reading another so we can change one function without changing another.
What is the Noun/Verb method?
Identifying nouns to reveal potential identifiers.
What is C?
Imperative procedural programming language, compiled, statically typed with low-level access.
What is a header file?
How extra modules are imported in C
List some default types in C
INT
FLOAT
DOUBLE
CHAR
_Bool
What are type specifiers?
Keywords that change the amount of data associated with a type
What happens if we initialise a variable at it’s highest value and then add one?
An overflow
What is implicit type conversion?
When a type can be converted to another without specific instructions to do so, e.g integer to float.
What does the Const keyword do?
Makes the variable constant and thus read only
What is the difference between ++n and n++?
Pre-increment and post-increment
What are strings really?
Arrays of chars
What is the placeholder symbol for a string?
%s
What is a structure?
Group elements of different types into one object
What can a structure be considered to be?
A data template
How can a structure be accessed?
structure_name.structure_item;
What does typedef do?
Assigns a new name to existing types and new data types, including structures
typedef int counter;
counter x,y;
T/F A function can return an array.
False
T/F A function can return an structure.
True
T/F You can have nested structures
True
What is a pointer?
A variable that stores a memory address
What could be an issue when memory is not cleared correctly?
Any variables declared get whatever value is at the location they are assigned
What does the sizeof function return?
The number of bytes taken up by the type submitted as it’s operand.
How can you calculate the length of an array?
sizeof(array)/sizeof(type)
What is the symbol for the address operator?
&
What would &var return?
The address the var variable is being stored at.
How can a pointer be declared?
double *p = &var;
Why is a type declared with a pointer?
So the pointer knows how many bytes belong to the variable.
What is the dereference operator?
*p
This is the same as just accessing a variable
Why can a pointer be incremented?
To access multiple elements in an array.
What does the malloc function do?
Allocate a specific amount of bytes in memory and returns the base address of these bytes.
What does the free function do?
Returns the pointer and associated memory back to the heap
What does the realloc function do?
Changes the size of previous allocated memory by inputting a pointer and a new size
What does the calloc function do?
Allocates a certain amount of blocks to the size specified
calloc(n_blocks,sizeof(int))
When do memory leaks occur?
When memory isn’t correctly returned to the heap.
Or when a pointer is reinitialised without freeing the original memory
How can we output to a file?
./myfile > data
How can we input from a file?
./myfile < data
What does EOF stand for?
End of File
Returned by getchar and scanf when the reach the end of their inputs?
What are the f functions?
Function for reading and writing to files, such as:
fopen
fclose
fprint
fscanf
fgets
How are preprocessor statements indicated?
#
What does #define do?
define PI 3.14159268
Replaces every instance of PI with constant 3.14
What happens if you place a hash in front of of the parameter in a preprocessor statement?
It will create a constant string out of the macro-argument
#define str(x) # x
What is a local variable?
Variables only accessible from the scope they are defined in.
T/F Does python support multiple return arguments?
True
What does the global keyword do?
Tells python to look for a global variable and make it accessible from this function
How can list comprehension be accomplished?
[expression for item in collection if condition]
squares = [x**2 for x in range(5)]
[0,1,4,9,16]
What is aliasing?
When two or more variables refer to the same object within memory, instead of copying the list another variable is given the memory address for the list
The copy method solves this problem
What is a ragged list?
A multidimensional list where the sublists have varying lengths
What is a dictionary?
A collection of key-value pairs where each key is unique
How is a file opened in python?
with open(file,mode) as file:
content=file.read()
List some of the possible file access modes
r - read
w - write
a - append
r+ - read and write, file starts at beginning
w+ - read and write, create file if not exists
x - exclusive creation
b - binary file
t - text file
What does the strip function do?
Removes any leading or trailing whitespace characters
How can a csv file be opened?
Using the csv module and csv.reader
csv.dictreader
csv.writer
What are the characteristics of an algorithm?
Performance
Efficiency
Understandability
Scalability
Reusability
Reliability
Elegance
What happens if the specification for a program is inadequate?
Assumptions
What is UML?
Unified Modelling Language
What is a synchronous message?
Requires a response before the interaction can continue?
What is a reflexive message?
A message an object sends to itself
What is an alternative fragment?
When a choice needs to be made between two or more message sequences
What is a loop fragment?
Represents a repetitive sequence
What is an IDE?
Integrated Development Environment.
What could an IDE contain?
A code editor
Build automation
A debugger
Version control
What are common features of a source code editor?
Syntax highlighting
Code completion
Refactoring
Version control
Code search
What are the coding styles for python?
PEP8
PEP257
Give some general good practise coding points
Avoid over doing whitespace
Documentation strings
What are the testing strategies?
Blackbox
Equivalence classes
Boundary value
Cause-effect
Error guessing
Whitebox
Statement coverage
What are some human-based testing methods?
Walkthroughs
Code inspections
User testing
What are some computer-based testing methods?
Print statements
Logging
Pytest
What are the error-locating principles?
Review your code
Describe your problem to others
Debugging tools
Avoid code experimentation
What are the fundamental software engineering activities?
Specification: Define the functionality
Development: Produce the software
Validation: Validate it does as client expected
Evolutions: Meet the client’s changing needs
What is DevOps?
Developers write software
Operators maintain it
DevOps is combining these teams to improve efficiency
A set of processes, ideas and technologies to make software delivery more efficient.
What is continuous integration?
Frequently committing code to a central repository, automate building and testing
What is continuous delivery?
Release software update to end users using automation
Follow continuous integration
What is continuous deployment?
Automates the deployment of code releases
How does Github support continuous integration?
Through github actions
Adding actions that run on every push for testing and other
What are equivalence classes?
The set of input values that have the same result.
What is cohesion?
The degree of which elements of a module are related to each other