佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 2213|回复: 20

The Daily WTF 编译噩梦

[复制链接]
发表于 11-8-2006 07:44 AM | 显示全部楼层 |阅读模式

分享一个每个程式编写员都应该去浏览的网站。

The Daily WTF

它主要描述程式编译人员在这一行工作上所遇到的有趣的趣事,糊涂/可怕的编码,无能的同事/老板,公司等等。

里面有时会发表一些错误编译编写的例子,可能你作为程式编译人员不知不觉中就犯了以上的错误,大家应该去那边看一看。

今天的例子:

Brian 是一位资深软件工程师,几年前他进入一间大型保安系统公司替他们完成一个最新的保安系统产品,他们的产品已经严重延迟了,一些的 Subsystem 也出了问题, 截止日期越来越近。

第三天,在工作上 Brian 和一位领头开发人员 Jerry 开会, 主要是想了解 Project 的内情, Jerry 的自我介绍时说他有二十年的 C++ 经验, 可是 C++ 从推出到那时都没有 20 年。不要紧,很多人都是这样说的。

接着 Brian 继续跟进了解, 应为软件是跨平台的, 第一个问题是软件不能在 Unix 平台上编译。 Brian 觉得奇怪,既然是跨平台为何连编译都不能呢, Brian 就问 Jerry 如何开发, Jerry 的回答竟然是 VC++6 和 MFC, Brian 吓一跳以为 Jerry 在开玩笑。那里知道 Jerry 是认真的, Brian 作为一个好脾气和耐性好的人,只好慢慢解释说在 Unix 上是不可以用 MFC 的。Jerry 说他只会用 Windows, Jerry 还反问 Brian, Unix 不是 Based on Windows 的吗?

Brian 没有办法,只好跟老板解释说 Jerry 完全不是资深编写人员不符合资格。 老板和同事都很奇怪, Jerry 的拿手戏是 Threads, Jerry 是以 Multi-threads 开发出名的。

各位想了解 Jerry 在 Thread Coding 作了何事,自己去那边看。

Flossin' My Threads

评分

参与人数 1积分 +50 收起 理由
fxam + 50

查看全部评分

回复

使用道具 举报


ADVERTISEMENT

发表于 11-8-2006 10:10 PM | 显示全部楼层
WTF应该是指 wat the 罚 吧 ....
回复

使用道具 举报

 楼主| 发表于 14-8-2006 03:21 PM | 显示全部楼层

满足顾客要求

这个例子比较象顾客 WTF。 也很好笑一下。

有一个软件编译员以前的工作小组是创造 Automated Scanning System。 那个系统软件主要是控制 Scanning Head 扫描一个物品,然后把扫描资料 传回给软件的 Data Acquisition Module。 那位编译员的责任部分是要软件检查传送回来的资料是否和预订的 Criteria 一样,如果不是就 Reject 咯。 很简单。

当那个软件在分析的时候,会有一个弹出讯息说, “Analysis Working .........” , 再加上一个 Progress Bar。 完成后讯息关掉, Result 讯息出来。 起初这需要大概一分钟,而且还要看顾客设定的 Parameter 和需要扫描的物品有多大和资料的复杂性。 顾客投诉说软件运作太慢了。 那位软件编译员觉得 他有办法改进,就是采用 Real Time Detection, 一边扫描一边比对资料,所以扫描完毕过后, Progress 讯息弹出来,因为这时 Analysis Routine 只需要测试最后一批 Data, 所以很快就完成了, Result 讯息一下就弹出来。 编译员和顾客都很满意。

可是不久顾客又有投诉,就是 Analysis Routine 太快了, 而且一定是坏了. 它们的怀疑是不管系统扫描的物体资料多复杂都好, Result 都在相等的时间 出来,一定是某个地方出了问题. 编译员就解释说,软件是采用 Real Time Detection 的方法所以那个后来的 Progress Windows 讯息很快就会关闭了, 但顾客还是不了解和坚持 Analysis 是不可能这样快的.

为了确保没问题,编译员就再检查软件一下, 结果软件是分析的非常正确. 为了那位顾客的坚持, 软件编译员没办法, 就只好在 Progress 讯息加了个 Delay Routine, 在扫描资料比较复杂的时候讯息弹出的时间也比较长. 这下顾客就很满意.

半年过后, 顾客又投诉 Analysis Routine 太慢了, 问编译员的公司能否加快软件. 软件编译员就缩短一半那个 Progress 讯息 Delay Routine 的时间. 顾客对此非常高兴.

当然不是那位编译员的决定, 公司对此 "optimization and refinement of algorithms" 开了个 $5000 的价码.

摘自: Meeting "customer demand" - Daily WTF
回复

使用道具 举报

 楼主| 发表于 15-8-2006 03:15 PM | 显示全部楼层

No Line Break?Aaaaaaaaaaaaaa

现在这个是 HTML WTF.

这是一位仁兄在复制学校网络时间表时无意间发现的.

那个网页编写员用了个很特别的方法来避开使用 Line Break Tag.

还没 Select Copy 前:


Select 过后:


原装 HTML 编码:

  1. <p align="center">
  2.   <font size="+1"><strong>Extended Hours January 17 - 27, 2006</strong></font>
  3. </p>
  4. <p align="left">
  5.   Wednesday, January 18 - 8:30am - 8:00pm
  6.   <font color="#FFFFFF"> aaaaaaaaaaaaaaaaaa </font>
  7.   Thursday, January 19 - 8:30am - 8:00pm
  8.   <font color="#FFFFFF">aaaaaaaaaaaaaaaaaaaaa </font>
  9.   Friday, January 20 - 8:30am - 6:00pm
  10.   <font color="#FFFFFF"> aaaaaaaaaaaaaaaaaaaaaaa</font>
  11.   Monday, January 23 - 8:30am - 8:00pm
  12.   <font color="#FFFFFF">aaaaaaaaaaaaaaaaaaaaa</font>
  13.   Tuesday, January 24 - 8:30am - 8:00pm
  14.   <font color="#FFFFFF">a</font>
  15.   <font color="#FFFFFF">aaaaaaaaaaaaaaaaaaaa</font>
  16.   Wednesday, January 25 - 8:30am - 8:00pm
  17.   <font color="#FFFFFF">aaaaaaaaaaaaaaaaaa</font>
  18.   Thursday, January 26 - 8:30am - 8:00pm
  19.   <font color="#FFFFFF">a</font>
  20.   <font color="#FFFFFF">aaaaaaaaaaaaaaaaaaaa</font>
  21.   Friday, January 27 8:30am - 6:00pm
  22. </p>
复制代码


摘自: The Daily WTF - No Line Break?
回复

使用道具 举报

 楼主| 发表于 17-8-2006 11:31 AM | 显示全部楼层

天才


几年前,某某公司有一位软件编译员,她很喜欢到处告诉别人,她是个天才,很有天分的天才。一两年后,她离开了公司,某天同事在公司其中一个软件在编译 Nightly Build 当中一些 Test Code 出了问题.经过检查,问题出在哪位天才写的一个 Random Number Generator.不过幸好,哪个不属于 Production Code.

我想大家在编译时都使用过 Random Number Function, 甚至在年轻时写过自己的第一个 Random Number Function,不过至多一行两行。不过我们这位天才不但有本事拉到很多行,使用的方法还是前无古人,后无来者。她的方式不但非常的不通顺,不少机会可能会崩溃,拥有至少8个编码错误,而且随时会跌入 Infinite Loop 的陷阱 (就是这个问题才发现).

这就好像那种寻找错误图像游戏,你能找到多少个?


  1. double MUTils::GenerateRandomValue(double theMin, double theMax)
  2. {
  3.   if (theMin >= theMax) {
  4.     // error in parameters, so return 0.0
  5.     return 0.0;
  6.   }

  7.   // seed the random generator if it hasn't already been seeded
  8.   if (0 == itsSeed) {
  9.     this->itsSeed = time(NULL);
  10.     srand((int) this->itsSeed);
  11.   }

  12.   // get a random double
  13.   int anIntegerPortion = rand();
  14.   int aFractionPortion = rand();
  15.   double aValue = (double)anIntegerPortion + 1.0/(double)aFractionPortion;

  16.   // figure out the range the double should fall in
  17.   // i.e. if the min was 0, how big would the max be?
  18.   double aRange = theMax - theMin;

  19.   // make the double be between 0 and aRange
  20.   for (; aRange <= aValue; aValue -= aRange);

  21.   // adjust the value so it's between min and max
  22.   aValue += theMin;

  23.   // all Done
  24.   return aValue;
  25. } // double MUTils::GenerateRandomValue(double theMin, double theMax)
复制代码


摘自: The Daily WTF - Genius
回复

使用道具 举报

 楼主| 发表于 3-9-2006 04:06 PM | 显示全部楼层

To the Hexth Degree


David H's 的前同事现在可以说是稳坐十六进制转换编码的宝座, 他用了不少过 5000 行的编码来转换十六进制,当然在 Java 平常都只是需要一行就可以了。

以下是其中部分编码:


  1. public abstract class HexadecimalConstants
  2. {
  3.   /**
  4.    * The number of hexadecimal characters per byte.
  5.    */
  6.   public static final int NUMBER_OF_HEXADECIMAL_CHARACTERS_PER_BYTE = 2;

  7.   /**
  8.    * The offset of the first bit within the four bits required to represent an
  9.    * hexadecimal character.
  10.    */
  11.   public static final int FIRST_BIT_OFFSET = 1;

  12.   /**
  13.    * The offset of the second bit within the four bits required to represent
  14.    * an hexadecimal character.
  15.    */
  16.   public static final int SECOND_BIT_OFFSET = 2;

  17.   /**
  18.    * The offset of the third bit within the four bits required to represent an
  19.    * hexadecimal character.
  20.    */
  21.   public static final int THIRD_BIT_OFFSET = 3;

  22.   /**
  23.    * The offset of the fourth bit within the four bits required to represent
  24.    * an hexadecimal character.
  25.    */
  26.   public static final int FOURTH_BIT_OFFSET = 4;

  27.   /**
  28.    * The '0' hexidecimal character.
  29.    */
  30.   public static final char ZERO = '0';

  31.   /**
  32.    * The bits that represent the '0' hexidecimal character.
  33.    */
  34.   public static final boolean[] ZERO_BITS = new boolean[]{false, false, false, false};

  35.   /**
  36.    * The '1' hexidecimal character.
  37.    */
  38.   public static final char ONE = '1';

  39.   /**
  40.    * The bits that represent the '1' hexidecimal character.
  41.    */
  42.   public static final boolean[] ONE_BITS = new boolean[]{false, false, false, true};

  43.   /**
  44.    * The '2' hexidecimal character.
  45.    */
  46.   public static final char TWO = '2';

  47.   /**
  48.    * The bits that represent the '2' hexidecimal character.
  49.    */
  50.   public static final boolean[] TWO_BITS = new boolean[]{false, false, true, false};

  51. /* ... snip 150 or so lines  ... */

  52.   /**
  53.    * The 'F' hexidecimal character.
  54.    */
  55.   public static final char F = 'F';

  56.   /**
  57.    * The 'f' lower case alternative to the 'F' hexidecimal character.
  58.    */
  59.   public static final char F_LOWER = 'f';

  60.   /**
  61.    * The bits that represent the 'F' hexidecimal character.
  62.    */
  63.   public static final boolean[] F_BITS = new boolean[]{true, true, true, true};

  64. }
复制代码


其中一段在 Main Convertion Class 的编码


  1. private static char convertBitsToHexadecimalCharacter(boolean bit1,
  2.                                                       boolean bit2,
  3.                                                       boolean bit3,
  4.                                                       boolean bit4) {

  5.     // if the first bit is true - the binary nibble is 1???
  6.     if (bit1) {

  7.         // if the second bit is true - the binary nibble is 11??
  8.         if (bit2) {

  9.             // if the third bit is true  - the binary nibble is 111?
  10.             if (bit3) {

  11.                 // if the fourth bit is true - the binary nibble is 1111
  12.                 if (bit4) {

  13.                     // return the 'F' hexidecimal character
  14.                     return HexadecimalConstants.F;

  15.                     // else the fourth bit is false - the binary nibble is 1110
  16.                 } else {

  17.                     // return the 'E' hexidecimal character
  18.                     return HexadecimalConstants.E;

  19.                 }

  20.                 // else the third bit is false - the binary nibble is 110?
  21.             } else {

  22.                 // if the fourth bit is true - the binary nibble is 1101
  23.                 if (bit4) {

  24.                     // return the 'D' hexidecimal character
  25.                     return HexadecimalConstants.D;

  26.                     // else the fourth bit is false - the binary nibble is 1100
  27.                 } else {

  28.                     // return the 'C' hexidecimal character
  29.                     return HexadecimalConstants.C;

  30.                 }

  31.             }

  32. /* ... Snipped 100+ lines ... */

  33.                 // else the third bit is false - the binary nibble is 000?
  34.             } else {

  35.                 // if the fourth bit is true - the binary nibble is 0001
  36.                 if (bit4) {

  37.                     // return the '1' hexidecimal character
  38.                     return HexadecimalConstants.ONE;

  39.                     // else the fourth bit is false - the binary nibble is 0000
  40.                 } else {

  41.                     // return the '0' hexidecimal character
  42.                     return HexadecimalConstants.ZERO;

  43.                 }

  44.             }

  45.         }

  46.     }

  47. }
复制代码


回复

使用道具 举报

Follow Us
发表于 3-9-2006 05:45 PM | 显示全部楼层
hahahah, good
回复

使用道具 举报

 楼主| 发表于 30-12-2007 03:59 PM | 显示全部楼层

Paula Bean

年关将到,为大家分享一下经典

**************************************


Heidi SMichael Hanson's 的老板正在设立一个企业航运/库存系统。因为内部资源缺乏,所以就把外边的 Contractor 引进帮忙。
其中一位名叫 Paula。据说是个非常有经验的 Java Programmer 而且对航运界也有很大的了解。
刚开始个几个月,事情进行得很顺利。Paula 在每个星期的进展会议,都报告一切良好顺利。

直到接近尾声的时候,Paula 报告需要一点点帮忙。当 Heidi 和 Michael 来的时候,他们发觉这可不简单。。。。。。
因为以下就是 Paula 为系统所写的全部编码。

  1. package test;

  2. public class paulaBean {

  3.   private String paula = "Brillant";

  4.   public String getPaula() {
  5.     return paula;
  6.   }
  7. }
复制代码


来自:
Classic WTF
回复

使用道具 举报


ADVERTISEMENT

发表于 30-12-2007 04:45 PM | 显示全部楼层
果然。 “brilliant”
回复

使用道具 举报

发表于 31-12-2007 01:08 PM | 显示全部楼层
原帖由 lipsin 于 30-12-2007 03:59 PM 发表
年关将到,为大家分享一下经典

**************************************


Heidi S 和 Michael Hanson's 的老板正在设立一个企业航运/库存系统。因为内部资源缺乏,所以就把外边的 Contractor 引进帮忙。
其中 ...
看到这篇,我要晕了。“经验丰富” 居然出来这个
回复

使用道具 举报

发表于 3-1-2008 11:48 PM | 显示全部楼层
曾经从同事那里接过一个vb的源码.... 一眼望去就想说wat the f***....
70%以上的variable都是用a,b,c,d... dd, oo, etc... 而且大部分还是Global Variable..... comment只有那一两行...
回复

使用道具 举报

发表于 5-1-2008 10:11 AM | 显示全部楼层
原帖由 苦瓜汤 于 3-1-2008 11:48 PM 发表
曾经从同事那里接过一个vb的源码.... 一眼望去就想说wat the f***....
70%以上的variable都是用a,b,c,d... dd, oo, etc... 而且大部分还是Global Variable..... comment只有那一两行...


有时我的variable也是这样的哦

a = 1
b = 什么什么的号码
。。。。。。。。。


回复

使用道具 举报

发表于 5-1-2008 04:06 PM | 显示全部楼层
原帖由 苦瓜汤 于 3-1-2008 11:48 PM 发表
曾经从同事那里接过一个vb的源码.... 一眼望去就想说wat the f***....
70%以上的variable都是用a,b,c,d... dd, oo, etc... 而且大部分还是Global Variable..... comment只有那一两行...

我senior還遇過var _1,_2,_3,_4,.....
至今依然讓他耿耿于懷...
回复

使用道具 举报

发表于 5-1-2008 06:49 PM | 显示全部楼层
那时候我find & replace了好几天...
回复

使用道具 举报

发表于 5-1-2008 06:58 PM | 显示全部楼层
原帖由 苦瓜汤 于 5-1-2008 06:49 PM 发表
那时候我find & replace了好几天...

善用 dreamweaver 的find + replace 一次搞定。
回复

使用道具 举报

发表于 5-1-2008 07:14 PM | 显示全部楼层
原帖由 vampcheah 于 5-1-2008 06:58 PM 发表

善用 dreamweaver 的find + replace 一次搞定。


要是那么简单的话也不会说wtf了... 哈哈。
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 7-1-2008 07:09 PM | 显示全部楼层

Could You Explain Programming Please

不多说自己看
    Him: Hey, you're good with computers right?

    Me: Yes.

    Him: And you know how to program computers?

    Me: Yes, that's my job actually.

    Him: Could you explain programming please?

    Me: I'm sorry, what do you mean?

    Him: I want to make a game like Halo, but I don't know how to start. Could you explain what I need to do?

    Me: You should probably go to the library and get a book.

    Him: Can you just tell me what I need to do?

    Me: Wait a minute. Are you asking me to explain how to program computers?

    Him: Yeah.

    Me: Over the phone?

    Him: Yeah.
回复

使用道具 举报

发表于 12-1-2008 09:50 PM | 显示全部楼层
这主题有趣,希望lipsin兄多分享,我bookmark起来了
回复

使用道具 举报

发表于 12-1-2008 10:50 PM | 显示全部楼层
原帖由 新力爱力新 于 12-1-2008 09:50 PM 发表
这主题有趣,希望lipsin兄多分享,我bookmark起来了


自己去 worse than failure。com 那边读啦。。
回复

使用道具 举报

发表于 28-1-2008 12:17 AM | 显示全部楼层
不懂是英文差还是编程差的关系
每次去那网站看都是有懂没懂酱的...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 14-5-2024 01:29 AM , Processed in 0.072022 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表