Too busy sharpening the saw

Post on 29-Nov-2014

727 views 0 download

description

Slides from my presentation at Roots 2011. Watch the recording here: http://vimeo.com/24735626

Transcript of Too busy sharpening the saw

TooBusySharpening

theSaw

I

AM

A

LIAR

!

Move upwards tothe unimportant

Try faking it

The most important thing is

the thing most easily forgotten

Be extravagant

Bridges - build - burn

Consider different fading systems

Courage!

Kanban?

def count_lines(code): current_line_is_code = False line_count = 0 current_state = init for c in code + '\n': input = translate_input(c) current_state, contains_code = state_table[current_state][input] if contains_code: current_line_is_code = True if input == input_n and current_line_is_code: line_count += 1 current_line_is_code = False return line_count

### debug output ###

state_str = ['init', 'code', '/','/*', '//', '*', '"', '\\']

def input_str(input): if input in ' \t': return '<space>' elif input in '\n\r': return '<NL>' else: return '<' + input + '>'

def count_lines_with_debug_output(code): current_line_is_code = False i = 0 line_count = 0 current_state = init for c in code + '\n': print "\n=================" print code[:i+1] + '$\n' print state_str[current_state], '\t', input_str(c), '\t', '=>', current_state, contains_code = state_table[current_state][translate_input(c)] if contains_code: current_line_is_code = True if translate_input(c) == input_n and current_line_is_code: line_count += 1 current_line_is_code = False print state_str[current_state], ('(%s)' % line_count) i+=1 return line_count

import sysif __name__ == '__main__': code = sys.stdin.read() print count_lines_with_debug_output(code)

# statesinit = 0code = 1slash = 2slash_star = 3slash_slash = 4star = 5string = 6bs_string = 7

# inputsinput_w = 0input_n = 1input_l = 2input_slash = 3input_star = 4input_quote = 5input_bs = 6

def translate_input(input): if input == '*': return input_star elif input == '/': return input_slash elif input == '"': return input_quote elif input == '\'': return input_bs elif input in ' \t': return input_w elif input in '\n\r': return input_n else: return input_l

T = Truef = False

# state_table[current_state][input] == (next_state, contains_code?)state_table = [ \ [(init, f), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, T)], \ [(code, T), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, T)], \ [(code, T), (init, T), (code, T), (slash_slash,f), (slash_star, f), (string, T), (code, T)], \ [(slash_star, f), (slash_star, f), (slash_star, f), (slash_star, f), (star, f), (slash_star, f), (slash_star, f)], \ [(slash_slash, f), (init, f), (slash_slash,f), (slash_slash,f), (slash_slash,f), (slash_slash, f), (slash_slash, f)], \ [(slash_star, f), (slash_star, f), (slash_star, f), (init, f), (star, f), (string, T), (slash_star, f)], \ [(string, T), (string, T), (string, T), (string, T), (string, T), (init, T), (bs_string, T)], \ [(string, T), (string, T), (string, T), (string, T), (string, T), (string, T), (string, T)] \]

def count_lines(code): current_line_is_code = False line_count = 0 current_state = init for c in code + '\n': input = translate_input(c) current_state, contains_code = state_table[current_state][input] if contains_code: current_line_is_code = True if input == input_n and current_line_is_code: line_count += 1 current_line_is_code = False return line_count

### debug output ###

state_str = ['init', 'code', '/','/*', '//', '*', '"', '\\']

def input_str(input): if input in ' \t': return '<space>' elif input in '\n\r': return '<NL>' else: return '<' + input + '>'

def count_lines_with_debug_output(code): current_line_is_code = False i = 0 line_count = 0 current_state = init for c in code + '\n': print "\n=================" print code[:i+1] + '$\n' print state_str[current_state], '\t', input_str(c), '\t', '=>', current_state, contains_code = state_table[current_state][translate_input(c)] if contains_code: current_line_is_code = True if translate_input(c) == input_n and current_line_is_code: line_count += 1 current_line_is_code = False print state_str[current_state], ('(%s)' % line_count) i+=1 return line_count

import sysif __name__ == '__main__': code = sys.stdin.read() print count_lines_with_debug_output(code)

# statesinit = 0code = 1slash = 2slash_star = 3slash_slash = 4star = 5string = 6bs_string = 7

# inputsinput_w = 0input_n = 1input_l = 2input_slash = 3input_star = 4input_quote = 5input_bs = 6

def translate_input(input): if input == '*': return input_star elif input == '/': return input_slash elif input == '"': return input_quote elif input == '\'': return input_bs elif input in ' \t': return input_w elif input in '\n\r': return input_n else: return input_l

T = Truef = False

# state_table[current_state][input] == (next_state, contains_code?)state_table = [ \ [(init, f), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, T)], \ [(code, T), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, T)], \ [(code, T), (init, T), (code, T), (slash_slash,f), (slash_star, f), (string, T), (code, T)], \ [(slash_star, f), (slash_star, f), (slash_star, f), (slash_star, f), (star, f), (slash_star, f), (slash_star, f)], \ [(slash_slash, f), (init, f), (slash_slash,f), (slash_slash,f), (slash_slash,f), (slash_slash, f), (slash_slash, f)], \ [(slash_star, f), (slash_star, f), (slash_star, f), (init, f), (star, f), (string, T), (slash_star, f)], \ [(string, T), (string, T), (string, T), (string, T), (string, T), (init, T), (bs_string, T)], \ [(string, T), (string, T), (string, T), (string, T), (string, T), (string, T), (string, T)] \]

puts gets. gsub(/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)|(\/\/.*)/,''). gsub(/^\s*$/,'').gsub(/\n+/,"\n").split(/\n/).length-1

def count_lines(code): current_line_is_code = False line_count = 0 current_state = init for c in code + '\n': input = translate_input(c) current_state, contains_code = state_table[current_state][input] if contains_code: current_line_is_code = True if input == input_n and current_line_is_code: line_count += 1 current_line_is_code = False return line_count

### debug output ###

state_str = ['init', 'code', '/','/*', '//', '*', '"', '\\']

def input_str(input): if input in ' \t': return '<space>' elif input in '\n\r': return '<NL>' else: return '<' + input + '>'

def count_lines_with_debug_output(code): current_line_is_code = False i = 0 line_count = 0 current_state = init for c in code + '\n': print "\n=================" print code[:i+1] + '$\n' print state_str[current_state], '\t', input_str(c), '\t', '=>', current_state, contains_code = state_table[current_state][translate_input(c)] if contains_code: current_line_is_code = True if translate_input(c) == input_n and current_line_is_code: line_count += 1 current_line_is_code = False print state_str[current_state], ('(%s)' % line_count) i+=1 return line_count

import sysif __name__ == '__main__': code = sys.stdin.read() print count_lines_with_debug_output(code)

# statesinit = 0code = 1slash = 2slash_star = 3slash_slash = 4star = 5string = 6bs_string = 7

# inputsinput_w = 0input_n = 1input_l = 2input_slash = 3input_star = 4input_quote = 5input_bs = 6

def translate_input(input): if input == '*': return input_star elif input == '/': return input_slash elif input == '"': return input_quote elif input == '\'': return input_bs elif input in ' \t': return input_w elif input in '\n\r': return input_n else: return input_l

T = Truef = False

# state_table[current_state][input] == (next_state, contains_code?)state_table = [ \ [(init, f), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, T)], \ [(code, T), (init, f), (code, T), (slash, f), (code, T), (string, T), (code, T)], \ [(code, T), (init, T), (code, T), (slash_slash,f), (slash_star, f), (string, T), (code, T)], \ [(slash_star, f), (slash_star, f), (slash_star, f), (slash_star, f), (star, f), (slash_star, f), (slash_star, f)], \ [(slash_slash, f), (init, f), (slash_slash,f), (slash_slash,f), (slash_slash,f), (slash_slash, f), (slash_slash, f)], \ [(slash_star, f), (slash_star, f), (slash_star, f), (init, f), (star, f), (string, T), (slash_star, f)], \ [(string, T), (string, T), (string, T), (string, T), (string, T), (init, T), (bs_string, T)], \ [(string, T), (string, T), (string, T), (string, T), (string, T), (string, T), (string, T)] \]

What’s Happening?

10 Tweet

puts gets. gsub(/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)|(\/\/.*)/,''). gsub(/^\s*$/,'').gsub(/\n+/,"\n").split(/\n/).length-1

andersnoråsi t ’s o n l y c o d e , m o m