玩转代码:32个有趣的代码注释
源码共读
共 10758字,需浏览 22分钟
· 2020-04-10
作者丨读芯术
来源丨读芯术(AI_Discovery)
代码注释是一种用“高级”英语陈述,描述程序将要做什么的“艺术”。有人嫌它丑,也有人觉得它还蛮有用的。 但还有一些“闷骚”的程序猿,早已把代码注释玩儿出了花。玩梗、吐槽、画画……还有什么是他们不能做的?
下面一起来欣赏一些有趣的代码注释吧~
注意:内容很长,毫不严肃,仅供消遣!
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 age
public 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 function
function 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 sorry
Few 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
图源:unsplash// somedev1 - 6/7/02 Adding temporary tracking of Loginscreen
// somedev2 - 5/22/07 Temporary my ass
//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 forces
without 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
end
## Safety pig has arrived!
text = h(text)
## _
## _._ _..._ .- , _.._(`))
## -. ` /-._.- ,/
## ) .
## / _ _ |
## | a a / |
## .-. ;
## -( ).- , ;
## -; | .
## /
## | 7 .__ _.-
## | | | ``/ /` /
## /,_| | /,_/ /
## /,_/ `-
##
//I m sorry, but our princess is inanother castle.
long long ago; /* in a galaxy farfar away */
try {
} finally { // should never happen
}
/*
* You may think you know what thefollowing code does.
* But you dont. Trust me.
* Fiddle with it, and youll spend many asleepless
* night cursing the moment you thoughtyoud be clever
* enough to "optimize" thecode below.
* Now close this file and go play withsomething else.
*/
//If you even THINK of changingthis code, you may have already gone //too far
// Replaces with spaces the bracesin cases where braces in places //cause stasis
$str =str_replace(array("{","}")," ",$str);
/* Ah ah ah! You ll neverunderstand why this one works. */
// This only exists because Scottdoesn t know how to use const //correctly
// All this code is yours, exceptgedit()...attempt no modifications //there.
else
{
// wobbly wilson said this would*never* happen!!
}
//this formula is right, work outthe math yourself if you don t believe me
stop(); // Hammertime!
// Abandon all hope you who needsto debug this
//This was clearly written underduress
doRun.run(); // ... "a doo run run".
// Whoever put this here is anidiot…this doesn’t work at all !
// TODO make this work
.= .`/,/!(=)Zm.
.._,,._.. ,-`- `, ` -` -`\7//WW.
,v=~/.-,---!|V-s.)iT-|s|-. `///mK%.
v!`i!-.e]-g`bT/i(/[=.Z/m)K(YNYi.. /-]i44M.
v`/,`|v]-DvLcfZ/eV/iDLND/ZK@%8W[Z.. `/d!Z8m
//,c(2(X/NYNY8]ZZ/bZd()/WY%WKKW) - |(][%4.
,\ic(e)WX@WKKZKDKWMZ8(b5/ZK8]Z7%ffVM, -.Y!bNMi
/-iit5N)KWG%%8%%%%W8%ZWM(8YZvD)XN(@. [ ]!/GXW[
/))G8NMN%W%%%%%%%%%%8KK@WZKYK*ZG5KMi,- vi[NZGM[
i!(44Y8K%8%%%**~YZYZ@%%%%%4KWZ/PKN)ZDZ7 c=//WZK%!
,YtMZW8W%%f`,`.t/bNZZK%%W%%ZXb*K(K5DZ -c\/KM48
-|c5PbM4DDW%f v./c[tMY8W%PMW%D@KW)Gbf -/(=ZZKM8[
2(N8YXWK85@K - c|K4/KKK%@ V%@@WD8e~ .//ct)8ZK%8`
=)b%]Nd)@KM[ ! cG!iWYK%%| !M@KZf -c))ZDKW%`
YYKWZGNM4/Pb -VscP4]b@W% Mf` -L///KM(%W!
!KKW4ZK/W7)Z. /cttbY)DKW% -` . ,)K(5KW%%f
W)KWKZZg)Z2/,!/L(-DYYb54% ,,`, --/v(((KK5WW%f
M4NDDKZZ(e!/7vNTtZd)8Mi!-,-/i-v((tKNGN%W%%
M8M88(Zd))///((|DDY\KK-`/-i(=)KtNNN@W%%%@%[
!8%@KW5KKN4///s(Pd!ROBY8/=2(/4ZdzKD%K%%%M8@%%
%%%W%dGNtPK(c/2[Z(ttNYZ2NZW8W8K%%%%YKM%M%%.
*%%W%GW5@/%!e]_tZdY()v)ZXMZW%W%%%*5Y]K%ZK%8[
*%%%%8%8WK)[/ZmZ/Zi]!/M%%%%@f Y/NNMK%%!
VM%%%%W%WN5Z/Gt5/b)((cV@f` -|cZbMKW%%|
V*M%%%WZ/ZG5((+)L -,,/ -)X(NWW%%
`~`MZ/DZGNZG5(((, ,t\Z)KW%@
M8K%8GN85(5///]i!vK)85W%%f
YWWKKKKWZ8G54X/GGMeK@WM8%@
!M8%8%48WG@KWYbW%WWW%%%@
VM%WKWK%8K%%8WWWW%%%@`
~*%%%%%%W%%%%%%%@~
~*MM%%%%%%@f`
// If you delete the credits, I will fucking kill you.
/************************************************************
* *
* .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. *
* | ______ | *
* | .-" "-. | *
* | / | *
* | _ | | _ | *
* | ( |, .-. .-. ,| / ) | *
* | > "=._ | )(__/ __)( | _.=" < | *
* | (_/"=._"=._ |/ / | _.="_.="_) | *
* | "=._"(_ ^^ _)"_.=" | *
* | "=__|IIIIII|__/=" | *
* | _.="| IIIIII/|"=._ | *
* | _ _.="_.=" /"=._"=._ _ | *
* | ( _.="_.=" `--------` "=._"=._/ ) | *
* | > _.=" "=._ < | *
* | (_/ _) | *
* | | *
* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= *
* *
* LASCIATE OGNI SPERANZA, VOICH ENTRATE * LEAVE EVERY HOPE, YOU COME IN
*************************************************************/
// If I from the future read thisI ll back in time and kill myself.
// TODO: Fix this. Fix what?
/*
This isn t the right way to deal with this, but today is my last day, Ron
just spilled coffee on my desk, and I m hungry, so this will have to do...
*/
return 12; // 12 is my lucky number
using namespace std; // So sue me
你还见过哪些有意思的代码注释?
近期精彩内容推荐:
在看点这里好文分享给更多人↓↓
评论
真高!比亚迪员工爆料比亚迪在越南的薪资水平:基本工资480万,全勤奖35万,交通补助20万,餐补110万,每周6天,每天10小时
上一篇:某大公司为逼迫员工离职,竟然把他的工位安排到厕所旁,没想到他直接开始记录领导的如厕时间,还发到公司大群...对此,你怎么看?--完--PS:欢迎在留言区留下你的观点,一起讨论提高。如果今天的文章让你有新的启发,欢迎转发分享给更多人。全文完,感谢你的耐心阅读。如果你还想看到我的文章,请一定给本
开发者全社区
0
太敢穿了!透视纱裙!性感火辣的身材
绝了呀今天的厂花:吴宣仪1995年1月26日,吴宣仪出生于海南省海口市,中国内地流行乐女歌手、影视演员。2016年2月,吴宣仪随宇宙少女发行首张迷你专辑正式出道。2018年4月,她参加《创造101》综艺选秀,获得第二名,成功加入火箭少女101组合。吴宣仪的颜值一直备受称赞,她的五官立体精致,皮肤白皙
逆锋起笔
0
某大公司为逼迫员工离职,竟然把他的工位安排到厕所旁,没想到他直接开始记录领导的如厕时间,还发到公司大群...
上一篇:字节的跳动职级与薪资(2024年)我们与公司间的合作,宛如两艘船只在茫茫大海上相互依靠,共同抵御风浪,携手驶向成功的彼岸。然而,当航向开始产生分歧,或是波涛汹涌的风浪改变了我们的初衷,我们或许应当冷静地选择和平分手,而非在风雨中硬撑。最近,一位网友的遭遇引起了广大职场人的关注和热议。这位网友
开发者全社区
0
金融研究 | 使用Python测量关键审计事项的「信息含量」
Tips: 公众号推送后内容只能更改一次,且只能改20字符。如果内容出问题,或者想更新内容, 只能重复推送。为了更好的阅读体验,建议阅读本文博客版, 链接地址https://textdata.cn/blog/2023-01-13-information-content-of-critical-aud
大邓和他的Python
0
我看阿里的年终奖总算发了!
到4月底了,这两天看朋友圈,发现阿里的年终奖终于发了,问了问老同学,也从网上检索了不少信息,基本搞清楚了阿里今年的年终奖情况。近来来阿里一些集团对绩效等级做了较大的调整,以前的旧绩效系统中,绩效分为3.25、3.5、3.75、4和5五个等级,其中4和5是较高绩效等级,较少见。而且之前3.5绩效内部划
公子龙
0
CVPR 2024|大视觉模型的开山之作!无需任何语言数据即可打造大视觉模型
↑ 点击蓝字 关注极市平台作者丨科技猛兽编辑丨极市平台极市导读 本文提出一种序列建模 (sequential modeling) 的方法,不使用任何语言数据,训练大视觉模型。>>加入极市CV技术交流群,走在计算机视觉的最前沿本文目录1 序列建模打造大视觉模型(来自 U
极市平台
1
金融研究(更新) | 使用Python构建关键审计事项的「信息含量」
Tips: 公众号推送后内容只能更改一次,且只能改20字符。如果内容出问题,或者想更新内容, 只能重复推送。为了更好的阅读体验,建议阅读本文博客版, 链接地址https://textdata.cn/blog/2023-01-13-information-content-of-critical-aud
大邓和他的Python
0
字节的跳动职级与薪资(2024年)
上一篇:阿里公布年终奖,P7, 3.5+,22W年终奖,还有35W长期现金激励,真香字节跳动自2012年3月成立以来,已经迅速成长为一个全球性的科技公司。其产品和服务已经遍布全球150多个国家与地区,并且支持超过75种不同的语言。在字节跳动的官方网站上,列出了一系列引人注目的产品和服务,包括但不限于
开发者全社区
0