In general comments should raise the level of abstraction from the code The

In general comments should raise the level of

This preview shows page 359 - 361 out of 517 pages.

In general, comments should raise the level of abstraction from the code. The programmer’s goal is to write classes and other code that hides complexity; that is, to make the code easier to use than to make it easier to write. Abstraction may not be obvious from implementation; comments should capture the abstraction. For example, what do I need to know to invoke a method? I shouldn’t have to read the code of a method before calling it. One reason we are excited about the material in this book is that virtually every other software engineering sermons in this book are paired with a tool that makes it easy for you to stay on the true path and for others to check to see if you have strayed. Alas, such is not the case for this sermon on comments. The only enforcement mechanism beyond self-discipline is inspection, which Section 10.7 describes. Summary of comments: Comments are best written at the same time as the code, not as an afterthought. Comments should not repeat what is obvious from the code. For example, explain why the code is written this way. Comments should raise the level of abstraction from the code. Self-Check 9.4.1. True or False: One reason legacy code is long lasting is because it typically has good comments. False. We wish it were true. Comments are often missing or inconsistent with the code, which is one reason it is called legacy code rather than beautiful code. 9.5 Metrics, Code Smells, and SOFA 7. Declining Quality - The quality of [software] systems will appear to be declining unless they are rigorously maintained and adapted to operational environment changes. Lehman’s seventh law of software evolution A key theme of this book is that engineering software is about creating not just working code, but beautiful working code. This chapter should make clear why we believe this: beautiful code is easier and less expensive to maintain. Given that software can live much longer than hardware, even engineers
Image of page 359
whose aesthetic sensibilities aren’t moved by the idea of beautiful code can appreciate the practical economic advantage of reducing lifetime maintenance costs. How can you tell when code is less than beautiful, and how do you improve it? We’ve all seen examples of code that’s less than beautiful, even if we can’t always pin down the specific problems. We can identify problems in two ways: quantitatively using software metrics and qualitatively using code smells . Both are useful and tell us different things about the code, and we apply both to the ugly code in Figure 9.6 . Software metrics are quantitative measurements of code complexity, which is often an estimate of the difficulty of thoroughly testing a piece of code. Dozens of metrics exist, and opinion varies widely on their usefulness, effectiveness, and “normal range” of values. Most metrics are based on the control flow graph of the program, in which each graph node represents a basic block (a set of statements that are always executed together), and an edge from node A to node B means that there is some code path in which B’s basic block is executed immediately after A’s.
Image of page 360
Image of page 361

You've reached the end of your free preview.

Want to read all 517 pages?

  • Spring '19
  • Dr.Marcos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors