Skip to content

Instantly share code, notes, and snippets.

@jradness
Last active February 7, 2023 20:16
Show Gist options
  • Save jradness/efde2346627ef74a45c441437182faac to your computer and use it in GitHub Desktop.
Save jradness/efde2346627ef74a45c441437182faac to your computer and use it in GitHub Desktop.
How to ask coding questions

(Copy/Paste template)

Problem:
What research have you done?
What have you tried?
Specific code sample:


Continue Reading 👇

Learning to ask good questions is an important skill you must learn as a developer. At a real job, vague questions won't cut it. If you need help or have a question, you MUST clearly describe what you need help with, what you have tried, and the result you are looking to get. This allows others to accuretley assist you 🙂

Here are a few simple steps to help you become great at asking questions.

📺 VIDEO: How To Ask Good Coding Questions

The Process


  1. Understand the code to the best of your ability.

  • Google unfamiliar concepts. You want to avoid asking a question that you can figure out on your own with a quick Google search.
  • Go through line-by-line and figure out what each line does. Take notes, think about things that might be confusing. Let them sink in.
  1. Clearly describe the problem.

  • Be specific. Provide context. Explain the result you want to see.
  1. Provide the code that illustrates the problem.

  • If you are working on a project, isolate just the part that is broken and share that.
  1. Make sure the code you’re sharing can reproduce the problem.

  2. Check yourself for typos.

  • Nobody wants to look for your typos. For example, if you’re stuck on a lesson in a tutorial, go back to a point where your code worked and redo the lessons from there, making sure that your code continues to work each step of the way. If you get to a point where your code doesn’t work, redo the lesson and double-check for typos.
  1. Explain what you did to troubleshoot the problem.

  • Come up with a list of hypotheses about what the problem might be and then test them methodically. For each hypothesis, explain what you did to test each hypothesis.
  • During this process you might figure out the problem yourself. This is very common.
  1. Explain what you think the problem might be.

  • Based on your tests in the previous step, provide your best guess on what you think the problem might be.
  1. Proofread your question.

  • Read through your question and make sure you’ve provided everything that someone would need to answer it.
  • Edit for clarity. If you think something might be confusing, fix it. If there’s a typo, fix it. If you have typos in your question, people will assume that you have typos in your code.
  1. Send updates and remember this will not be your last question.

  • If you’ve figured out the answer before anyone can respond, then tell people so they don’t waste time looking for an answer you’ve already found.
  • When you get an answer back, take time to digest it carefully and fully understand what the person is saying. Keep in mind they might not actually be right. So you need to verify that their solution works.
  • Thank each person that helped you and remember that they went out of their way to help you 😀

Now that you have some steps to follow, here is a simple template you can use to ask code questions. Please follow this format. This will significantly help others understand your question and help you with a solution.

Question Template


Problem: Clearly describe the problem and explain the context of the issue.
What research have you done? Google unfamiliar concepts. What resources did you find? W3 Schools? MDN web docs?
What have you tried? Explain what you did to troubleshoot the problem.
Specific code sample: Choose one of the four methods to show us your code:

  1. Specific code snippet
  2. File
  3. Github/CodePen link
  4. Loom video (must include audio)

Example questions


HTML

Problem: The size attribute on my html input element won’t size the input
What research have you done? I tried googling how to resize input elements but all I found were css solutions.
What have you tried? I tried using a plain number, a number in quotes and a number with px.
Specific code sample:

<input type=”number” size=”20” >

CSS

Problem: How do you make a diagonal background gradient in css?
What research have you done? I googled background gradients but didn’t find any examples on how to make it slanted.
What have you tried? I tried the transform property and offsetting the left side but it didn’t work.
Specific code sample:

<!-- HTML -->
<body>
  <div class="slanted-bg"></div>
</body>
/* CSS */
.slanted-bg {
  background-color: black;
  left: -50;
  height: 150px;
  width: 100%;
  transform: rotate(-40deg);
}

JavaScript

Problem: How do I update nested values in an object of objects with keys?
What research have you done? I googled exactly what I stated in the question above, but am having a hard time knowing what I’m looking for.
What have you tried? I’ve tried using (in this order) Object.assign, object.values and .map Object.values, .map and object.assign.
Specific code sample:

let myObject = {
  "id001": {
    name: "Joe",
    createdAt: {
      nanoSeconds: 745000000,
      seconds: 1645468219,
    },
    updatedAt: {
      nanoSeconds: 0,
      seconds: 1645471800,
    },
  },
}

The output I want:

let myObject {
  "id001": {
    name: "Joe",
    createdAt: 1645468219,
    updatedAt: 1645471800,
  },
}

My function:

Object.assign({}, myObject,
  Object
    .values(myObject)
    .map((nestedObject) =>
      Object.assign({}, nestedObject, {
        ...nestedObject,
        createdAt: nestedObject.createdAt.seconds
    })
  ))

But this generates an array of objects and doesn't keep the original structure.

Clarifying questions

If you want to clarify something, you can simply ask without following the question template 🙂

Example clarification questions:

When would you use an id over a class and vice versa to style an elemement?

Is it better to use px or rem units when working with font sizes?

How many (if/else if) statements are consisdered too many in one statement?

Using Markdown for Code snippets

To denote a word or phrase as code, enclose it in backticks (`). The backtick is located below the Esc button.

Single line code block: Use a backtick (`) before and after the text

Rendered Output: const greeting = "hello"

Multi line code block: Use three backticks (```) before and after the text

Rendered Output:

<html>
  <head>
  </head>
</html>
@Sklutse01
Copy link

Awesome guidelines.

@Austiny31
Copy link

This page will come in handy I'm sure of that.

@MSaadat1
Copy link

Important guidelines.

@VWashingtonCoder
Copy link

Bookmarking now. This is a great guideline!

@SiFAAB
Copy link

SiFAAB commented Oct 29, 2022

Nice guideline

@GEM-Maestro
Copy link

Great info!

@ekennedy81
Copy link

Clear guidelines. Appreciate the video as well. Wonderful resource tool.

@Danniebellee
Copy link

Coding made easy. Nice resource information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment