
All our academic lives, we’ve heard that there is no such thing as a “stupid question,” and while that is correct, you should still aim to ask a good question. No, you are not stupid for being curious. Asking a question is the only way to get an answer! However, there is a way that you can form a question with intention to ensure you receive a targeted answer.
When delivering a question, regardless of where it lands, we can control how it lands. A question that lands well is understandable by those who want to offer their help and provides all background information necessary to work toward an answer. How to ask questions the smart way by Eric Raymond provides details on how questions can land, whether smart or stupid, and how they effect the answer you’re given.
Stack Overflow is a question/answer online forum for programmers. It’s a resource that I had only recently learned about. While I have not browsed the site myself, I’ve heard a lot of my programmer peers say it’s useful for specific, or common, problems you might run into while coding.
Most media online tends to have content that you wouldn’t really call smart, and what you may find on Stack Overflow is no exception! It is often the case that users will ask a question stupider than most, which can waste the time of those who attempt to help and the author of the question.
Below is an example of a “stupid” question:
Q: no token found or no token provided
the problem i am facing is that everything works fine locally but when it comes to production it gives this error ...
...front end code
import React, { useState } from 'react';
import { motion } from 'framer-motion';
import { axiosInstance } from '../../lib/axio';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../../context/AuthContext';
const AuthPage = () => {
const navigate = useNavigate();
const { login } = useAuth();
const [isLogin, setIsLogin] = useState(true);
const [name, setName] = useState('');
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const handleOnSubmit = async (e) => {
e.preventDefault();
if (!username || !password) {
alert('All fields are required.');
return;
}
if (isLogin) {
try {
// Simulate an API request for login
// Replace this with your actual login logic, such as an API call to check credentials
const response = await axiosInstance.post('/user/login', { username, password });
console.log("login response:", response);
if (response.status === 200) {
login();
alert("Logged in successfully!");
navigate("/blogs/create");
window.scrollTo(0, 0);
} else {
alert(response.data.message);
console.log("response error : ", response);
}
} catch (error) {
alert(error.response?.data?.message || 'Unable to log in. Check your credentials.');
console.log(error)
}
}
else {
try {
const response = await axiosInstance.post("/user/signup", {
name,
username,
password,
});
console.log("signup response:", response);
if (response.status === 201) {
login();
alert("Signed up successfully!");
navigate('/blogs/create')
window.scrollTo(0, 0);
} else {
alert(response.data.message || 'Something went wrong. Please try again.');
}
} catch (error) {
alert(error.response?.data?.message || 'Unable to sign up. Please try again.');
}
}
}
const toggleAuthMode = () => {
setIsLogin((prevMode) => !prevMode);
};
return (
<div className="flex justify-center items-center h-screen bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500">
<motion.div
className="w-full max-w-md p-6"
initial=
animate=
transition=
>
<div className="bg-white shadow-2xl rounded-2xl">
<div className="p-8">
<h2 className="text-2xl font-bold text-center mb-6 text-gray-800">
{isLogin ? 'Login' : 'Sign Up'}
</h2>
<form onSubmit={handleOnSubmit}>
{!isLogin && (
<div className="mb-4">
<label htmlFor="name" className="block text-gray-700 text-sm font-bold mb-2">
Name
</label>
<input
type="text"
id="name"
value={name}
onChange={(e) => { setName(e.target.value) }}
className="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-400"
placeholder="Enter your name"
/>
</div>
)}
<div className="mb-4">
<label htmlFor="username" className="block text-gray-700 text-sm font-bold mb-2">
username
</label>
<input
type="username"
id="username"
value={username}
onChange={(e) => { setUsername(e.target.value) }}
className="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-400"
placeholder="Enter your username"
/>
</div>
<div className="mb-4">
<label htmlFor="password" className="block text-gray-700 text-sm font-bold mb-2">
Password
</label>
<input
type="password"
id="password"
value={password}
onChange={(e) => { setPassword(e.target.value) }}
className="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-400"
placeholder="Enter your password"
/>
</div>
<button className="w-full py-2 text-white bg-blue-600 hover:bg-blue-700 rounded-lg">
{isLogin ? 'Login' : 'Sign Up'}
</button>
</form>
<p className="text-center text-sm text-gray-600 mt-4">
{isLogin ? "Don't have an account?" : 'Already have an account?'}{' '}
<button
onClick={toggleAuthMode}
className="text-blue-600 hover:underline focus:outline-none"
>
{isLogin ? 'Sign Up' : 'Login'}
</button>
</p>
</div>
</div>
</motion.div>
</div>
);
};
export default AuthPage;
..everything works locally .. but after production this error is coming .... if tried the secure:false....adding domain in cookie .. i tried everything i can .. still stuck
... expecting to work everything on production
(A lot of this code was cut for your reading convenience, see the full question here.)
As you might’ve observed, there’s not much to digest from this question!
The user simply dumps all their code into their post without much of an explanation for what’s happening. They give an incredibly vague description of what they experienced, but even from that, there’s not much to take away. Even the title of their question is ambiguous!
If this user wants help, they might be out of luck!
While a very skilled software engineer might take the time to analyze their code and search through the lines to find an error, the author of the post certainly does not make it an easy job for them. This alone can sway users away from offering their help. There’s a lack of description, no clear indication of what exactly they want to be educated on. The question comes off as an attempt to get a quick answer out of someone who has all the time in the world. As of writing this, there are no answers commented on the post.
This question doesn’t land well and isn’t very “smart!”
Now that we’ve assessed that damage, let’s move onto a “smarter” question:
Q: Why is processing a sorted array faster than processing an unsorted array?
In this C++ code, sorting the data (before the timed region) makes the primary loop ~6x faster:
#include <algorithm>
#include <ctime>
#include <iostream>
int main()
{
// Generate data
const unsigned arraySize = 32768;
int data[arraySize];
for (unsigned c = 0; c < arraySize; ++c)
data[c] = std::rand() % 256;
// !!! With this, the next loop runs faster.
std::sort(data, data + arraySize);
// Test
clock_t start = clock();
long long sum = 0;
for (unsigned i = 0; i < 100000; ++i)
{
for (unsigned c = 0; c < arraySize; ++c)
{ // Primary loop.
if (data[c] >= 128)
sum += data[c];
}
}
double elapsedTime = static_cast<double>(clock()-start) / CLOCKS_PER_SEC;
std::cout << elapsedTime << '\n';
std::cout << "sum = " << sum << '\n';
}
- Without std::sort(data, data + arraySize);, the code runs in 11.54 seconds.
- With the sorted data, the code runs in 1.93 seconds.
(Sorting itself takes more time than this one pass over the array, so it's not actually worth doing if we needed to calculate this for an unknown array.)
Initially, I thought this might be just a language or compiler anomaly, so I tried Java:
import java.util.Arrays;
import java.util.Random;
public class Main
{
public static void main(String[] args)
{
// Generate data
int arraySize = 32768;
int data[] = new int[arraySize];
Random rnd = new Random(0);
for (int c = 0; c < arraySize; ++c)
data[c] = rnd.nextInt() % 256;
// !!! With this, the next loop runs faster
Arrays.sort(data);
// Test
long start = System.nanoTime();
long sum = 0;
for (int i = 0; i < 100000; ++i)
{
for (int c = 0; c < arraySize; ++c)
{ // Primary loop.
if (data[c] >= 128)
sum += data[c];
}
}
System.out.println((System.nanoTime() - start) / 1000000000.0);
System.out.println("sum = " + sum);
}
}
With a similar but less extreme result.
My first thought was that sorting brings the data into the cache, but that's silly because the array was just generated.
- What is going on?
- Why is processing a sorted array faster than processing an unsorted array?
The code is summing up some independent terms, so the order should not matter.
Now that’s more like it! The question above is much more structured, and even goes beyond the standard! The author has a title that is clear and a body that provides even more insight into their issue. What’s special about this is that they also offer their attempt at solving the issue in another language.
It offers multiple perspectives on the question, doing more than just dumping their code onto a post and asking for help. They include the run time of the code and their expectations of its performance with notes and sum it up at the bottom with questions that are easy to follow. This kind of question would attract someone willing to help!
We’re told that you can solve anything with the help of the internet, and this thought alone might lead someone to think that we can let the internet do all of the work, but that isn’t entirely true. Like most cases, putting effort into your work will always benefit you.
You can’t expect to get real answers from real people when you don’t give them enough to work off of. I don’t even think ChatGPT could’ve figured that first question out. If you want to gain something from a piece of work that you put out there, that requires some of your effort. You have to meet them halfway, especially if you seek their guidance.
And what’s most valuable: when you put in the effort to learn, you will retain the information and become educated.
Seeking a quick answer will give you just that, and without giving your full attention to learning a topic, you’ll be out of luck when the time comes for you to recall that answer.
So don’t be stupid, ask smart questions.