7

Before I begin, I should mention that I'm not familiar with meta, and I'm not even sure if this is okay. For the time being, based on the existence of other questions with similar titles, I'm assuming that it is okay to ask for help revising a question on meta, before posting the question on the main site. Please let me know if I'm wrong, and if so, where to go for this specific type of problem.


I recently wrote a question on the main site, and within the span of minutes, accrued four downvotes with no comments explaining why. The only person who commented said that the part about The Witness is irrelevant. This is information that I included because I didn't want to just spam code in a question without talking about some background first.

So I deleted the question. And before I re-post it, I want to make absolutely sure that I do it right so that it won't be negatively received, hence why I am turning to meta for help.

Anyway, below is the full text of the original question (followed by the revision I currently have). The help is much appreciated.

Anybody who's played enough of The Witness probably knows about the puzzle where you have to sit through an hour-long monologue while a moon slowly moves from one side of the screen to the other (full transcript). During this bizarre and long-winded monologue about Video Game Easter Eggs, a mention is made of "Gary's Formula", which involves taking every letter of a string, multiplying its position value by six (A = 6, B = 12, C = 18, etc), and summing them together. This is used as a "proof" that Santa Claus is evil, because G(Santa Claus) = 666.

So I wrote an implementation of it, and then I wrote a 101-byte golf of it.

main(c,v)char**v;{for(char*a=v[1];*a;a++)c+=6*(*a>64&&*a<91?*a-64:*a>96&&*a<123?*a-96:0);return c-2;}

This is where the question comes in, essentially "why does this happen?":

$ make garygolf && (./garygolf santaclaus; echo $?) # expect: 666
154

If I change the code to include a call to printf, it uncovers the strange and interesting bug that is currently blowing my mind.

$ cat garygolf.c
main(c,v)char**v;{for(char*a=v[1];*a;a++)c+=6*(*a>64&&*a<91?*a-64:*a>96&&*a<123?*a-96:0);printf("%u\n", c-2);return c-2;}
$ make garygolf && (./garygolf santaclaus; echo $?)
666
154

I'm not even sure whether it's a bug in the program, a bug in the shell, or if I'm just using the shell wrong. If $? somehow wasn't the return value, or something else was modifying the return value just before exit, then adding extra arguments should result in the same return code of 154, but look:

$ ./garygolf santaclaus second third; echo $? # result should be off by two
668
156

It's off by two. Where is 154 coming from? I feel like I'm missing something obvious.

Here's some more outputs, showing how deep this unpredictable output goes:

$ dogg(){ ./garygolf "$1"; echo $?; }
$ dogg compute
558
46
$ dogg computer
666
154
$ dogg computers
780
12
$ dogg computersa
786
18
$ dogg computersaz
942
174

And as for the first paragraph, here is my second draft:

I recently wrote an implementation of "Gary's Formula". Gary's Formula is described on this 58-minute diatribe about video game easter eggs (you can find the segment by searching for "santa claus"). In brief, the algorithm works as follows: for each letter in string, multiply the letter's positional value by six (A = 6, B = 12, C = 18, etc). The result is the sum of all of the letters' values.

The rest, I haven't changed.

12
  • 12
    Two people have voted this meta question down and I have yet to hear an explanation as to why. The problem with doing that is that this is a question about asking questions. If you downvote such a thing, you're telling the asker they shouldn't bother asking questions period (a critical comment is all you need). And it's pretty effective, because the needless hostility and complete lack of communication makes me not want to ask questions. If I can't even go to meta for some peer review, then there's no point. Questions are instrumental to SE. Don't alienate the life blood of the community. Commented May 21, 2018 at 1:32
  • 5
    The golfing is an albatross round your neck. Commented May 21, 2018 at 9:29
  • 14
    Dumping code like that is an insult to the skilled and experienced developers who volunteer time to help with SO Q&A. Asking them to waste time on unravelling gunge is grossly disrespectful, as is describing their downvotes as 'hostile' They just downvoted because that's as much effort as they thought your question warranted and, as has been demonstrated over, and over, again, leaving comments just presents a username target for OP's who are inclined to treat anything other than total subservience from volunteers as 'unwelcoming':( Commented May 21, 2018 at 9:38
  • 1
    @Martin James: Or this variation Commented May 21, 2018 at 10:28
  • 1
    I admit, my viewpoint regarding criticism is fanatical. I go as far as thinking that downvotes should be required to be accompanied by a comment, even if selected from a boilerplate, because "this sucks and here's why" is infinitely better than "this sucks". I take feedback very seriously and treat each downvote as a horrible screw-up on my part. Naturally, I want to right those wrongs. And when I can't, because the downvote is un accounted for, it's upsetting. Am I unreasonable for being a perfectionist? Probably. Commented May 21, 2018 at 11:21
  • 4
    @BradenBest Well, downvotes are not supposed to mean "this sucks". They mean "this is not useful", "this is off-topic", "this should be improved". It's true that they are not always accompanied by a comment. Comments sometimes are counter productive. See Why isn't commenting mandatory on downvotes, and why are ideas suggesting such shot down? Commented May 21, 2018 at 11:27
  • 1
    @BradenBest I understand. I wish the situation was better. I have to admit that I used to comment more often when voting, but I have been hit with hostile response so many times that I tend to vote without commenting at the moment. I do provide comments giving possible reasons when OP asks for them politely and seems to be open to suggestions. Commented May 21, 2018 at 11:52
  • > be a new user > asks c++ question > gets the crap kicked out of them > mfw.jpg
    – user1228
    Commented May 21, 2018 at 16:26
  • Braden, I have also had contributions to SO downvoted without the courtesy of a note saying "here's why I downvoted you". The sad fact is that, as with any social medium, SO has all kinds of users. Some are courteous; others aren't. No-one who downvotes you and refuses to expend 5 minutes of effort to explain why deserves a single erg of "what did I do wrong?" mental energy from you.
    – Brian
    Commented May 21, 2018 at 21:51
  • 1
    Honestly, regarding this meta question, I was all set to upvote it because asking for constructive feedback on SO posts is most definitely a valid use of meta, but then I hit the paragraph that includes the sentence "And if this meta question gets downvoted, I probably won't ever ask a question on Stack Overflow again" which basically means you're throwing a hissy fit. That sentence by itself may be why you got downvotes on this meta question.
    – Ajean
    Commented May 21, 2018 at 22:04
  • @PeterMortensen regarding your edit, I'm not sure what style guide you're going by, but there's nothing wrong with using '4' instead of the word, 'four'. Just as long as you're consistent. I.e. 'I ate 3 apples in 10 minutes.' is okay, and 'I ate three apples in ten minutes.' is also okay. 'I ate 3 apples in ten minutes.', on the other hand, is sloppy. IIRC, there is one exception when it comes to small versus large numbers. I.e. it's okay to write 'I ate three apples in 100 minutes.' (but not 'I ate 3 apples in one hundred minutes.') Commented May 21, 2018 at 22:13
  • @Ajean Yeah, I probably shouldn't have written that. I let my obsession with being on good terms get the better of me, and dropped the ball there. I'm gonna delete that paragraph, so I hope nobody construes it as me trying to backpedal / censor. Commented May 21, 2018 at 22:22

2 Answers 2

29

Your code is golfed and unreadable, and almost all of it is irrelevant. The context about the video game you were playing is also irrelevant.

You need to construct a minimal reproducer for your bug - minimal in terms of complexity, not in terms of character count.

For reference, assuming I understand your code correctly, the following program would have reproduced the bug:

int main(void) {
    return 666;
}

You're returning an out-of-range exit code, and it's getting reduced mod 256. This is what you should have reduced your example to. No horrible golfed loop and hardcoded ASCII values and K&R-era declarations and abuse of argc as an accumulator.

3
  • 1
    I see. But you've actually ended up answering the original question. So... should I even bother posting the question now? Commented May 21, 2018 at 0:43
  • I suppose it's prudent that I follow through. After all, you guys critiqued my question, so it's only fair that I, at the very least, publish the final draft to show my work. Which I did, in an update to this question. I'm still unsure about actually posting it to SO, though. Commented May 21, 2018 at 1:15
  • 9
    You can post the question and write your own answer, now that you know the answer. Make sure the question doesn't include any of your golfed code -- for example user2357112's code is sufficient to get the question's point across. The question should be phrased simply, for example "Here's a program that returns 666. <code> But when I run it in the shell, the output is 154 instead: <code> Why?"
    – k_ssb
    Commented May 21, 2018 at 5:15
22

The question I have for you is, why did you "golf" this code?

For this question to be largely accessible to others, it would be better to ungolf your code and elaborate on the algorithm you're using a bit. I mean, I understand C fairly okay but I refuse to accept Cthulhu into my life when reading this expression:

*a>64&&*a<91?*a-64:*a>96&&*a<123?*a-96:0

That's the best advice I can give you; four or so people felt like your question was difficult to understand or comprehend because you made your code inaccessible. If you made your code more accessible, you probably get a better reception.

3
  • Oh, good point. As for why I golfed the code, it's something I like to do to challenge myself. Regarding making the code more accessible, could this be done by breaking it down into its parts and writing code comments? I've included what I have in mind as part of the most recent revision to the question. Commented May 21, 2018 at 0:35
  • 16
    It's a significant improvement, but it'd be best to leave the obfuscating syntax completely out of the equation if you can. I can at least respect that you like to challenge yourself, but you should challenge yourself once you have the working code in place.
    – Makoto
    Commented May 21, 2018 at 0:37
  • I didn't notice that last part about "having the working code in place". The golf isn't behaviorally 1:1 with the original. I made compromises to save those precious bytes, like removing the call to printf to save 6 bytes. If you're curious, here's the version I wrote just before the golf. It's functionally far more robust than the golf. More robust than it probably needs to be. Commented May 21, 2018 at 1:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .