• Articles
  • Why we are a bunch of tough lovers.
Published by
Nov 4, 2010 (last update: Jun 22, 2011)

Why we are a bunch of tough lovers.

Score: 4.1/5 (48 votes)
Tee hee hee... I called us lovers! O_o
Hello females, males, transsexuals, natural hermaphrodites, and unsexed...

This is an article about our refusal to answer homework questions and solve homework problems.

I expect the majority of the people who have posted something along the lines of...
Hey pplz:
Write a program that implements Eratosthenes's sieve. The program should take in from the console the upper limit for the range 1-n to be searched for primes and output the number of prime numbers.

...were flat-out denied the problem's solution, and those who got the solution might have seen the solution giver reprimanded for giving the solution. If you are either a solution-giver or a solution-seeker, then I'm sorry but there's a difference between the easy way out and the right way out, and in this article I hope to explain why we are so set against giving out problem solutions.

Say that for the above problem, I posted the solution of:

#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <math.h>

using namespace std;
int size;
int* primes;
bool checkprimeness(int i)
	for (int j = 0; j < size; j++) 
		if (i % primes[j] == 0) return false;
	return true;

void main()
    int max;
    printf("Enter your number: ");
    cin >> max;
    if (max < 2) {
	printf("What the fortran do you take me for?\nThere are no positive primes here!\n");
	else {
		primes = (int*)malloc(4*max);
		size = 0;
		primes[size] = 2, size++;
	int i;
    for (i = 2; i < max+1; i++) {
		if (checkprimeness(i))
			primes[size] = i, size++; 
	cout << "\n";
    for (i = 0; i < size; i++) 
		cout << primes<i> << "\n";

Off the top of my head, there are five problems with doing this.

1: The OP (original poster) may not read through the code.
We have no guarantee that the OP will not do some really quick foot-kissing and run off with this solution, presenting it to the instructor as his/her own without examining it first. This is a problem because:

1.1: We will have wasted our time creating the solution (the above took me about 5 minutes, but it's still time wasted), as the OP will have learned nothing positive and unless it's good practice for you, you just spent some time writing a bit of code that won't teach anything positive. :)

1.2: Those of us who were paying close attention will notice that this code is not in fact the solution to the problem. Misreads happen, and if the student doesn't pay close enough attention, he/she won't notice that I "accidentally" made the program output the list of prime numbers instead of the demanded number of prime numbers.
Also, as tition correctly noticed in the thread version of this article 3 months later, the algorithm I used is not Eratosthenes's sieve; it never strikes out any numbers from a complete list. If this were in a solution I gave to the OP it might easily have gone unnoticed, and he/she might lose a substantial amount of credit on the problem if this piece of code was given in as a solution.

1.3: In the event that someone tried to turn this example in for credit, they might lose stunning amounts of credit just because of the ugly style I wrote it in. More on this in point 5.

2: This enforces laziness during college.
The OP might in some cases learn that others will do his/her work for him/her, possibly leading to some... unfortunate changes, as well as reinforcing laziness. This is only a possibility, like the above, but it still exists; I've seen it happen.

3: No comment(s).
If the OP actually did try to learn from my example, it could be hard to follow due to the lack of explanatory comments. Some of us will put in the comments, but I recognize that others may not, so when the given solution doesn't have explanatory comments it's time wasted for the OP, and possibly simply doing the problem would have taken less time to do and would have lead to a better understanding.

4: This enforces laziness after college.
(inspired by a response by cnoeval) If somehow the OP managed to get through college cheating and obtain a reasonable degree to work in the computer science industry, then he/she would have both wasted at least two good years of his/her life, and also have great trouble being able to actually work. Some people might help them in that area as well, possibly for years, but even the most generous people have a limit.

5: It spreads bad coding habits like a disease.
The style of this piece of code is actually quite horrific, but what's worse is that someone without much experience in C++ might give this to someone as a solution to turn in. I'd congratulate the effort, but in the event that the OP does try to learn from the code, he/she might develop habits that in C++ are not only terrible, but also very hard to unlearn. Usually we try to point this out, but we aren't everywhere and we aren't active all the time. Please don't give out solutions, just in case your habits aren't ideal!

NOTE: The example won't even compile if one closely follows the C++ standard. In addition, the program has a memory leak, as a result of the memory primes points to never being freed. I do NOT recommend running this program without fixing it first!
If you learn better by seeing a problem and its solution side by side, ask a forum member if they can create a similar problem and solve it so that you can see the problem and the solution side by side. If one of us has the time, we will happily do that or link to an already done example. :)

For a few guidelines in creating a good question, see the article here.

Happy coding!


EDIT1: Made a slight change to the problem description to make it somewhat more realistic and added point #4. Also made the console pause slightly more elegant but slightly harder to understand.
EDIT2: Added point 1.2.1 (now a part of 1.2)
EDIT3: Made a few minor changes.
EDIT4: Doused the example with a bucket of unadulterated evil, and added point 5.
EDIT5: A few anti-refinements to the example were added.
EDIT6: A few small wording changes were made, changed the article to take advantage of the features of the new Articles section.