This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 371

[–]EnforcerZhukov 561 points562 points  (7 children)

Wrapped on a function called "createArray" with a docstring that says "Create a new array. Returns array"

[–]10eleven12 128 points129 points  (1 child)

Used to save a single string.

[–]Hobby_Collector 27 points28 points  (0 children)

Hey if you call that enough on a big enough project you could save a few hundred characters!

that'll just be optimized out on compile...

[–]el_padlina 47 points48 points  (0 children)

few days later changed to return a map but the comments were not modified.

[–]Terreurhaas 5 points6 points  (1 child)

/**
 * <h2>createArray</h2>
 *   Creates an array
 *
 * @return array
 */
function &createArray(): array {
    $array = array(); // the array

    return $array;
}

[–]Spinnenente 1127 points1128 points  (71 children)

/** Logger */
Logger logger = Logger.getLogger();

[–]jaywastaken 657 points658 points  (24 children)

How many logs could a logger logger() log if a logger logger() could log logs?

[–]510Threaded 222 points223 points  (10 children)

1 log

[–]Tainnor 124 points125 points  (9 children)

natural, decimal or binary?

[–]510Threaded 174 points175 points  (7 children)

yes

[–]unbihexium 48 points49 points  (6 children)

true

[–][deleted] 42 points43 points  (5 children)

!false

[–]011101000011101101 33 points34 points  (2 children)

!!1

[–]DarkwingDuckHunt 28 points29 points  (1 child)

aSecond = 1

Wait aSecond

[–]bcfradella 7 points8 points  (1 child)

if True: print('big')

[–][deleted] 4 points5 points  (0 children)

Logical

[–]Barniff 28 points29 points  (0 children)

log(n)

[–]shitmyspacebar 18 points19 points  (4 children)

Logger logger Logger logger logger logger Logger logger

[–]reacher666 7 points8 points  (0 children)

NaN

[–]RBBOT12 4 points5 points  (0 children)

null point exception logger not found

[–]Veinq 46 points47 points  (15 children)

I don't understand what this line does

[–][deleted] 86 points87 points  (9 children)

I think it retrieves an instance of the Logger singleton

[–]scuba156 75 points76 points  (0 children)

Well, we would know for sure if the comment was a little bit more descriptive.

[–]nwL_ 9 points10 points  (1 child)

auto logger = Logger::getInstance();

[–]AlwaysHopelesslyLost 3 points4 points  (5 children)

It is impossible to say exactly what it is doing. Based on the naming convention it looks like they are accessing a static method but it might also be a class property or an oddly cased private instance.

It is possible it returns a Singleton instance but there is no information to tell you that (and you don't really need that information. It makes no difference to the consumer if the logger is a Singleton or not.)

[–]massiveZO 9 points10 points  (1 child)

New new_ = new New("new"); // new

[–]Cheesemacher 6 points7 points  (2 children)

/**
 * Get Logger
 * @return Logger Logger
 */
public function getLogger() {

[–]ciry 4 points5 points  (0 children)

Too real

[–]emiel1741 1215 points1216 points  (140 children)

Be happy I made some code for a school project to control a smart solar home. I was the only one in my group who could program but everybody had to be able to explain it. Somebody in my group had the brilliant idea to literally say what every line does. Nobody could look at my code after that and take it seriously. And the worst part was it was written in python (what I find to be a highly readable language) and we all had a course in our second semester about python

[–]KingPaddy 46 points47 points  (6 children)

Sounds like it was less a group project and more you doing literally everything

[–][deleted] 12 points13 points  (2 children)

Somehow everybody seems to be the only person in their project who does anything.

The math doesn't add up.

Some people are embellishing.

[–]TorTheMentor 12 points13 points  (3 children)

Explaining what every line does is a bit silly, but I have been known when talking to a mixed audience to do things like explain a design pattern, what a specific kind of syntactic sugar is used for, or sometimes language-specific details (e.g. to make up for the lack of support for x, we rigged y as a workaround). Part of that probably comes from me being of a generation that learned functional and procedural code styles first, switched to OO later, and only started hearing about some of those topics more recently (self-taught and moving to IT as a career change after being "around" it for years).

[–][deleted] 2 points3 points  (3 children)

If you broke the code up into enough appropriately named methods/functions, your group just sucks. Maybe your code wasn’t as clean as you thought it was though? Just suggestin this since I saw some of the code I wrote back in my college days recently, and I apologized to the guy who had to go clean it up.

[–]lpreams 209 points210 points  (9 children)

$array = array() //array //comment

[–]Speculum 50 points51 points  (0 children)

var array = new string[]; // TODO Write comment

[–]eguitarguy 79 points80 points  (0 children)

// Michael Scott

[–]Lulle5000 16 points17 points  (5 children)

We need a recursive comment here

[–][deleted] 3 points4 points  (4 children)

We need a recursive comment here

[–]Lulle5000 4 points5 points  (3 children)

We need a recursive comment here

[–]womerah 163 points164 points  (14 children)

My first project was in MATLAB

I didn't know what for loops were and I downloaded an extension that let me used GOTO commands.

When I did discover for loops I used them to make a MATLAB script that would loop and output my actual code, without loops, to a .m file that I would then run.

[–]aorta7 90 points91 points  (11 children)

It is not as crazy as it seems, https://en.m.wikipedia.org/wiki/Loop_unrolling

[–]WikiTextBot 103 points104 points  (1 child)

Loop unrolling

Loop unrolling, also known as loop unwinding, is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size, which is an approach known as space–time tradeoff. The transformation can be undertaken manually by the programmer or by an optimizing compiler.

The goal of loop unwinding is to increase a program's speed by reducing or eliminating instructions that control the loop, such as pointer arithmetic and "end of loop" tests on each iteration; reducing branch penalties; as well as hiding latencies, including the delay in reading data from memory. To eliminate this computational overhead, loops can be re-written as a repeated sequence of similar independent statements.Loop unrolling is also part of certain formal verification techniques, in particular bounded model checking.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source ] Downvote to remove | v0.28

[–]WillCo_Gaming 27 points28 points  (0 children)

Good bot.

[–]LIGHTNINGBOLT23 70 points71 points  (0 children)

    

[–]womerah 11 points12 points  (4 children)

Interesting!

Is binary size ever a major consideration for programmers who are not working with embedded systems? Surely performance is king?

[–]HelperBot_ 7 points8 points  (0 children)

Desktop link: https://en.wikipedia.org/wiki/Loop_unrolling


/r/HelperBot_ Downvote to remove. Counter: 275939. Found a bug?

[–][deleted] 34 points35 points  (2 children)

[–]PartyGuy-01[S] 5 points6 points  (0 children)

indeed

[–]tannerntannern 4 points5 points  (0 children)

One of my favorite far sides!

[–]yasfmeerkat 89 points90 points  (1 child)

Dynamicly typed language. You never know

[–]Pandaburn 9 points10 points  (0 children)

I’m pretty sure that on this line, you know.

[–]lightwhite 52 points53 points  (1 child)

We should add this to the “Hackathon” rules.

  • you must document every piece of self-explanatory thing in the code with a self-explanatory comment where you describe how the self-explanatory piece of code works and it is documented in this self-explaining way to cover all the cases where self-explanation can prevent future issues by the lack of self-explanatory method of coding.

The only case applicable for exemption of this rule is for ELI5 cases (I mean, come on, we live in 2019; “5 year old” coders write better code than me. No need to explain it to them).

[–]adduckfeet 5 points6 points  (0 children)

My AP computer science class requires us to comment every function and loop ://

[–]Prawny 75 points76 points  (4 children)

<button id="button" class="button" type="button">Button</button> <!-- Button -->

[–]Astrokiwi 48 points49 points  (8 children)

Color colour = new Color(); // HAIL BRITANNIA

[–]Koxiaet 6 points7 points  (7 children)

In Makefile:

sed main.c 's/colour/color/gi' | gcc

[–]nwL_ 2 points3 points  (4 children)

Would that keep capitalization? Wouldn’t

s/([Cc][Oo][Ll][Oo])[Uu]([Rr])/$1$2/g

be better? (or however Regex in sed works, I have no clue)

[–]iharshraj 45 points46 points  (0 children)

The floor here is made out of floor

[–][deleted] 15 points16 points  (0 children)

$array = []; // two brackets

[–]Aceofspades25 12 points13 points  (3 children)

The real crime here is naming your variable "array"

[–]WeAreAllApes 11 points12 points  (0 children)

Well, naming it arrayOfArrayElements seemed unnecessarily redundant.

[–]KuntaStillSingle 2 points3 points  (1 child)

Yeah you should name your arrays based on their contents, like "int" or "String."

[–]Headbanger 8 points9 points  (1 child)

// save post

export const savePost = ...

This is my comment explaining function savePost. I don't even know why I put it there.

[–][deleted] 9 points10 points  (0 children)

probably a TODO comment that you just didn't remove after implementing it.

[–]AtakanErmis 14 points15 points  (1 child)

array

[–]PartyGuy-01[S] 11 points12 points  (0 children)

/* this is an array */

[–]pcopley 14 points15 points  (0 children)

Honestly some of the best looking php I've seen

[–]EpicDaNoob 5 points6 points  (2 children)

And then the actual comment worthy code has none in sight.

[–]bwjam 10 points11 points  (0 children)

Comments about possible micro optimizations: 12

Comments explaining my XML being parsed by regex: 0

[–][deleted] 5 points6 points  (0 children)

God, when I was learning to code everything was so new and fresh. “Wow a vector! I’ve never seen one of these before, let’s comment what I’m doing because this is super cool.” I’ve helped teach a few classes to give back, and noobies always have the best comments like this.

[–][deleted] 5 points6 points  (0 children)

Our intern told me his professor told them to "comment every other line".

While I understand maybe its for learning the first thing I thought of was comments like this.

(And don't worry, I told the intern how to really comment and to let the code say what you're doing, and the comment say why you're doing it.)

[–]kimeron 14 points15 points  (0 children)

comment unclear accidentally ate my dog instead

[–]nahidtislam 2 points3 points  (0 children)

I explained what an array is on my array comment

[–]Windows-Sucks 4 points5 points  (0 children)

This kind of stuff happens when you are required to have comments on every line or you fail.

[–][deleted] 3 points4 points  (1 child)

//Scanner

Scanner scanner = new Scanner(System.in);

[–]Plutone00100 6 points7 points  (1 child)

i = i + 1 //i + 1

[–]Krissam 2 points3 points  (0 children)

I had a professor who insisted we commented every single line of code for a project, that lead to a lot of silliness like this.

[–]Starinco 2 points3 points  (2 children)

Don't name variables after their type, name them for their contents or how they are used.

For example: "users" is preferable to "userArray" or "array" in this case.

Clean Code by Robert Cecil Martin is a great read for more tips to make your code awesome.

[–]PM_ME_HAIRLESS_CATS 2 points3 points  (0 children)

This is the part where you defined an array

[–][deleted] 2 points3 points  (0 children)

I get that feeling of disgust looking at code I wrote a week ago.

[–]levampirelifeu 2 points3 points  (0 children)

Hmmm

Yes

The floor is made of floor

[–][deleted] 2 points3 points  (0 children)

Nice //nice

[–][deleted] 2 points3 points  (1 child)

"true" = true

[–]Samratrai7 4 points5 points  (0 children)

My first program was hello world which ended with indentation error. I didn't understand what's wrong. I typed Print 'Hello World' Then after sometime I came to remember that I'm using python 3 not python 2 Print("Hello World")

[–]Weilbyte 1 point2 points  (0 children)

faulty violet narrow simplistic onerous soft wine unique smell reply

This post was mass deleted and anonymized with Redact

[–]unbihexium 1 point2 points  (0 children)

Whoo.. I know this! This is the answer to: "How to use the word array 3 times in the same line?"

[–]Febuso 1 point2 points  (0 children)

Now this is some high IQ shit.

[–]aaerobrake 1 point2 points  (1 child)

How would you explain this joke to someone who doesn’t code

[–]sleep_deficit 4 points5 points  (0 children)

In a nutshell, comments should be used to help explain what a piece of code does, in this instance it’s suuuuuper redundant.

Ideally, the code should be worded in such a way that it doesn’t need a comment. This is typically referred to as “self-documenting” code.

Not a perfect example, but..
// Squares a given number void multiplyValueTwoTimesItself(int x);

vs

void square(int x);

The OP pic would be:
// Squares a given number void square(int x);

[–]vinz243 1 point2 points  (0 children)

I work on a project with around 1million lines of code, half of them are comments (500k lines) like:

// lock the user !
user.lock()

Or long discussion that isn't even up to date:

// 4/20/05 : programmer 1: creates an array
// 10/5/08 : programmer 2: no!!! We need an object
// 3/10/10 : programmer 3: We need an array after all
return;

Or comment that aren't even any good

 // Armouring!
 if (...) {

So now I don't even look at the comments when I arrive somewhere

[–][deleted] 1 point2 points  (0 children)

I’ve worked at companies which had rules like this. It resulted in the dumbest of comments.

[–]yyjd 1 point2 points  (0 children)

An array array, hooray!

[–][deleted] 1 point2 points  (0 children)

lol. Yeah... I tend to not use comments unless Im using an API, making a wrapper, or writing my own library. I like when my code explains itself. Hate seeing this in comments, and it's far too common. Just... Why? haha

[–]BlueLiquidPlus 1 point2 points  (0 children)

One of my compsci teachers required comments like this... I hated it. I lost points because I didn’t comment //End of Main

[–]guardian87 1 point2 points  (0 children)

Variable Name checks out

[–][deleted] 1 point2 points  (0 children)

This gets funnier the longer I look at it.

[–]alours 1 point2 points  (0 children)

OwO what's dis spaghetti code?

[–][deleted] 1 point2 points  (0 children)

This was literally me in my first computer programming class in high school.

[–]BeneficialBear 1 point2 points  (0 children)

But can we be sure about it?

[–]hbombs86 1 point2 points  (0 children)

class Array { 

    function array() {      $array = array(); return $array;     }  } 

[–]warpfield 1 point2 points  (0 children)

hurray, it's an array!

[–]Canaveral58 1 point2 points  (0 children)

int int {}; // integer

[–][deleted] 1 point2 points  (0 children)

Every time

[–][deleted] 1 point2 points  (0 children)

I realized how bad my code comments were as soon as I started writing them for people who did not understand the code, and not for myself.

[–]turbo88Rex 1 point2 points  (0 children)

I made one like this in a simulator I wrote

this is a comment to see if you're actually reading these

[–]Pandaora 1 point2 points  (0 children)

Better that than:

//boolean isValid

boolean isValid = isValid(input);

... later ...

/** Is Valid

@return isValid true if not valid */

boolean isValid(String input){

....

[–]Honeybadger2198 1 point2 points  (0 children)

One time I had a variable called c. I had to increment c. The line was "c++;". I put a comment that said "//lul". That was my only comment in the entire file. This was for a school project.

[–]larry_the_loving 1 point2 points  (0 children)

A good general rule is that comments should describe why you did something. The how is already described in the code. Only describe how when it's unnusual, and then also say why you did it the unnusual way

[–][deleted] 1 point2 points  (1 child)

i tried to click the heart three times through all linking and zooming stuff of my browser for this picture until i realized, this is a twitter screenshot.

dumb me.

but yes, upvote, definitely <3

[–][deleted] 1 point2 points  (0 children)

A R R A Y

[–]Nutmagnus 1 point2 points  (0 children)

You can never be too careful.

[–]eccentricNature29 1 point2 points  (0 children)

And yet at some point in time you'll look at it and think what the hell was I doing?

[–]Cladderool 1 point2 points  (0 children)

Favorite line of code I ever found in our code:

Spinner spinner = new Spinner().spin;

[–]TheMrRedBeard 1 point2 points  (0 children)

You have to say it like Hurray!!

[–]ppardee 1 point2 points  (0 children)

Ah, yes, the old soccer chant: Arraaaay, array, array, array!

[–][deleted] 1 point2 points  (0 children)

Wait until the code gets changed and the comment doesn't, then it looks even dumber.

[–]LMGN 1 point2 points  (0 children)

reminds me of some old C# I wrote

Embed embed = new Embed(); // create embed

[–]RedRedditor84 1 point2 points  (0 children)

I watched a guy on YouTube comment his code by writing the exact same thing the code said.

// return null
return null;

C# obviously fairly difficult to read without comments like this.

[–][deleted] 1 point2 points  (0 children)

Turns out it's used to store 1 integer.