Do not give positive feedback to bad posts

in programming •  7 years ago  (edited)

3199296759_e5130dc6c1_z.jpg

source

I was searching for posts about computer programming on steemit and I've stumbled on this title: C++ Program of (a) power b without using any builtin functions. I've decided to take a look at it.

First thing you can notice reading it from the platform, is the formatting which makes it unreadable. So I've copied the text in an online reformatter. Then I had to fix the disappearing *, because *s pairs became italics.

But this is just make-up which doesn't change the meaning of the code…

The meaning? This code is total crap. I am horrified. I am a professional programmer who has also some experience reviewing students' code, and well, I've seen many mistakes and odd things, but something as pointless as this one… I don't remember anything like this. Moreover, it doesn't what it says it does, and this is the first clue any student should interpret as an invite to try harder.

I'll be back on this later. Let's first face a possibile sad truth.

Self-steeming

In this moment the post has 9 votes by:

  • tincho
  • imosco
  • macbaren
  • busy.org
  • learnandgrow (himself)
  • hanitasteemer
  • sauper-saiyanbot (a bot, I suppose)
  • sinbad989
  • wolf-kinght

These votes bring the post $8.62 (currently). Which is, I think, a very high value for 9 votes and for such a low-quality post.

The sauper-saiyanbot also commented. Twice. With this text:

its really a great logic in this program

And this other text:

amazing post

The first comment has got 3 votes (for $0.25). These 3 votes are by

  • sauper-saiyanbot
  • hanitasteemer
  • learnandgrow

The second comment has “only” 2 votes ($0.15), by learnandgrow and sauper-saiyanbot.

Even if it is just a bot (very likely), the comments are surreal because the post is very ugly (wrong formatting), it looks bad, and the logic isn't great, it is sick — and also wrong, as you can see testing the program.

Likely the author, learnandgrow, and the bot sauper-saiyanbot are connected someway, hence no surprise the bot writes so far-from-reality comments.

It comes to my mind an interview I've read today, 20 questions with @surfermarly (The Steemian Series).

Question 10.

Some of your [surfermarly's] recent posts have analyzed questionable practices currently occurring on Steemit, which some would argue are toxic to the platform.

I haven't read her posts so far (also, I am back just today and thought she was gone — instead I see she's back, good thing for steemit, I believe), so, just conjecturing right now: maybe they are talking about something more toxic, but since I've spotted this overvalued low-quality post with such nonsense comments, I think behind it there's one of these questionable practices.

Keep a decent quality

If there are questionable practices which allows opportunist users with low-quality effortless contents to gain steem and attract even few ”big” votes, then common users producing good-enough-quality contents could surrender, because they see their efforts defeated by just “technique” and submerged by crap. They ask themselves, “how is it possible that this crap got so many and/or so big votes?”, and they go away.

By the way, if an opportunist user uses the questionable practices but also produces high quality content, I think it's unfair but it comes no harm to steemit, because after all we have a good content. Besides, I would rather believe the user had so much positive feedback because of the quality of her work, and I wouldn't investigate if she has used or not questionable practices: it doesn't matter anymore because good contents should be rewarded anyway.

Let's take a look at another combination: a user producing far-from-good but honest contents, and who doesn't use any trick. This can receive positive feedback, but it depends on the tastes or checks of the community, not on the questionable practices.

What do I mean by “honest contents”?

Well, let's talk about the post C++ Program of (a) power b without using any builtin functions. It is clear to me that there isn't any effort in that post. He didn't care about the formatting on steemit, first thing first. Title aside, there isn't any initial text, a preamble explaining what he's going to write: he just dumped the code.

You can like or dislike many different kind of posts, but you must realize that usually it is just because of your taste. The problem when posting computer code declaring what it does, is that it can be judged objectively. First of all: does it compile? Then, does it work, does it what the title (in this case) says? These are two basic objective criteria to judge the quality when all you have is just code.

And about the code in that post… In the brightest case it looks like unredacted homework, and it also works like unredacted homework — that is, it doesn't work. Which makes you ask, why do you posted it?

It's fine if a computer programming student post his code; he should, nonetheless, be confident that it works, hence being proud of it — look what I did, and I'm just a novice!; otherwise he should ask expert people on steemit to check if it is fine, or something like that, not selling it like a way of computing ab without using builtin functions.

Moreover, we shouldn't expect a void comment like “amazing post” or worse, a positive comment about the nonsense logic contained in the code. A programmer couldn't write such a positive comment without being pointed as fake.

Anyway…

I almost hope that the guys behind that post are here just to exploit steemit using questionable practices, totally uncaring about the content. Because otherwise it would mean that really somebody thinks that that post is amazing and the code has “great logic” inside!

It would mean there's a danger for the human-programmed-computer driven world, if he wants to work in the information technology industry. And if he's the type who actually wrote the code thinking it does what he declared it does in the title, it also would show the failure of the school system.

Let's take a look at the code

I want the reader to understand my astonishment, so be patient.

First of all you have to keep in mind the aim: you want to compute ab writing your own algorithm. We are all educated, I think, to know the very basic of such an expression when b is an integer: it means you have to multiply a b-times. For example, if b is 3, you compute a*a*a. And so on.

And if b is negative? It can be proved that a-b = 1/ab, so you can compute ab as before, then invert it, or you can multiply b-times the number 1/a (it isn't the same thing, but here we don't care). Because you have a|b| as denominator, it must be not equal to 0 (otherwise we have a divide-by-zero error).

What if b is 0? It can also be proved that a0 = 1.

Everybody older than fourteen should know this.

This is all you need to know to imagine the algorithm. It could look like this (pseudocode):

invert := false
if b < 0 then
  invert := true
  b := -b
end if
result := 1
repeat b times
  result := result * a
end repeat
if invert is true then
  if result ≠ 0 then
    result := 1/result
  else
    error "1/0"
  end if
end if

This is one way it can be done; I'm not saying this one is the best: it's just one among others.

Anyway, it's a simple algorithm (luckly we're dealing only with integers; but the same algorithm works if a is a real number, too).

Now take a first look at his code. Do you see the kind of simplicity you would expect from the pseudocode above?

But, hey, maybe it works, despite the fact that there's some code smell, which usually means the code doesn't work; however it may seem to work for some input values.

I can't read the code, but can test the program!

The code isn't only wastefully complicated — we could forgive it to a novice student, maybe.

When you test it, looking at the pattern you realize that it isn't an “odd” or wrong implementation of a correct algorithm: it must be an “odd” (and maybe also wrong) implementation of a wrong algorithm.

Before posting he should have checked the results with a calculator, then he wouldn't have posted the wrong code, would he?

Let's try.

numexresultok?
001Y
1101Y
2101024Y
2-10.2N
2-20.02N
2-30.002N
-214N
4116N
-224Y
-23-8Y
-2-1- 0.2N
-2-2- 0.02N
-2-3- 0.002N
10-10.10Y
11-10.11N
12-10.12N
10-20.10N
12-20.12N
10-30.010N
100-10.100N
100-20.100N
100-30.100N
100-40.0100N
-100-4- 0.000100N
100011000000N

Ok, it's enough. I hope you get the obscenity of these results (it doesn't give the correct results even for a1!) and from the pattern we can try to infer what kind of wrong algorithm he tried to implement — not succeeding… that is, we have a wrong implementation of a wrong algorithm! And, I can't stress it enough, it can be easily seen, and it should have been seen before posting.

The failure of the school system?

I can imagine that when the program says that 41 = 16, it's because of a logic programming error; a bug which can be easily discovered by testing… (but I am arguing also that giving something good to the community wasn't his main concern). In fact, I refuse to believe that he doesn't know that 41 = 4.

On the other hand, though, negative powers show a pattern which, regardless of the correct or wrong implementation, makes you think he doesn't know how something like a-3 must be computed.

We know that 10-1 = 0.1, 10-2 = 0.01, 10-3 = 0.001, and so on. If you are very naive, and uneducated, or just too young to have studied these things, you can infer a wrong rule for negative powers: let a be a symbol (e.g. 10), then a-1 = 0.a, a-2 = 0.0a, a-3 = 0.00a, and so on. This inference should have been checked trying with 11-1 (which isn't 0.11).

Anyway, for 10-2 his code doesn't give 0.010 but 0.10: a wrong implementation of the wrong algorithm? Or a correct implementation of an even worse and more obscure wrong algorithm? We can't say.

But I bet that if there weren't anything to earn, he wouldn't have published such a code on his student blog…

Bad coding

We can say that it's a (wrong) implementation of a wrong algorithm, and not a wrong implementation of the correct algorithm because we spotted a pattern when b is negative (and also because a1 gives a²).

Let's forget it for a minute and let's look at how the code does what it does (I cut the unimportant parts and use <<LABEL>> to label pieces of code).

if (num > 0 && ex > 0) {
  <<CODE_A>>;
} else if (num < 0 && ex > 0) {
  <<CODE_A>>;
}

See, CODE_A appears twice. Then the piece can be “reduced”:

if (ex > 0) {
  <<CODE_A>>;
}

and it continues like this:

else if (num > 0 && ex < 0) {
  <<CODE_B>>;
}
else if (num < 0 && ex < 0) {
  <<CODE_C>>;
}
else if (ex == 0) {
  <<CODE_D>>;
}
else {
  // ... invalid exponent "expression"! ...
}

When it reaches “Invalid exponent expression“ it's because a (num in his code) is 0 and the exponent is negative. A more correct error message is “division by zero” — but he doesn't any division, so the error is part of a rule learnt by heart, without understanding why it must be so.

The CODE_A is the code responsible for the result a1 = a².

<<CODE_A>>:
  re = num * num;
  for (n = 2; n < ex; n++) {
    re = re * num;
  }

The error is clearly in the first line: re (the result) is initialized with a². Then, n starts from 2, and 2 < 1 (ex is 1) is false: the body of the loop isn't executed, but re is given as final result.

A fix:

<<CODE_A>>:
  re = 1;
  for (n = 0; n < ex; n++) {
    re = re * num;
  }

The CODE_B is a nightmare, and it isn't clear why it must different from CODE_C: they should have been the same, almost (except that when num is negative, he must write “-0.” instead of “0.”). Instead CODE_B behave differently according to the range num is in.

This isn't “great logic”: this is beyond a faulty logic. Even if we accept the wrong algorithm as reasonable, entering this strange world where it makes sense, there aren't good arguments explaining why CODE_B and CODE_C should differ so much; in the worst case they should differ just for a sign printed before the “0.”. Moreover, what if num is between 1000 and 9999? Why this case, and all the others, aren't considered?

Since CODE_B must be like CODE_C, I would group them; therefore

else if (num > 0 && ex < 0) {
  <<CODE_B>>;
}
else if (num < 0 && ex < 0) {
  <<CODE_C>>;
}

becomes

else if (num != 0 && ex < 0) {
  <<CODE_BC>>;
}

where CODE_BC is:

<<CODE_BC>>:
  if (num < 0) {
    cout << "-";
    num = -num;
  }
  cout << "0.";
  ex = -ex;
  <<BC_CORE>>;
  cout << num;

The BC_CORE can be something like the code in CODE_B, with its if-elseif lines, or like the code in CODE_C (just a for loop). It doesn't matter because both are wrong, but for consistency one or the other should be used for both num < 0 and num > 0 cases, the only logical difference being handled as shown in CODE_BC.

Stop the conio.h thing

When I reviewed students' code the conio.h was everywhere and I always explained why you shouldn't use it, nor add a pause at the end of your program: just run the program from a console — it seems hard to explain it to Microsoft Windows users, but if you study programming, you must know how to do it. Ask your teacher.

Now, why those students (and few professors told them it was ok) feel the need to add a pause at the end of the program?

They work in an IDE, maybe Microsoft Visual C++. They run the program from inside it, hence without a console for the console output, which is where text would go when you write cout << "hello". When the program starts and try to write to console, the system (I don't care to be more precise here) opens a console to give room to the text the program is output. But that console exists as long as the program exists; this is why it suddenly disappear when the program ends, giving you no time to read whatever the program output.

This is why students add a pause. Anything can work, even the reading of another input which then isn't used; like this:

string s;
cin >> s;

This is ugly, too, but avoids the inclusion of a library which is for Microsoft Windows. Students should learn to write code which can work on any system where a standard C++ compiler exists, i.e. code written in standard C++ using the standard C++ libraries and nothing else.

Conclusion

I hope I wasn't too harsh with the author and his post itself; but it isn't just the code which smells: the plauding comments are suspect, and the post is too careless (dump the crap code here), and nonetheless it has too much value already, without having any merits. It jeopardize the quality of steemit giving a bad content which teaches wrong things.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

I stumbled upon these posts from @learnandgrow as well. This clearly is just some scheme to hide self voting.
Unfortunately the programming tag on STEEM isn’t curated a lot such that it is a joke compared to the /r/programming sub on Reddit.

Thanks for your resteem @xinta.
As i see you really spend a lot of times doing post and adding quality. Hope you get the views and the rewards you deserve.

Have a good day and thanks! :)

Thank you. I tried, and try, to do my best.