玩转代码:32个有趣的代码注释

全文共3581字,预计学习时长23分钟

图源:unsplash

代码注释是一种用“高级”英语陈述,描述程序将要做什么的“艺术”。有人嫌它丑,也有人觉得它还蛮有用的。

但还有一些“闷骚”的程序猿,早已把代码注释玩儿出了花。玩梗、吐槽、画画……还有什么是他们不能做的?

下面一起来欣赏一些有趣的代码注释吧~

注意:内容很长,毫不严肃,仅供消遣!

i++; //increment i

// Magic. Do not touch.

return 1; # returns 1

return null; //Not really null

// sometimes I believe compilerignores all my comments

// I am not responsible of thiscode.// They made me write it, against my will.

// I dedicate all this code, all mywork, to my wife, Darlene, who //will have to support me and our three childrenand the dog once it //gets released into the public.

# To understand recursion, see thebottom of this fileAt the bottom of the file# To understand recursion, see thetop of this file

//// Dear maintainer://// Once you are done trying to 'optimize' this routine,// and have realized what a terrible mistake that was,// please increment the following counter as a warning// to the next guy://// total_hours_wasted_here = 42

//private instance variable forstoring agepublic static int age;

//Dear future me. Please forgiveme.

//I can't even begin to express how sorry I am.

#define TRUE FALSE//Happy debugging suckers

//open lid

//take sh!t

//close lidComments for a File open, data dump, file close…

/* You are not meant to understandthis */

const int TEN=10; // As if thevalue of 10 will fluctuate...

//When I wrote this, only God and Iunderstood what I was doing

//Now, God only knows

/*

* TODO: Remove this functionfunction remove($customer_id)

{

$this->Customer->remove($id);

}

*/

// I'm sorry.

// drunk, fix later

// I am not responsible of thiscode.

//This code sucks, you know it andI know it.

/* Please work */

// I have to find a better job

// Joe is sorryA few hundred lineslater...// Harry is sorry too

Catch (Exception e) { //who cares?}

// IE7 update. this is still badcode, but IE8 is probably a long way off :)

#Christmas tree initializer

toConnect = []

toRead = [ ]

toWrite = [ ]

primes = [ ]

responses = {}

remaining = {}

// Remove this if you wanna befired

// somedev1 - 6/7/02 Adding temporary tracking of Loginscreen// somedev2 - 5/22/07 Temporary my ass

// no comments for you

// it was hard to write// so it should be hard to read

// This comment is selfexplanatory.

// If this code works, it waswritten by Paul DiLascia. If not, I don't know

// who wrote it

} catch (PartInitException pie) { // Mmm... pie

int main(void)/* Program starts here */

// Houston, we have a problem

// I am not sure if we need this,but too scared to delete.

// Autogenerated, do not edit. Allchanges will be undone.

// If this comment is removed the programwill blow up

//This code sucks, you know it andI know it. //Move on and call me an idiot later.

/**

* Always returns true.

*/public boolean isAvailable() { return false;

}

// hack for ie browser (assumingthat ie is a browser)

// Joe is sorryFew Hundred Lines Later// Harry is sorry too

///////////////////////////////////////this is a well commented line

Exception up = newException("Something is really wrong.");throw up; //ha ha

// TODO - Comment this function

//Mr. Compiler, please do not readthis.

//If you're reading this, then myprogram is probably a success

// All bugs added by David S.Miller

Catch (Exception e) { //eat it}

Repeat

...Until (JesusChristsReturn) // Not sure

// This should fix something thatshould never happen

// somedev1 - 6/7/02 Adding temporary tracking of Loginscreen// somedev2 - 5/22/07 Temporary my ass

图源:unsplash

//todo: never to be implemented

//I am not sure why this works butit fixes the problem.

/*** For the brave souls who get this far: You are the chosen ones,* the valiant knights of programming who toil away, without rest,* fixing our most awful code. To you, true saviors, kings of men,* I say this: never gonna give you up, never gonna let you down,* never gonna run around and desert you. Never gonna make you cry,* never gonna say goodbye. Never gonna tell a lie and hurt you.

*/

// simply copied from another code

//This is a kind of magic.

//Please comment on your sourcecode

int MyFunction(){ // There once was a man named Dave

int Result = 0; // Whose code just wouldn't behave

MyObject *Ptr = new MyObject(); // He left to go to a meetin'

Result = Ptr->DoSomething(); // And left his memory a leakin'

return Result;

}

////3.4 JeK My manager promised me a lap dance if I canfix this release//3.5 JeK Still waiting for that dance from my manager//3.6 JeK My manager got changed, the new manager ishairy, dont want the dance anymore//3.7 Jek Got that dance, yuck!//

public boolean isDirty() { //Why do you always go out and

return dirty;

}

# as you can see: I comment thecode!

// TODO: Finish.

/*after hours of consulting the tome of google

i have discovered that by the will of unknown forceswithout the below line, IE7 believes that 6px = 12px

*/

font-size: 0px;

public GetRandomNumber(){ // Chosen by a fairly rolen dice

return 12;

}

// *** drunk -- fix later ***

// TODO: Delete

// if i ever see this again i'mgoing to start bringing guns to work

图源:unsplash

// For the sins I am about tocommit, may James Gosling forgive me

def format_ticket_content(text,recursive = true)

if text.is_a?(TicketNote)

note = text

text = note.content

else

note = nil

打开APP阅读更多精彩内容