How to ask for help: Difference between revisions

From Computer Science Wiki
No edit summary
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
Having problems is normal. '''If you do not learn how to solve your own problems, life will be difficult for you.'''  
Having problems is normal. '''If you do not learn how to solve your own problems, life will be difficult for you.'''  


=Step One: Why can't you write this program?=
== Why can't you write this program?==


When you first realize you have a problem, follow these steps:
When you first realize you have a problem, understand '''what kind of problem are you having'''?


With gratitude to  and permission from Stephen Hughes (Coe College) and Philip East (University of Northern Iowa)<ref>http://www.cs.uni.edu/~east/</ref>
With gratitude to  and permission from Stephen Hughes (Coe College) and Philip East (University of Northern Iowa)<ref>http://www.cs.uni.edu/~east/</ref>
Line 15: Line 15:
| I can’t describe how to get a solution  || [[#Algorithmic thinking; problem decomposition]]
| I can’t describe how to get a solution  || [[#Algorithmic thinking; problem decomposition]]
|-
|-
| I don’t know all the details || Real world problems require research
| I don’t know all the details || [[#Real world problems require research]]
|-
|-
| I can solve it by hand, but I don’t know how to code  it. || New Language Features
| I can solve it by hand, but I don’t know how to code  it. || [[#New Language Features]]
|-
|-
| I can do it || Explore efficiency or professionalism.
| My code isn't working the way it should || [[#Debug your code]]
|}
|}


== Requirements Gathering ==
== Requirements Gathering ==


Do you understand ''EVERY. SINGLE. WORD.''' in the problem?  
Do you understand '''EVERY. SINGLE. WORD.''' in the problem? In this case the student needs to: re-examine the problem statement identifying specific problem requirements;  play with the problem—draw pictures of interaction, imagine inputs & outputs, ...;  seek clarification from the originator of the problem, etc.<ref>http://www.cs.uni.edu/~east/PcPI/prose_2.0.php</ref>


== Algorithmic thinking; problem decomposition ==
== Algorithmic thinking; problem decomposition ==
If you don't know how to get to a solution, break the problem down into smaller parts.
A common obstacle novice programmers face arises from difficulty with problem representation—making the problem more concrete in their minds. They are not familiar with thinking abstractly in terms of variables and operations on them. The action in this case is to specify the desired outcome and begin problem decomposition from that point. Produce questions that indicate intermediate outcomes desired or information needed. Identify data needed to produce the outcomes and where that data must come from;  necessary manipulations of the data;  tasks that may need to be repeated or occur depending on some aspect of the problem data;  etc.<ref>http://www.cs.uni.edu/~east/PcPI/prose_2.0.php</ref>


* Create a diagram of the problem
* Create a diagram of the problem
Line 35: Line 39:
* Explain the problem to a friend
* Explain the problem to a friend


== Real world problems require research ==


== Checklist for solving problems when coding in PHP ==
In this case domain knowledge is lacking. Additional research on the task is required. It may be as simple as looking up a formula;  finding rules for a game; etc.<ref>http://www.cs.uni.edu/~east/PcPI/prose_2.0.php</ref>
 
[[Media:PHP problem solving checklist - Google Docs.pdf | Click here for our checklist]]
 
== How to view our linux error log ==
 
I encourage students to open a new tab in their terminal window. The command below will create a running list of errors. To escape from the output, push the key combination control-C.
 
  tail -f /var/log/php/error.log
 
== Problem Solving Steps ==
 
# Repeat the problem, make the error happen again
# '''TRACE''' the problem ([https://en.wikipedia.org/wiki/Tracing_(software) click here to learn more]) - Insert a notification or breakpoint into your program
# Google the problem in general terms. For example: <code>python how to import a calendar</code>
# Re-read your code (sometimes, reading backwards helps you see little errors)
# Use your [[debugging tools]]
# Ask a friend
# Google the specific error message your program is raising
# Don't ask your teacher until you have a '''very specific''' question.
 
== Click the image to learn about common mistakes ==


[[File:Problem.png|center|thumb|caption|You must learn to solve problems.]]
For example, if you are asked to solve a problem by writing a program which converts celsius to fahrenheit you might have not memorized the formula.  


== New Language Features ==
A different kind of research is needed here. Students can look up information in their text books or online about how some task can be accomplished in the programming language being used. Alternatively, they may need to consider how the problem can be represented using numbers and string or collections of them. Or, they might be encouraged to ask the teacher!<ref>http://www.cs.uni.edu/~east/PcPI/prose_2.0.php</ref>


== Other problem-solving strategies ==
== Debug your code ==
There are different techniques you can use when debugging your code. Most of them can be distilled to a few simple techniques:


# Look for error or warnings in your IDE (probably the fastest way to spot silly mistakes)
# Read error logs (on our server in Germany, they are in /var/log/php/error.log) You should type: <syntaxhighlight lang="php" inline>tail -f /var/log/php/error.log</syntaxhighlight>
# Walk away for a few minutes
# Walk away for a few minutes
# Take a short break (2 to 3 minutes)
# Explain the problem to a friend
# Physically stretch your body
# Write out a small sample and walk through your code by hand, step by step, running each operation on your sample input to see if the final output is what you expect. <ref>https://www.interviewcake.com/</ref>
# Explain the problem to a little rubber duck (really)
# [[Media:PHP problem solving checklist - Google Docs.pdf | Click here for a PHP debugging checklist]]
# [[Media:Problem.png|Click here for a python debugging flowchart .]]
# Make your bug lonely! Isolate your code into small chunks to understand what might not be working
# Make sure every variable contains a value. In php, you can dump all variables by using the <syntaxhighlight lang="php" inline>print_r(get_defined_vars());</syntaxhighlight> function in your code.


== References ==
== References ==

Latest revision as of 15:19, 1 January 2020

Having problems is normal. If you do not learn how to solve your own problems, life will be difficult for you.

Why can't you write this program?[edit]

When you first realize you have a problem, understand what kind of problem are you having?

With gratitude to and permission from Stephen Hughes (Coe College) and Philip East (University of Northern Iowa)[1]

Type of problem What you need to do to solve it
I don't understand the problem #Requirements Gathering
I can’t describe how to get a solution #Algorithmic thinking; problem decomposition
I don’t know all the details #Real world problems require research
I can solve it by hand, but I don’t know how to code it. #New Language Features
My code isn't working the way it should #Debug your code

Requirements Gathering[edit]

Do you understand EVERY. SINGLE. WORD. in the problem? In this case the student needs to: re-examine the problem statement identifying specific problem requirements; play with the problem—draw pictures of interaction, imagine inputs & outputs, ...; seek clarification from the originator of the problem, etc.[2]

Algorithmic thinking; problem decomposition[edit]

If you don't know how to get to a solution, break the problem down into smaller parts.

A common obstacle novice programmers face arises from difficulty with problem representation—making the problem more concrete in their minds. They are not familiar with thinking abstractly in terms of variables and operations on them. The action in this case is to specify the desired outcome and begin problem decomposition from that point. Produce questions that indicate intermediate outcomes desired or information needed. Identify data needed to produce the outcomes and where that data must come from; necessary manipulations of the data; tasks that may need to be repeated or occur depending on some aspect of the problem data; etc.[3]

  • Create a diagram of the problem
  • Draw a picture of the problem
  • Explain the problem to a rubber duck (really)
  • Forget about a computer; how would you solve this with a pencil and paper?
  • Think out loud
  • Explain the problem to a friend

Real world problems require research[edit]

In this case domain knowledge is lacking. Additional research on the task is required. It may be as simple as looking up a formula; finding rules for a game; etc.[4]

For example, if you are asked to solve a problem by writing a program which converts celsius to fahrenheit you might have not memorized the formula.

New Language Features[edit]

A different kind of research is needed here. Students can look up information in their text books or online about how some task can be accomplished in the programming language being used. Alternatively, they may need to consider how the problem can be represented using numbers and string or collections of them. Or, they might be encouraged to ask the teacher![5]

Debug your code[edit]

There are different techniques you can use when debugging your code. Most of them can be distilled to a few simple techniques:

  1. Look for error or warnings in your IDE (probably the fastest way to spot silly mistakes)
  2. Read error logs (on our server in Germany, they are in /var/log/php/error.log) You should type: tail -f /var/log/php/error.log
  3. Walk away for a few minutes
  4. Explain the problem to a friend
  5. Write out a small sample and walk through your code by hand, step by step, running each operation on your sample input to see if the final output is what you expect. [6]
  6. Click here for a PHP debugging checklist
  7. Click here for a python debugging flowchart .
  8. Make your bug lonely! Isolate your code into small chunks to understand what might not be working
  9. Make sure every variable contains a value. In php, you can dump all variables by using the print_r(get_defined_vars()); function in your code.

References[edit]