開源日報 每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,堅持閱讀《開源日報》,保持每日學習的好習慣。
今日推薦開源項目:《傳奇歷史 nCovMemory》
今日推薦英文原文:《How to Ask Questions About Programming》

今日推薦開源項目:《傳奇歷史 nCovMemory》傳送門:GitHub鏈接
推薦理由:這段以後在人們心中無法忘卻的歷史,現在正在不斷的向我們展現它的一切;或者應該說,這世界上的所有人,現在此時此刻,正在不斷的完善這段歷史。
今日推薦英文原文:《How to Ask Questions About Programming》作者:Martin Andersson Aaberge
原文鏈接:https://medium.com/better-programming/how-to-ask-questions-about-programming-dcd948fcd2bd
推薦理由:問問題可是門學問

How to Ask Questions About Programming

Programming isn』t about writing code. Programming is about problem-solving. The actual code, anyone can learn. If you are good at problem-solving, the coding part is basically learning syntax and how to search for functions, libraries, and tricks to solve the task.

Questions that don』t deserve an answer

This article is based on a series of real questions asked in various Facebook groups. The questions are legit, it』s just how you approach your audience I want to look into.

If your question is along these lines, why should anyone bother spending their personal time helping you?
  • 「How do I solve this?」 (Random screen shot of an obvious school assignment.)
  • 「How do I do this? I have tried everything.」 (Clearly didn』t try everything in the whole world.)
If you just dump out a question where you expect people to do all the work for you, you』re being disrespectful. You』re basically asking random strangers to do all the work for you while you sit back and harvest from their work.

Example 1: Area of a Triangle

「How do I calculate the area of two triangles making up a square in Python?」

Photo by Shapelined on Unsplash

The autoreply to all questions should be, 「What did you try so far?」 (Or, if it』s a philosophical question, 「What are your thoughts on the subject so far?」 Please post your current code when asking questions.

If your answer is 「I haven』t tried anything yet. I just have issues solving it,」 please come back when you have tried something.

The example above is a terrible way to ask that question. Here』s what I consider a good way to ask a question:

「How do I calculate the area of two triangles making up a square in Python? So far I have tried the following:

The math behind the area I believe is pretty straightforward. A square has equal sides, so we know the base and the height because they』re also the same. We don』t even need to invite Pythagoras — yay! I googled the area of a triangle, and this is the formula:
A = 1/2 bh
Here』s my current code:
def find_square_area(length):
    return int(length)*int(length)def find_triangles_area(length):
    return (1.2*int(length)*int(length))side_length = input('length of square sides: ')
print (f'The area of the square is {find_square_area(side_length)}')
print (f'The area of each triangle making up the square is {find_triangles_area(side_length)}')
The code seems to run, but I』m expecting half of that square area because I think that』s what it should be. I mean, I』m just slicing it in half. Am I thinking wrong or coding wrong? Appreciate the help!

A question of this caliber I would love to see more of. Clearly, the imaginary user has given it some serious thought. They have read up on the theory of the problem they want to solve and have also done the code.

The code seems to work, and the user is also reflecting on the logical error here. This one could easily slip, but if you stop and think, the area of each triangle can』t be bigger than the square itself. Something is clearly wrong.

I』m sure several people would help, and we』d be able to pinpoint that the math in the find_triangles_area() function is incorrect. Maybe the discussion would also lead to talk about operators like *= — not that you need to use it, but it could spark more creativity.

For this session, we have several wins. Firstly, the original poster has learned a lot by almost figuring out the issue. Secondly, the question is appealing to answer. This is an answer I want to reply to.

Photo by Andre Hunter on Unsplash

Example 2: Pythagoras

Let』s invite Pythagoras to the party anyway and create a question related to the theory.
「I don』t understand The Pythagorean theorem — explain it to me.」
Well, that』s a seriously vague question. Where do I even start? Considering how many sites there are online that explain this brilliantly, I don』t believe that』s the real question.

If I were to answer it, maybe I』d ask something along these lines:
What exactly about the Pythagorean theorem do you have trouble with? The concept, the math, or something else?
That should trigger some thought, and the user posting the question could go:
「Well, after it』s set up, we have numbers on both sides right … 24² = 16² + b². Then, suddenly we』re doing the square root of 320 and b. Where did all the numbers go? Why are we suddenly working on 320?」
It turns out the user actually just has issues with the expression. Maybe they were looking at examples that skip a few steps and, therefore, made it more confusing.

Now that we fished for more information, we can go through that piece step by step, and the user would probably get a nice reply.

That wasn』t such a bad question though, was it? Well, if the information was there from the start, we wouldn』t have wasted a bit of time. Just a tiny snippet of information would help everyone out here.

In Conclusion

Whenever you want to ask a question about programming or problem-solving, make sure you have done something yourself first. If you want to actually learn from it, you have to do something. It』s also the best way to learn in general. You can watch all the tutorials you want, but if you never try anything out, how can you get a feel for it?

If you want decent replies, make sure you post decent questions. You』d be surprised how many people actually enjoy helping others, myself included. I love to teach, and I love to learn. Let』s make teaching and learning great again. Thanks for reading!
下載開源日報APP:https://openingsource.org/2579/
加入我們:https://openingsource.org/about/join/
關注我們:https://openingsource.org/about/love/