Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active September 9, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/37e4cf3bea6541023bab to your computer and use it in GitHub Desktop.
Save JoshCheek/37e4cf3bea6541023bab to your computer and use it in GitHub Desktop.
Notes for how to start a project

Starting a project

Apparently there are rules

  1. You don't know what you're doing. (Therefore: whatever you are doing, it's the wrong thing)
  2. So start with a big high-level test. (because it gives us information as early as possible, and has low inertia, so that it is easier to change our code when we eventually figure out how it is wrong)
  3. Don't go thinking about "how" to do something until:
    • You've thought about "what" you want to do
    • The missing "how" is what's preventing the goal from being achieved (each thing you write, you should be writing it because something is currently blowing up due to it's missingness / incorrectness)
  4. Whatever you use... it exists, and it works.

Start at the top not the bottom

  1. This gives you integration knowledge very early (the most volatile piece)
  2. This means that everything you do, you do because something needs it to exist. Which means you actually need it (vs thinkingthink you need it)

The anatomy of abstraction

(according to me right now, anyway)

  • what - high abstraction, thinking about goals, not details
  • how - sits underneath of the "what", allows the "what" to work.

Each "how" will be a series of "what"s, which will in turn have their own "how".

Example:

# what: method name
# how:  method body
def sort(sorted)
  left.sort(sorted) if left
  sorted << data
  righ.sort(sorted) if right
  sorted
end

Example

# what: left hand side of the equal sign (the variable name)
# how:  right hand side of the equal sign (the the calculation whose result we are naming)

filename = ARGV[0]

Tidbits

# ===== Running shell commands =====
# $ echo hello world
`echo hello world` # => "hello world\n"

# did it succeed or blow up?
$?.success?        # => true

# ===== Changing directories =====
Dir.chdir "/Users/josh" do
  # my program has changed to my home directory in here
end
# here it is in whatever directory it used to be in

# =====  Absolute path  =====
# starting at the directory of the current file,
# go to it's parent directory
File.expand_path("..", __dir__)

# =====  Getting the arguments provided on the command line =====
# if you were to call it like this:
# $ ruby lib/chisel.rb input.md output.html
# then you could get those filenames like this:
input_filename  = ARGV[0]
output_filename = ARGV[1]
# ARGV is an array of strings, specifically,
# the strings you gave it when you ran the program on the command line

# =====  How to not execute that toplevel code  =====
this_is_the_program_and_not_the_test = ($PROGRAM_NAME == __FILE__)

if this_is_the_program_and_not_the_test
  # the stuff that should only run when I call it from the command line,
  # not when the tests require the file (ie things that print,
  # things that read and write files)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment