×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

My first example is long procedure / function. What is the longest function that you saw? I worked with a system that has functions that contains more than 1000 lines. To make it worse, this system has 7 different modules.

本文发表在 rolia.net 枫下论坛Their clients can buy 1, 2 or all 7 of them. Each module has its own function that share more than 70% code.

Every time I looked on theese functions, I was totally lost; 1000 lines! By the time, I finished line 600, I probably forgot what line 200 is about.

When programmers modify something in module A; they have to go over all other modules to decide if they should do it on module B, C, D, E, F, and G?

At 1 point, I was so mad that I decided to do something about it. I discussed witht the architect and get his blessing to consolidated and optimized all the spaghetti code into just 1 single function. It took me 2 months and I discovered over 50 bugs. I managed to merged them into a function that has less than 40 lines. It is simple and readable.

Every programmer liked it; except.... the BOSS. During our monthly meeting, a programmer said I did great work on this function and asked when I was going to fix all other functions.

My boss called me into his office and complained that I wasted all my time that contributed no added value to the system. I told him that I had discussed with other senior developers and get the green light from our architect. I even showed him how many bug was discovered in this function for the last 2 years and during the 2 months that I optimized it. He still insisted it was a total waste of my time.

I eventually left the company. Before I left the company, I did a very simple predictive model. I did a regression on the time that was spend on fixing the bug vs. number of line in our system and also correlated to how many line we added to the system every month. And my prediction was that within 2 years, they would spend 50%+ of their time fixing bug.

I was wrong! Someone called me just about a years later that their boss was very upset and mad in a monthly meeting because they spend over 50% of their time fixing the bugs!

BTW, anyone see a jumbo class that has over 1000 variables!更多精彩文章及讨论,请光临枫下论坛 rolia.net
Sign in and Reply Report

Replies, comments and Discussions:

  • 工作学习 / 学科技术讨论 / 共享经验 - Poor Coding. I have been programming for over 20 years and I saw so many bad coding examples and I hope you can share your experience with us. WHAT YOU SHOULD NEVER DO!
    • My first example is long procedure / function. What is the longest function that you saw? I worked with a system that has functions that contains more than 1000 lines. To make it worse, this system has 7 different modules.
      本文发表在 rolia.net 枫下论坛Their clients can buy 1, 2 or all 7 of them. Each module has its own function that share more than 70% code.

      Every time I looked on theese functions, I was totally lost; 1000 lines! By the time, I finished line 600, I probably forgot what line 200 is about.

      When programmers modify something in module A; they have to go over all other modules to decide if they should do it on module B, C, D, E, F, and G?

      At 1 point, I was so mad that I decided to do something about it. I discussed witht the architect and get his blessing to consolidated and optimized all the spaghetti code into just 1 single function. It took me 2 months and I discovered over 50 bugs. I managed to merged them into a function that has less than 40 lines. It is simple and readable.

      Every programmer liked it; except.... the BOSS. During our monthly meeting, a programmer said I did great work on this function and asked when I was going to fix all other functions.

      My boss called me into his office and complained that I wasted all my time that contributed no added value to the system. I told him that I had discussed with other senior developers and get the green light from our architect. I even showed him how many bug was discovered in this function for the last 2 years and during the 2 months that I optimized it. He still insisted it was a total waste of my time.

      I eventually left the company. Before I left the company, I did a very simple predictive model. I did a regression on the time that was spend on fixing the bug vs. number of line in our system and also correlated to how many line we added to the system every month. And my prediction was that within 2 years, they would spend 50%+ of their time fixing bug.

      I was wrong! Someone called me just about a years later that their boss was very upset and mad in a monthly meeting because they spend over 50% of their time fixing the bugs!

      BTW, anyone see a jumbo class that has over 1000 variables!更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • <<Refactoring: Improving the Design of Existing Code>> <<Code Complete>>
      • This is one of the consulting services that I provide to my clients. But you have to make them aware the benefit of optimized code / problem of spaghetti code. My marketing approach is more on education, to educate my prospective clients.
    • Your code should be readable.
      Have you seen any code like this before"

      if (x1+y1 + z1 > aa) then.....

      or

      If (leave1 + leave2 + leave3 > leave4)

      And then you have to find out where x1 is assigned and it may be x1 = a + b + c

      After 30 minutes of diggin various pieces of code, then you finally found out it may just mean that the employee took too much leave this year, and the system should alert his manager.

      I have tried to ask in various organization to bring in business anlayst to review our code. If BA cannot understand what our code means, then it is just not readable enough. Again, I failed! Code review should be programmers' responsibility.

      The good thing is that no one else dares to touch your code and enhance your job security.
    • I worked on a legacy system. There are about 80 tables in a database and all tables has column names C1, C2, C3, ..., C100. No PK, FK, index, etc. No stored procedures. No data dictionary.
      To get exact meaning of a column, especially in some cases, they needed to dig into source codes that were probably named module1_func1, module1_func2, .., modulen_funcm.

      The leader developer was promoted several time to a high position and he considered the system as his own baby. It's not allowed to criticize the system.
      • Did we work for the same company before? And to make it even challenging, each column is actually a zip content of a big block of data; they argue it would improve the performance.
        • It seems not. But that company has another way to manage data and they totally didn't benefit from database systems either. I do not want to expose details. So it seems many company do these bad things and make money.
      • Ugly database 可以增加这些人的Job security, 那个Lead Developer政治正确,永远不必担心被Layoff。
        • +1
      • "The leader developer was promoted several time " - ass hole everywhere.
    • 编程20年了, 应该想办法多挣点钱.
      • Thanks, I am trying!
    • Do NOT access database table or class directly, use view or interface.
      • Do not use view in database, that's the worse thing I can think of.
      • If you have this rule I can say you don't do a good job in coding. Don't make up stupid rules if the system DOES allow you to do so and it easy to read. Does the VIEW make maintainance easier or performance better?
    • 硬件也一样。。俺老板最有名的一句话。I don't care what's going on. Just fix it
      • They called it bandit apporach. My question is always if you want to fix the source or just the symptoms . Fixing the symptoms can be quick and easy but without fixing the source, there would be more symptoms coming back very soon.
        It adds up quick.
    • It's all about the job security. Nobody give a damn about the quality of code, nobody.
      The better the system maintainable the quicker you got your ass kicked out.

      People sick from time to time so doctor and nurse got work to do, people create garbage everyday so garbage worker can strike to increase the rate, salt and weather in Toronto guarantee work for road maintenance, the only hope of developer is the bug you hosted yourself.

      Well, it's another story if you maintain your own code with job security.

      This is another version of '劣币驱逐良币'
      • So, the best way is to do Quick Fix first; and make it more 'spaghetti' and harder to read. Fxxx them all!
        • totally wrong, it is acceptable to start with a workable approach, and the next thing is to make it clean. Depending on personality, some people may do the second part, some may not
    • Code without unit test
      • 真心话 or 鹦鹉学舌?
        • after year 2002, i have never wrote code without unit test.
    • 最近那本 Clean Code 我觉得是类似的书里面写的最好的
    • never say nerver:). i.e sometimes I keep the redundant code just because I want to leave space for the uncertainty.