Looking at this question got me thinking. A lot of people post homework question / programming assignments on Stack Overflow and that's fine if they make a legitimate effort (the linked question, not so much) and need help. But my concern is that a lot of homework questions are deliberately contrived with some silly restriction that doesn't make sense for a real programming question but, probably, makes sense in the context of the course and addresses the specific thing the instructor is trying to teach.
For example, in the question linked the user wants to determine the number of days in a month. Anybody who has spent more than 5 minutes in the .NET framework would (should) immediately go to DateTime.DaysInMonth and get the answer in one line. But the user's question explicitly states that they must use a switch
statement. It should be obvious to anybody with experience that this is the wrong way to do it because leap years are tricky (a fact recognized by the question with the statement that they should just always return 28
days for February) and it's pretty much always a bad idea to roll your own code for handling dates and times.
The problem is if somebody legitimately searching for how to get the number of days from a month comes across this question and thinks that having a switch
statement is the only way to do it, they will be mislead. Now this particular question probably isn't a problem, it's been voted down and closed anyway, but there are probably other questions out there with unnecessary restrictions placed on the solution (essentially XY problems) and it seems they ought to be recognized as such so somebody else searching for a solution doesn't end up thinking that the restriction placed on the homework question is actually a real thing.
So, on the one hand, I think we should help people with homework questions if they've made a real effort to solve it and are stuck, regardless of whatever restrictions their instructor has put on it. But on the other hand, I wonder if the answers are really useful to the broader audience of Stack Overflow users who are trying to solve the same (or similar) problem but don't have one hand tied behind their back?
So somebody rightly answered the question with the correct way to get the number of days in the month without regard to the restriction of using a switch
statement. However, their answer still picked up a downvote, unjustly in my opinion, but I can also understand why somebody might look at an answer that has ignored the restriction and downvote it because they haven't actually answered the question. So ignoring the restriction and giving a better solution to the original problem does risk picking up downvotes.
I guess perhaps the solution is to give the better solution (preferably first) and then give an answer including the restriction. But it still seems like the question is less than useful to anybody that isn't doing the exact same class with the exact same instructor.
switch
statement" which are a level above those real-life restrictions.homework
tag?Homework.StackOverflow.com
orToLazyToDoItMyself.StackOverflow.com