Conceptual Questions Flashcards
Briefly outline Defensive Programming
Defensive programming is a method of writing code that is designed to protect against bugs. This includes:
1) Building up code bit by bit
2) Using functions copiously
3) Testing as you go against known inputs/outputs
4) Logging each step of your progress
5) Using comments to remind you of any assumptions/cut corners
6) Be on the lookout for common “gotchas”
7) Remembering to focus on readability
Briefly outline the general approach to debugging
1) Reproduce the bug
2) Determine exactly what the problem is
3) Eliminate “obvious” cases (e.g. Is it plugged in?)
4) Divide the process, separating out the parts that work from the part(s) that don’t (“isolate” the problem)
5) When you reach a dead end, reassess your information; then step through the process again
6) As you proceed, make predictions about what should happen and verify the outcome
Briefly outline the Actuality of Software Testing
There are 2 types of software testing:
(1) Execution-based verification, which is where you:
a) Generate and execute set of representative test-cases/inputs, and check the correctness of the output
b) Examples are integration testing” (between system components), or “unit testing” the components of the system
(2) Non-execution-based verification, which is where you detect bugs by eyeballing the code directly, e.g. Code Review or Pair Programming
Briefly describe the ideal specifications of Test Cases
Test cases should be designed independently of the software implementation, and (ideally) be designed to:
1) Test one thing each (e.g. one use case per input type)
2) Test over the spectrum of use cases (often based on the “boundaries” of inputs)
3) Identify and test “corner case” inputs (partly)
Briefly list Common Python Gotchas
1) Equality (==) vs. assignment (=)
2) Printing vs. returning from functions
3) Correct use of types (e.g. False vs. “False”)
4) Incorrect use of function/method (e.g. return list.sort())
5) Spelling and capitalisation
6) Loops and incrementing
7) Conditionals and indentation
8) Namespace problems
9) Incorrect indexing
Briefly Outline what an Iterator is
Definition: An object that keeps track of the traversal of a container. An iterable object will return an interator object when you pass it to the built-in Python function iter(). (This happens automatically with for… in…:) Iterators have a __next__ method that will return the next thing in the iteration, and update their state/memory of where they are up to. You can access it with the built-in function next(). Iterators raise a StopIteration exception when the container is empty.
Why use an iterator?
We would use iterators because there’s less scope for a programmer to make an error: (1) You do not have to initialise the index variable, (2) You do not have to define the end value of the index variable, and (3) you do not have to increment the index variable. Simply create the Iterator using iter and step through it using next. Python will take care of all the indexing. (Similarly, we prefer for over while for a subset of those reasons). Iterators are more memory efficient than storing and indexing a whole iterable: E.g. For … in … Is better than .readlines() … for.. in…
What is the difference between an Iterable and an Iterator?
An iterable describes something that could conceptually be accessed element-by-element, while an iterator is an actual interface (or an object) that allows element-by-element access to an iterable. An iterator: - Has No Random Access - "Remembers" last item seen - has no len() - can be infinite - Traverse exactly once (forwards)
What is the relationship between the “internet” and the “(worldwide) web”?
The internet is the open network by which computers are connected and communication between computers take place; the worldwide web is a subset of the internet used to link hypertext documents.
What is an IP address?
An IP address is a numerical label assigned to each device participating in a computing network that uses Internet Protocol for communication. Each device on the Internet has a unique “IP address”. Devices address each other by their IP, but communicate via “Internet routers”. Communication is from a “client” to a “server”.
IPv4 vs. IPv6: In IPv4, IP addresses are represented as 4 “8-bit” integers, each in the range [0, 255], e.g. 128.250.36.33 is Tim’s main web server, but in IPv6, IP addresses are represented by 8 4-digit hexadecimal numbers.
Static vs. Dynamic: IP addresses can be allocated to a device either “statically” (an IP is reserved for a given device) or “dynamically” (an IP is allocated to a device dynamically when it connects to the Internet)
Local vs. External: IP addresses can also either be “local” (addressable only on a private network) or “external” (directly addressable from anywhere on the internet). In IPv4, a number of address rangers, including 192.168.x.x, are reserved for local IPs. Devices with local IPs can often still access the open Internet through “proxy servers” or “gateways”
What is a Hostname?
A hostname is a hierarchically-organised, human-readable version of a machine address, that maps onto IP addresses using DNS, or the Domain Name System. We use this because humans tend to find sequences of numbers hard to remember, so we use hostnames, such as hum.csse.unimelb.edu.au, made up of (case-insensitive) letters and full stops.
What is a Port?
Machines communicate with other machines over the internet via a collection of numbered “ports”. A port is an endpoint of communication in an operating system, that specifies a process or type of service. A port is identified for each address and protocol by a 16-bit number known as the port number.
What is a URL?
A URL is a “Uniform Resource Locator”, and Internet resources are “addressed” via URL, e.g.: http://nlp.stanford.edu:8080/parser/.
URLs are made up of the following parts: scheme://hostname:port/path, where: (1) scheme = the “protocol” for accessing the file, (2) hostname = the device the file lives on, (3) port = access port (optional), (4) path = where the file lives on the device
With the aid of an example, explain the difference between an HTML “tag”, and an HTML “entity”
A tag pair is used to apply some operation to a document extent (or insert an object of some description at a particular point in the document), whereas an entity is simply a special character. For example <b>text</b> is used to make ‘text’ appear bolded, and < is an entity used to represent the
What is the relationship between a hostname and an IP address?
Hostnames are hierarchically-organised, human-readable versions of machine addresses that map onto IP addresses using DNS, or a ‘Domain Name System’. They are used because humans find it easier to remember than the large sets of numbers that are IP addresses.
Explain what recursion is, what are its elements, and why we use it?
Recursion is where, in a function, we call the same function, and it is used to solve problems in a “divide-and-conquer” manner, breaking down the problem into smaller sub-problems and solving them in the same way as the big problem.
Recursion is generally made up of 2 parts: (1) A recursive function call on smaller inputs, and (2) a reachable base case to ensure the calculation halts. It is used when an iterative solution would involve a level of iterative testing proportionate to the size of the input, which occurs in the Powerset problem, for example.
Recursion has two forms, head recursion, where we recurse first, and then perform some local calculation, and tail recursion, which is where we perform some local calculation, then recurse.
What are the limitations of recursion?
Function calls are computationally expensive, meaning deep recursion comes at a price. There is often an efficient iterative solution to the problem, although there may not be a general iterative solution. Recursion is elegant, but elegance isn’t more readable or efficient.
What are Raster images and vector images?
A raster image is an image represented by colour ‘pixels’ that are mapped from the top-left, row by row, bottom to right, whereas Vector images are represented as points, lines, and curves, on a map, and the order of the vectors is unimportant. Vector images allow us to zoom in, without loss in quality, as the image is determined by points and not pixels.
What are the types of digital image?
Binary images are images that have only 2 possible values for each pixel, 0 for black, and 1 for white.
Grayscale images are images that have a value for each pixel that ranges from 0, for black, to 255, for white.
Colour images are images that have 3 values for each pixel that range from 0 to 255, which represent Red, Green, and Blue (RGB), and can be used to represent any of over 16 million colours (256^3).