r/ProgrammerHumor • • Feb 05 '18

StackOverflow in a nutshell.

Post image
16.2k Upvotes

1.2k comments sorted by

View all comments

213

u/InfernoForged Feb 05 '18

It's spreading to other stack exchange communities as well. Some of the commenters in electrical engineering are just straight up assholes too.

178

u/[deleted] Feb 05 '18

Honestly. I was reading a stackexchange thread on EE to help me understand a question on my homework. Half the responses were "why bother posting you're clearly a newb"

39

u/diamond Feb 06 '18

Half the responses were "why bother posting you're clearly a newb"

This is the nerd equivalent of jocks laughing at fat people in the gym.

24

u/Flaktrack Feb 06 '18

Sad part is you're more likely to get made fun of on SE than at the gym... in my experience anyway.

5

u/[deleted] Feb 06 '18

Yeah totally. People in the gym either don't care about you or think that it's great that you want to better yourself. Many people on SE are just pricks.

3

u/diamond Feb 06 '18

I think you're definitely right.

160

u/Kinglink Feb 05 '18

Often times I've seen "That's clearly homework". OK but answer the question. Let the professor worry about if he's a cheater.

0

u/[deleted] Feb 05 '18

[deleted]

72

u/Kinglink Feb 05 '18

At the very least lay out the answer. I fully get "I don't want to help you cheat" but if you have a question like "How do I reverse a string?" You CAN answer the question without making it copy and pastable.

"Go through the string to get the length of the string, or use Strlen() Then use a for loop to cycle between 0 to half the length. For each value, exchange the string pointer + integer with string pointer + length - integer. Now you should have a reversed string" should be a good answer.

I've left a few minor issues and a few optimizations as well as edge cases in there as well, I answer the question but still leave the OP the challenge of coding it and improving it, and testing it.

71

u/[deleted] Feb 06 '18 edited Feb 06 '18

I would give them the answer and explain why it's correct.

I know I'm probably helping someone cheat, but I find that people generally want some sort of reference.

So, my answer would be something like:

Think about your question for a bit - You want to read the string backwards. How do you read something backwards? You read it anti-forwards. Now, think about how you would read something forwards with a for loop. (Assume you want to reverse the string s which is defined somewhere else.)

for (int i = 0; i < s.Length; i++) { ...s[i]... }

Look closely at that loop syntax - we're starting at 0, incrimenting by one each loop, and exiting when i < s.Length is no longer true. We can reverse that by starting at s.Length-1(the last value where the loop would pass), decrementing by one each loop, and terminating at zero (or when i >= 0 is no longer true).

for (int i = s.Length-1; i >= 0; i--) { ...s[i]... }

Now we have our loop. Let's make a temporary string to store the reversed string in, then assign it to the original string.

{
    string tmp = ""; //An empty string because we will be using `+=`
    for (int i = s.Length-1; i >= 0; i--) {
        tmp += s[i]; //add the character to the new string in reverse order
    }
    s = tmp; //assign the value before exiting the block
}

One more thing. This method deals with a lot of overhead data. You can do what is called an "in-place" reversal by simply switching values around. This will also take up half the amount of loops of our previous example. For practice, see if you can figure out what's happening here:

for (int i = 0; i <= (s.Length-1)/2; i++) {
    char temp = s[i];
    s[i] = s[s.Length-(i+1)];
    s[s.Length-(i+1)] = temp;
}

9

u/Nefari0uss Feb 06 '18

Those kind of answers are the best. In depth, gives details as to what's happening, and provides clear cut examples on how to do something.

9

u/PM_ME_YOUR_BOOO_BEES Feb 06 '18

You are a good person and it is answers like yours that helped me (and many, many others surely) when I was first trying to learn programming.

→ More replies (1)

5

u/PTRWP Feb 06 '18

Pretty off topic here, but why did you do the revered string like that? I'm still learning, but I've reversed strings by creating a new string then using for (i=string.length(); i>0; i--) and within the loop adding the current character to the end of the new string. I made it into a method so I haven't bothered to redo it in a different way since.

4

u/ar-pharazon Feb 06 '18

it avoids allocating a new string (though it is destructive, meaning that if you needed your original, unreversed string, you're going to have to reverse it again).

your method has the benefit of not destroying the original, but the particular way you wrote it is prone to triggering extra allocations. if you're using java, consider the following:

String forwards = "forwards";
String rev = "";
for (int i = forwards.length() - 1; i >= 0; i--) rev = rev + forwards[i];

in every iteration of the loop, we're actually discarding the old value of rev and replacing it with a copy that has the new character appended. this means we're generating a lot of unnecessary garbage.

if, on the other hand, you're in c++ using something like string::append, you're probably going to end up doing a vector resize (or similar operation) at some point.

but the bottom line is that extra allocation is unnecessary because you know beforehand exactly how much memory you need: forwards.length() characters. the java code to do this with only one allocation is roughly:

String forwards = "forwards";
char[] rev = new char[forwards.length()];
for (int i = 0; i < forwards.length(); i++) rev[forwards.length() - i - 1] = forwards[i];
String result = new String(rev);

c++ would be similar, though you could use the fill constructor rather than having the intermediate char array.

→ More replies (1)
→ More replies (1)
→ More replies (2)
→ More replies (35)
→ More replies (3)

4

u/yoshi314 Feb 06 '18

i actually had similar treatment in more technical subreddits sometimes.

i had a really non-trivial issue with excessive memory consumption on linux container, and most replies were more or less bluntly along the lines of "come back here when you learn how linux memory works", or "sounds like you're wannabe sysadmin, but your're not there yet"

turned out it was a virtualization bug triggered in a pretty rare circumstances. i found my answer in obscure corner of the internet, away from SO or reddit.

2

u/validproof Feb 06 '18

We should just have a machine learning a.i. running to remove those type of comments. Answers only. And if it's a duplicate, the a.i. would suggest you look at the duplicates before it publishs the question in a few hours. If you find the answer in the duplicates trend, you can simple remove the question being published before time expires.

0

u/[deleted] Feb 06 '18

[deleted]

→ More replies (1)

15

u/28inch_not_monitor Feb 05 '18

Oh yeah, had my question deleted from Drupal one because, well I can't find the reason any more. Some guy firstly came through and edit the shit outta my question which in turn made it a useless question as much of the important information was simply removed.

12

u/Avamander Feb 06 '18 edited Oct 03 '24

Lollakad! Mina ja nuhk! Mina, kes istun jaoskonnas kogu ilma silma all! Mis nuhk niisuke on. Nuhid on nende eneste keskel, otse kõnelejate nina all, nende oma kaitsemüüri sees, seal on nad.

3

u/SicSemperTyranator Feb 06 '18

Ohhhh, they are even worse there because there isnt a huge amount of archived references to look at. Try to ask an HDL question, I dare ya.

3

u/[deleted] Feb 06 '18

Literally the first comment on the first question i asked on electrical engineering was "google my question here". Dude, i did search.

At least some guy lead me to some sources i could check in order to learn about the subject i was asking about (I did mention my level of knowledge which is was very low)

3

u/[deleted] Feb 06 '18

Stack overflow is too strict and quora is too permissive. Every time I look at quora its always "is python worth learning anymore? My friend said its dying."

2

u/XxNerdKillerxX Feb 06 '18

Ha serverfault is like asshole central for some reason. Asked a question and was basically told I was too much of a newb to be asking questions like that.

→ More replies (1)
→ More replies (2)