Skip to content

Instantly share code, notes, and snippets.

@peterjacobson
Last active August 29, 2015 14:24
Show Gist options
  • Save peterjacobson/20a3cce9b4a96933037b to your computer and use it in GitHub Desktop.
Save peterjacobson/20a3cce9b4a96933037b to your computer and use it in GitHub Desktop.
Coding vocabulary, articulation, reasoning & communication
# HOW TO
# articulate, reason, communicate and think about code
# key vocabulary is in '', e.g. 'highest level'
# I find the articulation and vocabulary around coding really important.
# You'll slowly pick it up from videos, stack overflow and tutorials.
# Perhaps it is worth a little focus in its own right...
# I welcome feedback: is this guide helpful or confounding?
# Here we go...
# -----------------example problem------------------------------
let!(:long_array) { [1,2,3]*10 }
# what's this crazy 'let' thing?
# just a 'lazy evaluating' version of long_array = [1,2,3]*10
# => long_array = [3 'element' array]* 10
# => long_array = 30 'element' array
expect(pad!(long_array, 10).length).to eq 30
# OK, so, let's break this down!
# at the 'highest level'...
# => expect().to eq() == testing 'construct'
# => expect('all this stuff').to eq[ual] 30
# or
# => expect(this 'package' to 'evaluate' to 30)
# then
# => [stuff] = 30
# => [pad!().length] = 30
# => [pad!()] . [length()] = 30
# => [object pad! method returns] << [length] = 30
# [whatever object the pad! method 'returns'/'spits out'] we 'call' [length] 'on'
# or
# we 'send the message' [length] to the [pad! method return object].
# to make sense, the object the pad! method 'returns' must 'respond' to the 'message' "length"
# i.e
# [integer].length doesn't make sense
# [array].length makes sense
# => we probably want to return an array from the pad! method
# [pad!(arguments).length] = 30
# what arguments are we 'passing' the pad! method?
# pad!(long_array, 10)
# long_array = 30 'element' array,
# 10 = random integer
# we need
# pad!_return_object.length = 30
# => array.length = 30
# => an array with 30 elements
# !! we've already got a 30 element array = long_array!
# if we make the pad! method just 'spit' the long_array it is 'passed', 'straight back out',
# we'll pass [pad!(arguments).length] = 30
def pad!(array, rand_int)
array
end
# PASS THE TEST!!!
# WHOOP!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment