Slide 1

Slide 1 text

On asking questions @fglc2

Slide 2

Slide 2 text

Sooner or later, trouble will strike

Slide 3

Slide 3 text

Sooner or later, trouble will strike Don’t Panic

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

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?

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

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 ' # ./spec/spec_helper.rb:142:in `block (2 levels) in ' # -e:1:in `'

Slide 9

Slide 9 text

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 ' # ./spec/spec_helper.rb:142:in `block (2 levels) in ' # -e:1:in `'

Slide 10

Slide 10 text

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 ' # ./spec/spec_helper.rb:142:in `block (2 levels) in ' # -e:1:in `'

Slide 11

Slide 11 text

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 ' # ./spec/spec_helper.rb:142:in `block (2 levels) in ' # -e:1:in `'

Slide 12

Slide 12 text

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 ' # ./spec/spec_helper.rb:142:in `block (2 levels) in ' # -e:1:in `'

Slide 13

Slide 13 text

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 ' # ./spec/spec_helper.rb:142:in `block (2 levels) in ' # -e:1:in `'

Slide 14

Slide 14 text

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 ' # ./spec/spec_helper.rb:142:in `block (2 levels) in ' # -e:1:in `'

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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!)

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

I’m still stuck

Slide 21

Slide 21 text

Help the reader recreate your problem

Slide 22

Slide 22 text

Simplify the problem • Try to recreate a small self contained example • Remove non pertinent bits • Make sure your simplification hasn’t removed the problem

Slide 23

Slide 23 text

Banish “it doesn’t work” • What did it do? • What did you expect it to do (& why?)

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Further reading • http://www.catb.org/esr/faqs/smart-questions.html • http://stackoverflow.com/help/how-to-ask • http://stackoverflow.com/help/mcve