Asking questions

Asking questions

Rails girls london 2015 slides

81b61875e41eaa58887543635d556fca?s=128

Frederick Cheung

May 16, 2015
Tweet

Transcript

  1. On asking questions @fglc2

  2. Sooner or later, trouble will strike

  3. Sooner or later, trouble will strike Don’t Panic

  4. None
  5. 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?
  6. 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
  7. None
  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. 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>'
  11. 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>'
  12. 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>'
  13. 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>'
  14. 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>'
  15. None
  16. None
  17. 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
  18. 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!)
  19. None
  20. I’m still stuck

  21. Help the reader recreate your problem

  22. Simplify the problem • Try to recreate a small self

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

    What did you expect it to do (& why?)
  24. None
  25. 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
  26. 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
  27. Further reading • http://www.catb.org/esr/faqs/smart-questions.html • http://stackoverflow.com/help/how-to-ask • http://stackoverflow.com/help/mcve