How do you ask a question? The Smart Way and the Not-So-Smart Way

08 Sep 2020

The Smart Way and the Not-So-Smart way; How do you ask a question?

Whenever anyone needs help, the first thing we do is ask for help. It is only natural that people who cannot figure out the solution after exhausting every possible source will do this in the end. After all, there will be roadblocks that cannot be figured out on your own or even after looking through every probable source. Which is why we must discuss asking questions the smart way versus asking questions the not-so-smart way. In this short yet concise essay, I will show you a smart way to ask a question and a not-so-smart way. Some of these may be simple, but they get straight into the point.

What exactly makes a good question?

The first thing we need to refer to is Eric Steven Raymond and Rick Moen’s article on asking questions the smart way; you want to try and find an answer from either an archive or mailing list, the web, the manual, the FAQ, through inspection or experimentation, through a skilled friend, or in the case of a programmer, through reading source code. At least once you are done exhausting these choices, you can prove that you have in fact tried and that this problem is indeed a bit of a unique problem. Be careful, though, when asking your questions. You should probably consider looking through Stack Exchange before asking any questions, as there are several topics that might have already answered your question.

Questions, the smart way

Stack Overflow is one of the biggest programming communities on the internet. It serves as more than just a place to have your questions answered; it serves as a forum, a site with a number of different answers and approaches to the same question, and a place filled with people who want to reach an end goal. That said, there was one smart question that I really did like, located at Stack Overflow. Attached below this paragraph is the source code that is provided by the user as well as the comments made by the user. This question provides the correct title header while also providing source code to work with along problems (and maybe solutions) that the user has reported. What differentiates this from other questions, however, is the fact that the user has already found a workaround but wants to make the code a little more efficient. The answer on the question, in fact, does not redirect the user to another site or to another forum and instead looks for a more efficient way of fixing the code.

If we use jest with typescript, which have an intersection observer used, the mocking of intersection observer will become hard. So far I'm at:

beforeEach(() => {
  // IntersectionObserver isn't available in test environment
  const mockIntersectionObserver = class {
    observe() {
      console.log(this);
    }

    unobserve() {
      console.log(this);
    }

    disconnect() {
      console.log(this);
    }

    root = null

    rootMargin = '0'

    thresholds=[1]

    takeRecords=() => ([{
      isIntersecting: true,
      boundingClientRect: true,
      intersectionRatio: true,
      intersectionRect: true,
      rootBounds: true,
      target: true,
       time: true,
    }])
  };
  window.IntersectionObserver = mockIntersectionObserver;
});

But still this is throwing error like:

Type 'typeof mockIntersectionObserver' is not assignable to type '{ new (callback: IntersectionObserverCallback, options?: IntersectionObserverInit | undefined): IntersectionObserver; prototype: IntersectionObserver; }'.
  The types returned by 'prototype.takeRecords()' are incompatible between these types.
    Type '{ isIntersecting: boolean; boundingClientRect: boolean; intersectionRatio: boolean; intersectionRect: boolean; rootBounds: boolean; target: boolean; time: boolean; }[]' is not assignable to type 'IntersectionObserverEntry[]'.
      Type '{ isIntersecting: boolean; boundingClientRect: boolean; intersectionRatio: boolean; intersectionRect: boolean; rootBounds: boolean; target: boolean; time: boolean; }' is not assignable to type 'IntersectionObserverEntry'.
        Types of property 'boundingClientRect' are incompatible.
          Type 'boolean' is not assignable to type 'DOMRectReadOnly'.ts(2322
          
I can keep adding correct types to each element, but is there a better way?

How can I add an intersection observer to the jest environment? I think it will be better than mocking like this.

The not-so-smart way

To me, there is no such thing as a stupid question. After all, questions asked usually have a range in difficulty, from close-to-simple to fairly intense. However, when you ask a smart question, you want to attempt to fulfill the quota as in Eric Raymond and Rick Moen’s article. With that being said, here is one not-so-smart question, aslo at Stack Overflow. As you can see, the title header is a repeat of what is available in the description, just a simple question. There is no detailed description, no attempts at implementation, no indication on whether the user attempted it or not. Of course, a not-so-smart question does not have to be… well… not-so-smart. However, there are a number of redirections to user manuals and/or other websites for working with php.

How can i send special characters like & over POST request?

Is the smart way always the right way to go?

The answer to that question is both yes and no. Yes, because you not only learn; you help other people, even those who are helping you, learn in the process. In this case, it is a win-win situation where nobody loses. At the same time, you might only be looking for a simple answer to a question or maybe some guidance on how to initiate a program or start some coding. Often do I go to public forums (especially Stack Overflow) to try and find answers to my questions. Sometimes the questions are trivial, other times they are fairly advanced and require some additional thought.

As I have said before, there is no such thing as a stupid question. However, asking a smart question will help you reach an answer faster than asking a not-so-smart question.