26-01-2022
Meta Stuff
First thing this morning was wondering why my SSG server wasn't working, when I hadn't set up the basic interpolation correctly :)
Today's Foci
Focus 1
- Doubles -
- Write and explain douvles
- They're sort of false values that are set up specifically for testing. They can be used in place of running complex processes, and aim to modularise the testing through low-coupling. This improves a tests-specs reliability and flexibility. Seperation of Concerns!
Focus 2
- Bud Forms
- GET. THEM. DONE.
- At least I've made a start, and this blog is helping me retroactively fill them. Also found a markdown to pdf converter through TeXLive LaTeX ( recommended )
- apt list -i will print installed packages; grep "" to search for string
Topic
Domain Modelling and Diagramming
-
Investigate diagramming practice
-
How to use multiple objects in our programmes
-
Understanding how diagramming could support our understanding of a problem
-
Use a diagramming technique to inform how we might design out program before writing our code
Why would we use diagramming?
to Organise code and improve readability
avoid obsolscence
Seperation of Concerns
- SRP - a SRP chould fit into one clause ( no 'and' )
- split a programme multiple distinct parts
Get to see the whole programme instantaneously - can understand the programme and relationships at a glance
A diagram provides clarity for the client ( communicates without jargon )
in professional environments, use whiteboarding to look at diagram modelling - allows to monitor UX / UI / and backend simultaneously?
helps break down the codebase into simpler bite-sized chunks
helps us see relationships between different parts of the programme
Listen to David Bowie - low
As a coach - user So that I know who I am coaching - goal I would like a student to have a name - code representation
have is usually a property/attribute - usually made on initialization
a singular noun tends toward Classism
a pluralisation of a noun might be a property
Modelling User Stories
state - a variable which holds information about an object
podcast - Andrick Uberman - the human lab
Is there an unquestionable logical procedure for modelling user stories
Noun | Property or Owner? |
---|---|
Student | Owner & Property |
Cohort | Owner |
Name | Property |
Students | Property |
Signed In | Property |
Actions | Owned by |
---|---|
Sign in | Student |
Sign out | Student |
Add | Cohort |
list students | Cohort |
count signed in | Student (@@class variables) |
Actions | Property it Reads or Changes |
---|---|
Sign in | @@is_signed_in |
Sign out | @@is_signed_in |
Add | students |
list students | students |
count signed in | @@is_signed_in |
Class Diagrams for user Stories
Class | Students |
---|---|
Properties (instance variables) | name, @signed_in, self.students |
Actions (methods) | sign_in, sign_out, @@count_signed_in_students |
Class | Cohort |
---|---|
Properties (instance variables) | students |
Actions (methods) | Add student, List students |
Go to the stakeholder / client ask the clients intention: what do they want
Noun | Verb | Prop? |
---|---|---|
Noun | Property or Owner? |
---|---|
book | owner |
library | owner |
title | property |
author | property |
Actions | Owned by |
---|---|
Actions | Property it Reads or Changes |
---|---|
Class | CLASSNAME |
---|---|
Properties (instance variables) | |
Actions (methods) | |
Doubles
Perhaps ObjA relies on ObjB, but ObjB is expensive to set up or unreliable
how can we test ObjA without relying on ObjB?
Enter, Doubles; "pretend" objects
We can use a double as a pretend ObjB to interact with our tests for ObjA
Stubbing provides a canned response to a subject
# weather.rb
class Weather
def generate
weather_types = [:rainy, :sunny, :stormy]
# picks a random index in the array and returns the value at that index
weather_types[Kernel.rand(weather_types.length)]
end
end
# weather_spec.rb
describe Weather do
it "creates stormy weather" do
allow(Kernel).to receive(:rand).and_return(2) # stubbing Kernel.rand
expect(Weather.new.generate).to eq(:stormy)
end
end
Spy
Spies are special types that dont require a pre-programmed method
Fake
fakes aren't doubles, but real instances of working classes that uses their implementations - usually contain shortcuts unsuitable for production
Good code is easy to test
Bad code is hard to test
Hard to test code is bad!
Encapsulation
break out programmes into small steps which methods and variables should live in which objects?
low coupling, and high-cohesion!!
Cohesion
Each class should have one purpose or job one goal
One flesh, one bone, one true religion One voice, one hope, one real decision Whoa, whoa, whoa, whoa, whoa, whoa Give me one vision, yeah
A class has high cohesion when everything inside relates to its one purpose, without anything extraneous.
Perfection is minimalism (in OOP)
Useful Tactics
Methods Learned Today
Sharing Explanation Examples
teach any
Plane.new
as really meaning?
Class.new