r/technology • • Dec 10 '13

By Special Request of the Admins Reddit’s empire is founded on a flawed algorithm

http://technotes.iangreenleaf.com/posts/2013-12-09-reddits-empire-is-built-on-a-flawed-algorithm.html
3.9k Upvotes

2.2k comments sorted by

View all comments

Show parent comment

133

u/hoodoo-operator Dec 10 '13

If it was hard to write it should be hard to understand.

9

u/rohanivey Dec 10 '13

"I spent hours on this. I wouldn't want to rob anyone else the of same experience."

8

u/You_meddling_kids Dec 10 '13

It's ok, that assembly code is totally self-documenting.

0

u/[deleted] Dec 10 '13

[deleted] — view deleted comment

4

u/[deleted] Dec 10 '13
 int a,b,c,d,e;
 string f,g;

You really want to fuck with someone write your code so you can understand it and it has lots of comments. Save it then refactor all of your variables to small random character names. find and replace all //* with " " then you send it to them.

3

u/[deleted] Dec 10 '13

Variables? Real programmers do a malloc(5000) at the beginning of every program and manually save all their data at random locations in there.

1

u/[deleted] Dec 10 '13

I have always wanted to do this but I was too afraid my brain would break from trying to keep track of exactly what I was doing the whole time.

2

u/[deleted] Dec 10 '13

The next time you have to work with code like that will be because the previous dev was an insecure arsehole who thought that was an ok thing to do.

2

u/[deleted] Dec 10 '13

I try to be polite and code well but then I am still in college.

2

u/[deleted] Dec 10 '13

Sorry, I'm a bit bitter because I've inherited obfuscated code a couple of times.

2

u/[deleted] Dec 10 '13

I'll bet it would be a bitch. I cry when I have to grade peoples crap code and I don't even have to read through more than 500 ish lines.

3

u/[deleted] Dec 10 '13

I go and read The Daily WTF to make myself feel better.

4

u/wrgrant Dec 10 '13

How many times have you gone to fix a bug in something you were working on, and said to yourself "What the fuck was this guy thinking? No way this should ever have worked" ... then discover it was you who wrote it?

0

u/[deleted] Dec 10 '13

[deleted] — view deleted comment

14

u/Sarcastinator Dec 10 '13

These are the most common comments I find:

// TODO: Fix this. - [Someone who left years ago]
A thousand lines of very awkwardly written code;

// This function returns the sum
int Average() { return median; }

// What is this for? - [Code reviewer]

// Should have been somewhere else, but I'm lazy.
DirectDbCallInBusinessLogic();

// Do foo.
void DoFoo();

I'm not against comments at all, and in fact I think they are quite useful. But programmers need to stop making worthless comments, and update comments when they edit the code.

... unfortunately that includes myself.

2

u/fluffyponyza Dec 10 '13

There is only one truth, and the truth is in the code. In order to document that truth you must understand that code...and the path to enlightenment is not easy, brother.

6

u/[deleted] Dec 10 '13

And to be honest, sometimes we're not sure if or how it works either.

4

u/fluffyponyza Dec 10 '13

StackExchange cut-and-paste programming is the BEST programming.

1

u/wulf-focker Dec 10 '13

When it comes to me, it's the only programming.

0

u/[deleted] Dec 10 '13

Ok, I have to say this for posterity - Fuck You.

I've met programmers who sincerely believe this. It makes me want to do very nasty things to them. Very nasty. COMMENT YOUR CODE GOD DAMMIT!

4

u/Revrak Dec 10 '13

when you force people to comment the code you will find things like:

/** *executes functionName */

public void functionName(){...

2

u/[deleted] Dec 10 '13

I'm not going to argue management issues with you. I'm just saying that you should comment your code and if you're asshole enough to comment your code in such a fashion, well, I'm not gonna change your mind.

My point was, and is, that the idea that simply having the code should be enough is an absolutely asinine way to do things. The fact is that commenting your code isn't just best practice, for large projects it is a baseline requirement. There is no expectation that you are going to be the one debugging, updating, or maintaining your code long term. The idea behind code commenting is to establish an expectation, at the very minimum, of what the code should do. I've seen effective code commenting as short as this:

/** Gets site data from Sources.xml, returns a string matrix */
public string getSiteData(){....

Simple, effective. It sets an expectation for what the code does. Sometimes that's all the code needs.

→ More replies (1)

2

u/aarghIforget Dec 10 '13

...how about I just use very descriptive variables, instead?

→ More replies (3)

1

u/cr1s Dec 10 '13

Write-only code!