令人笑喷的 56 个代码注释,你写过多少?

小灰灰 2022-09-06 15:15 65阅读 0赞

来源 | 程序员的幽默

老衲不请自来,

给大家献上一波神注释

供施主们娱乐娱乐

0a38491b4c30c9bfdb8ed482fc83130b.gif

0.

  1. /*
  2. * Dear Maintainer
  3. *
  4. * Once you are done trying to ‘optimize’ this routine,
  5. * and you have realized what a terrible mistake that was,
  6. * please increment the following counter as a warning
  7. * to the next guy.
  8. *
  9. * total_hours_wasted_here = 73
  10. *

亲爱的维护者

如果尝试对这段程序进行’优化’

并且您已经意识到这是一个多么可怕的错误,

请增加以下计数器的个数用来对后来人进行警告

这里总共浪费的时间= 73

1.

  1. Exception up = new Exception("Something is really wrong.");
  2. throw up; //ha ha

例外=新的异常(“确实有问题。”)

放弃; //哈哈

2.

  1. // When I wrote this, only God and I understood what I was doing
  2. // Now, God only knows

当我写下这个的时候,只有上帝和我明白我在做什么

现在,只有上帝知道

3.

  1. // sometimes I believe compiler ignores all my comments

有时,我会相信编译器会忽略我所有的注释

4.

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

谨以此代码,献给我的妻子达琳,感谢她一直支持着我,以及我的三个孩子和一条狗。

5.

  1. // drunk, fix later

喝多了,改天再修

6.

  1. // Magic. Do not touch.

魔法!不要碰。

7.

  1. // I'm sorry.

抱歉。

8.

  1. return 1; # returns 1

返回 1;# 返回 1

9.

  1. Catch (Exception e) {
  2. //who cares?
  3. }

捕获(异常e)

谁在乎?

10.

  1. /**
  2. * Always returns true.
  3. */
  4. public boolean isAvailable() {
  5. return false;
  6. }

代码返回 false ,注释则始终返回 true

11.

  1. /*
  2. * You may think you know what the following code does.
  3. * But you dont. Trust me.
  4. * Fiddle with it, and youll spend many a sleepless
  5. * night cursing the moment you thought youd be clever
  6. * enough to "optimize" the code below.
  7. * Now close this file and go play with something else.
  8. */

你可能相信你能看懂以下代码,

但是其实绝对不可能,相信我。

一旦你调试了,你绝对会后悔装聪明去尝试优化这段代码。

最好的方式是关闭文件,

去玩点儿你喜欢的东西吧!

12.

  1. try {
  2. } finally { // should never happen
  3. }

绝对不会运行到这里

13.

  1. const int TEN=10; // As if the value of 10 will fluctuate...

好像 10 的值会波动…

14.

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

这段代码的确很烂,我知道你也知道,

先不要骂我,请先接着往下看

15.

  1. // If this comment is removed the program will blow up

如果删了此处注释,程序就炸了

16.

  1. // I am not responsible of this code.
  2. // They made me write it, against my will.

我不负责这个代码

他们强迫我写,违背了我的意愿。

17.

  1. /* Please work */

请工作

18.

  1. // no comments for you
  2. // it was hard to write
  3. // so it should be hard to read

没有注释,

很难写,

所以它应该很难阅读

19.

  1. options.BatchSize = 300; //Madness? THIS IS SPARTA!

疯了吧?这是斯巴达!

20.

  1. // If this code works, it was written by Paul DiLascia.
  2. // If not, I don't know who wrote it

如果这个代码能够正常工作,那么是Paul DiLascia写的

否则,我也不知道是谁写的

21.

  1. // Peter wrote this, nobody knows what it does, don't change it!

这是彼得写的,没人知道它是做什么的,别改动!

22.

  1. /** Logger */
  2. private Logger logger = Logger.getLogger();

不管怎么费尽心力,人会受伤的时候就会受伤。by 村上春树

23.

  1. // I have to find a better job

我必须找到更好的工作

24.

  1. // Real programmers don’t comment their code.
  2. // If it was hard to write,
  3. // it should be hard to understand.

真正的程序员不注释他们的代码。

如果很难写

应该是难以理解

25.

  1. // This is black magic
  2. // from
  3. // *Some stackoverlow link
  4. // Don’t play with magic, it can BITE.

这是来自stackoverlow的黑魔法

别玩魔法,它会咬人的

26.

  1. // For the sins I am about to commit, may James Gosling forgive me

对于我即将犯下的罪行,希望詹姆斯·高斯林(James Gosling)能原谅我

27.

  1. // Comment this later

稍后对此注释

28.

  1. // Remove this if you wanna be fired

如果你想被炒鱿鱼,就删除它

29.

  1. }catch(Exception ex){
  2. // Houston, we have a problem
  3. }

Houston,我们有一个问题

30.

  1. // I can’t divide with zero, so I have to divide with something very similar
  2. result = number / 0.00000000000001.

我不能除以0,所以我要除以一个非常相似的数

31.

  1. int getRandomNumber()
  2. {
  3. Return 4; // chosen by fair dice roll.
  4. // guaranteed to be random.
  5. }

通过公平掷骰子选择

保证是随机的

32.

  1. #TODO: Figure out what I’m doing here and comment accordingly.

弄清楚这里做什么并相应地添加注释

33.

  1. // If this code is still being used when it stops working, then
  2. // you have my permission to shoot me. Oh, you won't be able
  3. // to - I'll be dead...

如果这段代码停止工作时还在使用,

杀了我吧,哦~你不能这么做

我死了……

34.

  1. // If you are reading this, that means you have been put in charge of my previous project.
  2. // I am sorry, so sorry for you. Godspeed.

如果你看到了这里,这意味着你已经被任命为我之前的项目的负责人。

对不起,真抱歉。祝你好运。

35.

  1. // I wrote this while drunk, I don’t know what it does,
  2. // but if you remove it the program breaks.

我是在喝醉的时候写的,所以不知道它是干什么用的

但如果你删除它,程序就会中断

36.

  1. // This code worked before, but my cat decided to take a
  2. // trip across my keyboard...

这段代码以前是有效的,但是我的猫决定在我的键盘上跑一趟

37.

  1. long long ago; /* in a galaxy far far away */

在很远很远的银河系外 (这段代码能运行,绝对是个奇迹)

38.

  1. long john; // silver

金银岛

39.

  1. #define TRUE FALSE // Happy debugging suckers

快乐的去调试你的代码吧,哈哈

40.

  1. // Dear future me. Please forgive me.
  2. // I can't even begin to express how sorry I am.

未来亲爱的我,请原谅我

我说不出来我有多抱歉

41.

  1. // private instance variable for storing age
  2. public static int age;

用于存储年龄的私有实例变量

42.

  1. // I am not sure why this works but it fixes the problem.

虽然我不知道为什么这样管用,但它却是修复了问题

43.

  1. last = first; /* Biblical reference */

最后即是开始,圣经引用

44.

  1. try {
  2. } catch (SQLException ex) {
  3. // Basically, without saying too much, you're screwed. Royally and totally.
  4. } catch(Exception ex)
  5. {
  6. //If you thought you were screwed before, boy have I news for you!!!
  7. }

不用多说,基本上你完蛋了

45.

  1. // John! If you'll svn remove this once more,
  2. // I'll shut you, for God's sake!
  3. // That piece of code is not "something strange"!
  4. // That is THE AUTH VALIDATION.

如果你再删除一次

看在上帝的份上,我要关闭你

这段代码不是什么“奇怪的东西”

那就是身份验证

46.

  1. long time; /* know C */

过来很久时间才知道

47.

  1. // Abandon all hope ye who enter beyond this point

入此门者了断希望

48.

  1. /* Ah ah ah! You'll never understand why this one works. */

啊啊啊!你永远都不会明白为什么这个方法有效

49.

  1. catch (Ex as Exception) {
  2. // oh crap, we should do something.
  3. }

糟糕,我们应该做点什么

50.

  1. // TODO make this work

用TODO做这件事

51.

  1. // If you're reading this, then my program is probably a success

如果你现在在认真详细的阅读这段代码,那么写的这段代码应该是没有问题的

52.

  1. // set break point here - you'll never reach it

在这里设置断点-你永远作不到十全十美

53.

  1. /*
  2. ** The author disclaims copyright to this source code.
  3. ** In place of a legal notice, here is a blessing:
  4. **
  5. ** May you do good and not evil.
  6. ** May you find forgiveness for yourself and forgive others.
  7. ** May you share freely, never taking more than you give.
  8. */

作者放弃此源代码的版权

这是一份祝福,而不是法律通知

愿你行善不作恶。

愿你宽恕自己,宽恕他人

愿你自由分享,永远不要超过付出

54.

  1. // I'm not sure what I did

我不确定我做了什么

55.

  1. // This is crap code but it's 3 a.m. and I need to get this working.

这是垃圾代码,但现在是凌晨3点,我需要让他能够正常运行

动态黑色音符 END 动态黑色音符

2T 程序员大礼包大放送,包括 C/C++、Linux、Python、Java、PHP、人工智能、单片机、树莓派等。

关注公众号????,后台回复「1024」,即可免费获取!

发表评论

表情:
评论列表 (有 0 条评论,65人围观)

还没有评论,来说两句吧...

相关阅读