What compsci textbooks don't tell you: real world code sucks

Source: Internet
Author: User
ArticleDirectory
    • Crappy software: Is it bad programming, or is it 'too good '?
    • Time-savers and face-savers

What compsci textbooks don't tell you: real world code sucks

 

By Dave Mandl

Posted in developer, 21st December 2012 GMT

 

There's a kind of cognitive dissonance in most people who 've moved from the academic study of computer science to a job as a real-world software developer. the conflict lies in the fact that, whereas nearly every sample program in every textbook is a perfect and well-thought-out specimen, usually ally no software out in the wild is, and this is rarely acknowledged.

 

To be precise: a tremendous amount of source code written for real applications is not merely less perfect than the simple examples seen in school-it's outright terrible by any number of measures.

 

 

 

Due to bad design, sloppy or opaque coding practices, non-scalability, and layers of uugly "temporary" patches, it's often difficult to maintain, harder still to modify or upgrade, painful or impossible for a new person joining the dev team to understand, or (a different kind of problem) slow and inefficient. in short, a mess.

 

Of course there are beyond tions, but they're just that: Beyond tions. in my experience, software is, almost as a rule, bad in one way or another. and lest I be accused of over-generalising: in more than 20 years I 've done work for maybe a dozen companies, almost all of them in the banking industry and keys of them household names.

 

The technology people employed at these companies are considered to be the very best, if only because the pay tends to be so good. i'll play it safe and stick to my actual experience in the financial sector even though I'm convinced this state of affairs is not limited to that one industry.

 

Getting back to the cognitive-dissonance problem: in casual discussion, developers and Tech managers will talk about all the wonderful things their system does, the stellar technical skills of their team, and how much their users love them-and all that may be true.

 

But talk privately, colleague-to-colleague, to one of these developers about the quality of the code base, all the daily headaches, the quick hacks and patches, the laughable mistakes made by the original author of the system (who left the firm a couple of years ago ), or the fear that the person who "knows the system" will leave for another job, and you'll hear a different story: "Of course there are problems. everyone knows that. things are always this way-it's barely even necessary to mention it."

 

Very few coworkers with whom I 've broached this subject have seen things differently, and I 've often heard stories of costly screw-ups that wocould shock the most jaded techie. but on a daily basis, in all but the worst cases, it's easier for developers to talk about things like what their system does, or how elegant its user interface is, than to dwell on any horrors lurking inside.

 

It also may be that, after years of working on a system with serous maintainability flaws, people simply become accustomed to the strange procedures they have to go through regularly to keep things running.

 

Complex Systems + borked code = beelllions down the drain

In the financial business there have been several software-related blowups in the last few years that were big enough to make it onto the evening news. to name just three, there were: the NASDAQ failure that wreaked havoc with Facebook's IPO; A trading fiasco at Knight capital in August that led to widespread market disruption and a $400 m drop in Knight's market value; and the "Flash Crash" of May, 2010, which caused market losses of at least $1 trillion in a matter of minutes.

 

System glitches and bugs this visible and this costly are relatively rare, but for every one of them there are a hundred smaller ones that only a handful of people ever hear about. A Reuters article this summer with the title "Morgan Stanley Smith Barney rainmakers consider exit" said this: "several dozen Morgan Stanley Smith Barney advisers who manage tens of billions of dollars of client money are considering leaving the firm, saying that widespread technology problems have made it very difficult for them to do their jobs. "(italics mine .)

 

These are all outright failures in highly complex systems, but poorly written code can crop up in applications of any size, and it may not lead to a direct, quantifiable loss. it will, however, require untold extra hours of work for routine support, make even minor upgrades painful, or force systems to be retired prematurely (in some cases, before they 've even gone live ). how does this happen?

 

Crappy software: Is it bad programming, or is it 'too good '?

the most common reason for the existence of bad software is bad programmers. good software, misleadingly, is usually easy to read, but it's not easy to write. there are an awful lot of developers out there who never learned the correct way to do things. maybe they're so enamored of a participant technology or coding technique that they insist on using it whether it's appropriate or not ("If the o Nly tool you have is a hammer ..."). Maybe they're in over their head on a project with a huge number of moving parts. maybe they 've been forced to pick up an unfamiliar language at a moment's notice. or maybe their thought processes just don't translate into logical, supportable code. the best seller ists will usually seek out of the least boring work, or the highest compensation, but even the most exciting project may be staffed with bad programmers merely because budget constraints, or stinginess, prevented the firm from shelling out for more talented ones.

at the other end of the spectrum, under projects are sabotaged by developers who are "too good"-that is, people who insist on coding everything in the most complicated and impenetrable way possible. this may be because they feel the constant need to show how much they know, or because doing things the simple way is just not interesting enough. as one friend of mine, a heavyweight who has had to rewrite your terrible applications, once said to me: "They think that if they're not writing 80 lines of code to add two numbers, they're not using their education. "

In my experience, these people can cause more harm than anyone else. I 've seen developers use the most tangled object-oriented techniques to do things that cocould have been accomplished much more easily with a trivial 10-line function. in C ++, an everything-but-the-kitchen-sink language used heavily on Wall St, templates (to give just one example) enable this kind of behavior by allowing you to create the most esoteric generic classes imaginable.

In one case where I had to take over development from a C ++ guru who felt the need to do everything in the most opaque, "sophisticated" way possible, his components simply had to be scrapped and rewritten from scratch. I couldn't begin to understand the code, and neither coshould a colleague who was one of the best C ++ developers I 'd ever worked. four solid months of work in the trash bin.

If the original developer had stayed with the firm and finished the project, that wocould only have deferred the day of reckoning, since no one cocould ever have taken over support of this monster. (the joke name on Wall st for this kind of situation is "Job Security": the sole expert on this system cocould never be sacked .) but even if the code had been marginally comprehensible, support wocould still have been a nightmare for anyone but the original developer, and it's likely that a new person wowould have broken things by trying to make changes to delicate classes that he didn't fully grasp.

Time-savers and face-savers

another source of bad code is laziness. for programmers, there's "good" laziness, which drives them to build tools that will relieve themselves and others of unnecessary drudge work-that's what we're here, after all. and then there's "bad" laziness, the kind that leads programmers to cut corners or do things in the quickest possible way, rather than taking the three extra hours to do them right. this always comes back to haunt someone-possibly the person who takes over six months later and doesn't know that this tiny block of exceptional code exists, or why. patches, almost by definition, are changes made without thought to the long-term consequences, and often sloppily, because they're usually considered "temporary. "

for the record, however, I don't think I 've ve ever seen anyone go back and clean up a quick-and-dirty fix made two years previusly just because it was the right thing to do. if the system is working, almost no manager will pay just to have you recode a piece of it "the right way," without adding any new functionality. there's always something more important that needs to be done-until that quick-and-dirty fix blows up and (because it's urgent) gets replaced by another quick-and-dirty fix. to some lazy programmers, it must be said, none of this matters: they take the easy way out precisely because they know they won't be around und when their time bomb explodes.

There are different ages that by their very nature make it easier to write bad code. as much as I love APL, a powerful language I once worked in that makes heavy use of Greek letters and other cryptic symbols, it's easily abused, and I 've seen some horriic APL systems written by people who HADN' t been trained properly.

(Unfortunately I had to support one such system early in my career. I prayed every day for a quick, painless death .)

Conway's famousGame of LifeIn dyalog.com's one line of APL code

If, as an exercise, you wanted to write a program that no one in the world cocould make heads or tails of, the K language wocould make that a breeze: I once worked in a group that had a large codebase in K (which as it turns out is a distant, ugly relative of APL ), and it never took me less than a half hour to decipher any one line of it.

As mentioned above, C ++, despite its superficial similarities to Java, is infinitely easier than Java to write impenetrable code in. and one language I 've been warned about, though I 've never had the opportunity to use it, is Haskell, an offshoot of ML. according to a friend in academia who's studied it, It's "The Taliban version of ML," in which it's all but impossible to write readable code.

This Haskell line prints all the powers of 2 As explained on stackoverflow

Ultimately, the greatest enemy of good programming practices is time. one of the reasons the code in your textbook is perfect and the Code where you work isn't is that the author of the book was allowed, or forced, to do things right.

in the real world, tight budgets, inclusighted managers, and unreasonable expectations from non-Techies almost always conspire to make developers do things too quickly. the final product may be good enough now, and be perfectly understandable to the people who 've just written it, but all that will change in a year, when there are new requirements and a new set of developers grappling with the hastily-thrown-together code. additionally, the codebase in even a small production system can be orders of magn1_bigger than in most textbook examples, and large systems are far from easy to build. despite protestations to the contrary, projects greater than certain size and complexity (see the Reuters article cited above) are Almost guaranteed to fail in some way without sufficient time for planning, design, testing, and adult supervision.

All the above aside, there's one simple and completely painless way to prevent future generations from cursing you when they look at your code: Include some comments!

 

 

In realityCodeAlways make life evil--The textbook didn't tell you.

From professional learning to practical work, developers will always be affected by a strong ideological difference. The reason for this ideological conflict lies in the fact thatProgramIt is always regarded as perfect, but software in reality is hard to be regarded as perfect.

Specifically, programs in the real world are not only imperfect, but even terrible.

Poor design, hasty practices, unscalable, and complicated temporary patching make the program difficult to maintain, upgrade, and even make it difficult for new members to integrate.

Of course there will be exceptions, but they can only be exceptions. In my experience, most of the software designs fail, but the failure methods are different. Over the past 20 years, I have worked in many companies and almost all of them are well-known banks. Technical staff of these banks are considered to be top players in the industry because they enjoy high salaries. What they need to do is to ensure the security of these systems in financial services, and this approach is not limited to this field.

Let's go back to the cognitive disorder. Generally, developers and technical managers always talk about the advantages of their systems, the main technologies used by the development team and how their products are well received by users are not necessarily true.

In all fairness, the headaches in the system, chaotic patches, ridiculous errors, and the trauma caused by the departure of team members, you will hear a completely different story-"In fact, there are many problems, and even everyone knows that the problem exists. But things are not transferred by our will-so we have no need to talk about them at all ".

Few people disagree with my question, and I often hear about the chaos that can scare technicians. Compared with potential problems in the system, people prefer to talk about problems such as system functions and beautiful interfaces.

Once you get used to working on a problematic system, people will get used to the strange processes that must be made to make the system work normally.

In recent years, there have been some major software-related news in the financial field: The NASDAQ Error Caused Facebook's fault, and the company's market value evaporated due to a failed exchange of Knight capital, and the $11 loss caused by the Lightning crash within minutes.

System faults are rare, and these minor problems are rarely noticed. A Reuters article pointed out that a large number of consultants in a company are considering leaving, because many technical problems make their work difficult.

Complex systems always have errors, and bad code can cause a sudden program crash, resulting in incalculable consequences.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.