Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Asking questions

Asking questions

Rails girls london 2015 slides

Frederick Cheung

May 16, 2015
Tweet

More Decks by Frederick Cheung

Other Decks in Programming

Transcript

  1. Isolate the problem • Narrow down ‘It’s not working’ to

    something more specific • “My data isn’t being saved in the database”: is it because of the form, the controller or the model? • Can you recreate the problem in the rails console? • Error messages: which line of code is responsible?
  2. Decode your exceptions • The exception tells you what went

    wrong and where (check just before too) • The stack trace gives you more information on where in your program you are
  3. NoMethodError: undefined method `length' for nil:NilClass # ./app/models/compiled_outfit.rb:310:in `block in

    results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:301:in `collect' # ./app/models/compiled_outfit.rb:301:in `results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:211:in `candidate_outfits' # ./app/models/compiled_outfit.rb:182:in `outfits' # ./app/models/compiled_outfit.rb:423:in `outfits_for_garment' # ./spec/models/compiled_outfit_spec.rb:106:in `block (5 levels) in <top (required)>' # ./spec/spec_helper.rb:142:in `block (2 levels) in <top (required)>' # -e:1:in `<main>'
  4. NoMethodError: undefined method `length' for nil:NilClass # ./app/models/compiled_outfit.rb:310:in `block in

    results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:301:in `collect' # ./app/models/compiled_outfit.rb:301:in `results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:211:in `candidate_outfits' # ./app/models/compiled_outfit.rb:182:in `outfits' # ./app/models/compiled_outfit.rb:423:in `outfits_for_garment' # ./spec/models/compiled_outfit_spec.rb:106:in `block (5 levels) in <top (required)>' # ./spec/spec_helper.rb:142:in `block (2 levels) in <top (required)>' # -e:1:in `<main>'
  5. NoMethodError: undefined method `length' for nil:NilClass # ./app/models/compiled_outfit.rb:310:in `block in

    results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:301:in `collect' # ./app/models/compiled_outfit.rb:301:in `results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:211:in `candidate_outfits' # ./app/models/compiled_outfit.rb:182:in `outfits' # ./app/models/compiled_outfit.rb:423:in `outfits_for_garment' # ./spec/models/compiled_outfit_spec.rb:106:in `block (5 levels) in <top (required)>' # ./spec/spec_helper.rb:142:in `block (2 levels) in <top (required)>' # -e:1:in `<main>'
  6. NoMethodError: undefined method `length' for nil:NilClass # ./app/models/compiled_outfit.rb:310:in `block in

    results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:301:in `collect' # ./app/models/compiled_outfit.rb:301:in `results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:211:in `candidate_outfits' # ./app/models/compiled_outfit.rb:182:in `outfits' # ./app/models/compiled_outfit.rb:423:in `outfits_for_garment' # ./spec/models/compiled_outfit_spec.rb:106:in `block (5 levels) in <top (required)>' # ./spec/spec_helper.rb:142:in `block (2 levels) in <top (required)>' # -e:1:in `<main>'
  7. NoMethodError: undefined method `length' for nil:NilClass # ./app/models/compiled_outfit.rb:310:in `block in

    results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:301:in `collect' # ./app/models/compiled_outfit.rb:301:in `results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:211:in `candidate_outfits' # ./app/models/compiled_outfit.rb:182:in `outfits' # ./app/models/compiled_outfit.rb:423:in `outfits_for_garment' # ./spec/models/compiled_outfit_spec.rb:106:in `block (5 levels) in <top (required)>' # ./spec/spec_helper.rb:142:in `block (2 levels) in <top (required)>' # -e:1:in `<main>'
  8. NoMethodError: undefined method `length' for nil:NilClass # ./app/models/compiled_outfit.rb:310:in `block in

    results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:301:in `collect' # ./app/models/compiled_outfit.rb:301:in `results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:211:in `candidate_outfits' # ./app/models/compiled_outfit.rb:182:in `outfits' # ./app/models/compiled_outfit.rb:423:in `outfits_for_garment' # ./spec/models/compiled_outfit_spec.rb:106:in `block (5 levels) in <top (required)>' # ./spec/spec_helper.rb:142:in `block (2 levels) in <top (required)>' # -e:1:in `<main>'
  9. NoMethodError: undefined method `length' for nil:NilClass # ./app/models/compiled_outfit.rb:310:in `block in

    results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:301:in `collect' # ./app/models/compiled_outfit.rb:301:in `results_to_candidate_outfits' # ./app/models/compiled_outfit.rb:211:in `candidate_outfits' # ./app/models/compiled_outfit.rb:182:in `outfits' # ./app/models/compiled_outfit.rb:423:in `outfits_for_garment' # ./spec/models/compiled_outfit_spec.rb:106:in `block (5 levels) in <top (required)>' # ./spec/spec_helper.rb:142:in `block (2 levels) in <top (required)>' # -e:1:in `<main>'
  10. Gather information • Use your log files: development.log records all

    requests, parameters, SQL queries • Use the debugger to interact with code as it runs • Log extra information def do_thing(parameter) Rails.logger.info "do_thing called with #{parameter}” ... end
  11. Rubber ducking • Walk through each line of your program

    • Explain to an (imaginary) rubber duck what that line is, what the values of variables are, what all the method calls it does are • Forces you to think about your code and any assumptions made (question them!)
  12. Simplify the problem • Try to recreate a small self

    contained example • Remove non pertinent bits • Make sure your simplification hasn’t removed the problem
  13. Banish “it doesn’t work” • What did it do? •

    What did you expect it to do (& why?)
  14. Context is king • Describe what you were attempting -

    don’t lead with a wall of code • Include error messages, stack traces (and how they related to the code you post) • Describe your investigations & attempts to fix this • Provide information such as ruby or rails versions, OS
  15. Where to ask? • Stack Overflow (and other sites in

    the Stack Exchange family) • Mailing Lists, forums • IRC channels • codebar or other face-to-face events