×

Loading...
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!

This can be necessary

"return bSuccess" returns integer value of bSuccess. For a 64bits computer, there are ~2^64 possible or returns. Later use of == may cause unexpected results.
"return bSuccess?True:False" returns finite value of either True or False. Later use of == is safe anywhere. if-then-else will generate the same code after compiler done its work.
A complex line of good-looking C code normally generate the same code after compile as several line of simple verbose ugly codes. Single liner is good for text books, tests and interviews. Verbose code may do good to projects - when you have to put enough lines of comments for each line you wrote 5 years ago for knowledge transfer, verbose codes is definitely preferred.
Report

Replies, comments and Discussions:

  • 工作学习 / 学科技术讨论 / 又没有人见过比这个吐血的程序:一段把字符串转换成大写的程序,竟然有人用穷举法if string='a' then string='A'来实现?
    最近在debug公司一套运行了10几年舍不得升级的老系统,发现一个程序老是运行不出来。花了九牛二虎之力才发现一个2000年做的程序,很简单的upcase()函数,一个2000年的programmer竟然写了几十条if then把所有可能的输入一个个转换。因为最近有了新的数据,if then就做不出来了。大概这就是传说中IT bubble的时候在书店给人抓进来的programmer
    • 找这个这也要花九牛二虎之力? 还以为你要反汇编呢
    • 这算啥?我有一A同事,用了个最蠢的方法,心里忍不住嘲笑,会后和另一组的B同胞同事分享,我还没说完,B同事冒出和A同事完全一样的方法,我只好把后半节话咽回去。
      • 古话说得好,如果都是蠢的,就一个人是聪明的话。这个人改思考了。与君共勉。
        • 好处是这些人创造许许多多的工作量,不担心没活干, 所以只在心理嘲笑嘲笑。
    • 也不能轻视这种if then, 代码容易理解,容易维护,也有积极一面
      • 说得有道理,工作中的情况要考虑多方面,赞成!
      • 每次遇到新的数据,都要改这个程序,这就叫“容易维护”?现在的抬杠的人可真是不一般的多
        • 你也不能保证你的代码以后不升级,如果算法太复杂,维护的成本更高
      • it is also "cross the platform". Maybe.
    • very robust and sturdy code. never obsolete.... good job.
    • uppercase can not handle EBCDIC code on Ascii machine, or ASCII or mainframe, neither could it handle the non-standard codepage.....
    • 我的一个同事写过 If ( !bSucceed ) return false else return true 这样的代码,我当时review的时候被转得晕死。
      • LOL.
      • 这个太难读, 俺是这样写的: If ( bSucceed == false ) return false else return true
        • better to be: If ( true == bSucceed ) return true else return false
          • Are you guys kidding me??? The simplest way is: return bSucceed
            • 这个同志很没有幽默感。
            • Are you guys kidding me??? YYYES
      • 还好没写成这样:return bSucceed?true:false;
      • This can be necessary
        "return bSuccess" returns integer value of bSuccess. For a 64bits computer, there are ~2^64 possible or returns. Later use of == may cause unexpected results.
        "return bSuccess?True:False" returns finite value of either True or False. Later use of == is safe anywhere. if-then-else will generate the same code after compiler done its work.
        A complex line of good-looking C code normally generate the same code after compile as several line of simple verbose ugly codes. Single liner is good for text books, tests and interviews. Verbose code may do good to projects - when you have to put enough lines of comments for each line you wrote 5 years ago for knowledge transfer, verbose codes is definitely preferred.
    • Look at it positively. Because of this or those errors, many programmers have work chance. Otherwise … :)
    • 这肯定是按行数挣钱的。王小波诗云:一个和尚独自归,关门闭户掩柴扉。另外很奇怪:为什么新数据if then就做不出来?26个字母没列全?
      • 可能现在要支持多国语言了,楼主不是按行拿钱,不想写汇编了
        • 2000年的程序我怀疑哪个upcase能支持多国语言?所以新数据该不工作还是不工作啊。
      • 不是每个字母,而是每个可能出现的数据,打个比方,每个员工的人名,换成大写,这样每进来一个新员工,就要多加一行if then....然后还有人说这样容易维护,还跨平台。看样子野鸡IT学校真的养活了不少人。
    • 其实,有什么好嘲笑的呢?又不是错了.就算你对了,也就是雕虫小技而已.
    • 再说多点吧.在我们公司,越抓这种小毛病的人.水平越低.而且,还有些是刚毕业的学生.
      • 能招进来那样的人,你们公司也就是那种找人免费做几个月然后给reference货色而已
        • haha. 我公司的实习生的工资和学历都有可能比你高.省省吧.
    • 呵呵,俺现在在C# code里面还经常用goto ... 有时候苯办法能解决大问题
    • 没见过。友情提醒转行做更有前途的工作。
    • oh my god . 浪费多少内存啊.
      • Since it only deal with 26 characters, It indeed uses more cpu cycle to save memory compare to using ctype functions.