2 Pages

Importance of method specs

Course: CS 101, Spring 2008
School: Cornell
Rating:
 
 
 
 
 

Document Preview

of Specifications methods You know what the first function mini does, because its specification, in the comment preceding it, tells you. You don't need the function body --which we show you now. You have no idea what the second function does, because its specification has not been given. To understand what it does, you would have to look at its body: Integer.signnum. A specification of a method tells us what a...

Register Now

Unformatted Document Excerpt

Coursehero >> New York >> Cornell >> CS 101

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
of Specifications methods You know what the first function mini does, because its specification, in the comment preceding it, tells you. You don't need the function body --which we show you now. You have no idea what the second function does, because its specification has not been given. To understand what it does, you would have to look at its body: Integer.signnum. A specification of a method tells us what a call on a method does. The specification should be precise, complete, and as clear as possible. So that you don't have to look at the method body. In fact, every method should have a specification, and you should never have to look at the method body when writing a call on method. The method body indicates how a task is carried out. When writing a call on a method, we don't want to know that, we want to know what the task is. And the spec should tell us. Writing procedure specifications We write method specs as Javadoc comments immediately preceding the method. Javadoc comments begin with /** and end with */. The next lecture will explain why we use Javadoc comments. Let's begin discussing specs for procedures. There are two points to make here. /** Set the title to t */ public void setTitle(String title){...} 1. The spec mentions every parameter by name, and in a way that explains what that parameter is for. If a spec doesn't mention a parameter, the reader may not understand what the parameter is for, and the spec is incomplete. 2. This spec is a command to do something. We don't say, "this procedures sets the title to t", or something similar. We say, "Set the title to t." This is because we use it as follows. Suppose we have a call on procedure setTitle: setTitle("I want peace"); . The way to figure out what it means is to replace it by the specification, but substituting the argument for the parameter: Set the title to "I want peace". Since the procedure call is a command to do something, so should be the specification. Writing function specifications Since a function returns a value, the spec should be a description of that value. In fact, it should say what a call on the function equals. For example, that's what the spec of function areAscending does. It says that a call areAscending(a, b, c) is equal to the value of the true-false sentence "a, b, and c are in ascending order." /** = "a, b, and c are in ascending order".*/ public static boolean areAscending(int a, int b, int c){...} Since functions evaluate to a value, we often write their specifications starting with the equals sign. You may see a spec like "Return true if a, b, and c are in ascending order." has This a sort of operational feel, which we would rather not have. In mathematics, if someone asks, "what is sin(0)," one doesn't say, "return the value of the sin of 0,", one says simply," that's (equal to) the sin of 0. Same thing with any function call. Writing constructor specifications Here's how we write a specification for a constructor. The word "Constructor" announces that is is a constructor. And it explains what the properties of the new instance --what each field contains. Notice that the spec says what the previous chapter will be, even though there is no parameter for it. Note also that all parameters are explained: /** Constructor: a new instance with chapter number n, chapter title t, and previous chapter null. */ public Chapter(int n, String t) {...} Good specifications Specifications of methods Get in the habit of writing a method specification before you write the method body. For two reasons. First, you won't forget to write the spec, Second, that spec will help you the programmer, as you write the method body. You will be able to refer to the specification as you write the body. You don't have to remember everything about the spec. Make sure that your spec is accurate and complete. It must be consistent with the method body. A spec that is wrong in any way is probably worse than no spec at all, because a programmer who relies on the specification in writing a call on the method is bound to be introducing an error into their program. [Adam: do NOT say "his or her". Say "their". After reading this, delete this comment.] Finally, include explicitly any preconditions on a call --that is, constraints that the caller must satisfy. For example, the specification of a function that computes the square root of r should include the statement: Precondition: r >= 0. Such a precondition need not be checked the function; it is up to the caller to call the function only when the precondition is true. Changing a spec If you realize you need to change what a method does, first change the specification, and then change the method body. Be disciplined in doing this, and you will make fewer errors. Let's show how this works. Here's our first step: changing the specification. And here's our earlier function areAscending, which may not treat equal parameters the way we want. For example, if a = b < c, true, and not false, should be returned. So, we change the spec to: /** = "a, b, c are in non-descending order (a <= b <= c)" */ We have revised the spec. The next step is to revise the function body to be consistent with the spec, and here it is.
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UCF - HUM - 2210
Part 1: The Beginning of Civilization Chap. 1-31. Prehistoric To Civilized Societies (Ch. 1) a. Stone Age Society i. Hunting-gathering to farming settlements ii. Stone and wooden tools to copper b. Religion i. Animism (25): All nature is alive like
UCF - HUM - 2210
Part II: The Greek Legacy: Triumph Humanism and Reason1. Individualism and the Greek Community (Vol. 1, Chap 5 &amp; 6) a. Heroic Age (1200-750 B.C.): i. Homer (750 BC) creates &quot;Epic Heroes&quot; to build a new culture for his time after &quot;dark ages.&quot; ii. Ba
UCF - HUM - 2210
Huynh, Quoc July 2, 2008 HUM-2210 Dr. EvansPart 3: Pax Romana and Roman Legacy, Chap 81. Major Impact of Roman Society a. Government: i. Republic (Res publica) = rule by people (509-31 BC). Elected representatives ii. Forum = common plaza for mee
UCF - HUM - 2210
Part IV: The Shaping of the middle Ages1. The Beginning of Christianity: Ch. 9 a. Jewish Backgrounds i. Hebrew Bible (Torah = Law of Moses): becomes Christian &quot;Old Testament&quot; ii. Monotheism: one universal God for all iii. Supernatural Beings: demon
UCF - HUM - 2210
EvansHUM 2211REVIEW SHEETEXAM 1LISTS 1. Features that identify a society as &quot;civilized&quot; 2. Geographical areas of early civilizations 3. Ages of early Greek mythology to Ovid 4. Dominant and alternate cultural themes in the Iliad 5. Literary w
LSU - PSYCH - 3081
Chapter 20: Summary and Possible Future DirectionsIntroductionPersonality psychologists seek to understand the whole of personality However, understanding the whole may be impossible Instead, the difficult task of understanding the whole person is
LSU - PSYCH - 3081
Chapter 19: Disorders of PersonalityThe Concept of DisorderPsychological disorder o Pattern of behavior or experience that is distressing and painful to the person o Leads to disability or impairment in important life domains o Associated with the
LSU - PSYCH - 3081
Chapter 18: Stress, Coping, Adjustment, and Health Models of the Personality-Illness ConnectionInteractional model o Objective events happen to a person, but personality determines the impact of events by influencing a person's ability to copy o Per
LSU - PSYCH - 3081
Chapter 17: Culture and PersonalityIntroduction Several reasons personality psychologists believe it is useful to explore personality across cultures o Discover whether concepts of personality that are prevalent in one culture are also applicable in
LSU - PSYCH - 3081
Chapter 17 terms Cultural variations: within group similarities and between group differences can be of any sort-physical, psychological, behavioral, or attitudinal. These phenomena are often referred to as cultural variations. Two ingredients are ne
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #1. Marketing Concept BW Jan 14, 2008 pg. 24 - see attached article Jan 22, 2008In &quot;That Computer Is So You&quot;, a Business Week article by journalists Steve Hamm and Jay Greene, attention is g
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #4 Marketing Era BW Mar. 17, 2008 pg. 60 - see attached article March 20, 2008In &quot;Upwardly Mobile Stationery&quot;, a Business Week article by Aaron Pressman, Staples is upgrading their image fro
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #2. Marketing Segmentation BW Feb. 4, 2008 pg. 68 - see attached article February 5, 2008In &quot;Social Networks That Break a Sweat, by Paula Lehman in Business Week, Bode Miller is introduced a
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #5 Product Life Cycle BW March 17, 2008 - see attached article March 28, 2008Apple is undergoing some changes, as documented in Business Week's &quot;The iPhone in the Gray Flannel Suit&quot;, an arti
USF - MAR - 3023
To: From: Subject: Reference: Date:Prof. Noel, MAR 3023 #3. Positioning BW Feb. 25, 2008 pg. 55 - see attached article February 22, 2008In Business Week article, &quot;Japan: Google's Real-Life Lab&quot; by Kenji Hall, the web-based giant Google is bringin
USC - ISE - 382
Database Systems: Concepts, design, and implementationISE 382 (3 Units)Description Concepts in modeling data for industry applications. Designing and implementing robust databases. Querying databases to extract business intelligence; Global Enterpr
USC - ISE - 382
ISE 382Midterm Review Questions (with answers)1) What does DBMS stand for? DBMS stands for Database Management System 2 What is a data model? Why are such models important? A data model is a logical representation of the structure of the database.
USC - ISE - 382
Homework 1 ISE 382 Database Systems 15 pointsDue Date Friday February 8thAnswer the following questions from your textbook. (1 point each) Page 24 1.7, 1.14, 1.18, 1.19, 1.24, 1.29, 1.30, 1.31 Page 95 3.10, 3.12, 3.15, 3.16, 3.17, 3.18, 3.20 Turn
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 1 INTRODUCTION, JANUARY 14, 2008OUTLINEIntroduce TAIntroduce instructor Registration for www.gezabottlik.comQuestionnaire (on line) Resume (submit on line) Take roll Grades Go over syllabus
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 3 PERFORMANCE, JANUARY 23, 2008OUTLINE Roll Questions? Chapter 2 - PerformanceGeza P. BottlikPage 1FACILITIES PLANNING ISE310L SESSION 3 PERFORMANCE, JANUARY 23, 2008Performance - Introduction Compet
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 2 Chapter 1, January 16, 2008OUTLINE Take roll Quiz example Chapter 1 Understanding the Supply ChainGeza P. BottlikPage 1FACILITIES PLANNING ISE310L SESSION 2 Chapter 1, January 16, 2008Example of a
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 7 Chapter 5, February 6, 2008OUTLINE Questions? Stories, experiences? Solver Chapter 5 Examples Decide on quizGeza P. BottlikPage 1FACILITIES PLANNING ISE310L SESSION 7 Chapter 5, February 6, 2008
USC - ISE - 310L
ISE310 Spring 20067/10/2008Probability Demand up Probability Demand down Probability staying the same % change0.5 0.5 0 20% Revenue CostProbability Price up 0.5 Probability Price down 0.5 Probability staying the same 0 % change 10% Spot Profi
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 6 CHAPTER 5, FEBRUARY 4, 2008OUTLINE Questions? Decide on Quiz Roll if no quiz Chapter 5.4Geza P. BottlikPage 1FACILITIES PLANNING ISE310L SESSION 6 CHAPTER 5, FEBRUARY 4, 2008Chapter 5 Network Des
USC - ISE - 310L
FACILITIES PLANNING ISE310L SESSION 5 CHAPTER 4, JANUARY 30, 2008OUTLINE Questions? Roll Any supply chain stories in the news? Chapter 4 Designing the distribution network Decide on quizGeza P. BottlikPage 1FACILITIES PLANNING ISE310L
Cornell - MATH - 1120
This syllabus is subject to CHANGE. Any changes will be announced in class and on the course web page as the semester progresses. The schedule is for MWF sections, but as it is meant to be only approximate, it gives a good enough idea of when various
Berkeley - POL SCI - 149
Defining Oneself Identity Politics in Modern Southeast AsiaMulticulturalism pervades Southeast Asia. Indeed, this culturally vibrant region is home to thousands of ethnic groups, languages, and religious practices. Instead of embracing its countrie
UCF - COP - 4600
UCFSchool of Electrical Engineering &amp;Computer ScienceCOP 4600: Operating Systems Summer 2008SyllabusInstructor: Eurpides Montagne Tele.: 823-2684 email:eurip@cs.ucf.eduLecture meetings: TR 10:00 a.m. 11:50 a.m.(HEC 118) Office hours: MW from
Michigan State University - ANTR - 551
Landmarks to know for Anatomy ClassVertebral Bodies C1 o Anterior oblique plane of Superior Thoracic Aperture C2 C3 C4 C5 C6 o Esophagus stems from pharynx o Trachea stems form the larynx C7 o Largest spinous process (vertebral prominens)
Michigan - MOVESCI - 250
The Relationship Between Female High School/Collegiate Aged Athletes' Varying Hormone Concentrations Associated With the Menstrual Cycle and the Susceptibility to Anterior Cruciate Ligament InjuriesBrittany Hartman Ashley Kick Jeff Magnatta Tim Mart
Chapman - PSY - 203
Karen Horney 1Karen HorneyAshley Hahn Psychology 202 December 7, 2006Karen Horney 2Introduction There are many women psychologists that have made an important contribution in psychology. However, they seem to not get a lot of credit for what
Chapman - PSY - 201
Hypothesis Paper Theme:Empirically based Strength determined by data Hypothesis driven if . then . (yours) Primary source including meta-analysis Not including review paper of empirical No first person Introduction Common elements Importance
Chapman - PSY - 201
Ashley Hahn Psychology 201 Critical Thinking M/W: 2:30-3:45 10/9/06 Hypothesis If a person takes yoga then his/her concentration will improve. Independent Variable: Yoga because yoga is going to be what causes the dependent variable. Yoga is a system
Ouachita Baptist - HIST - 2113
MODULE 1: A TRIBUTE TO THE COMMON FLEAFrom grade school, we are all indoctrinated with the basics of the discovery of America: Columbus, three ships, 1492, and so on. Omitted from that simplistic-and occasionally musical-narrative is any explanation
Ouachita Baptist - HIST - 2113
MODULE 2: PARADIGMS OF SETTLEMENTBy the seventeenth century, the three major imperial powers of Europe- England, Spain, and France-had begun to invest vigorously in the New World. Each pursued the settlement of the Americas for different reasons and
Ouachita Baptist - HIST - 2113
MODULE 3: THE SECRETS OF COLONIAL SUCCESSAs Roanoake proved, the settlement of a colony in America was by no means a guaranteed success. As the colonization industry became increasingly privatized, the urgency of returning a swift and sizeable profi
Ouachita Baptist - HIST - 2113
MODULE 4: REVOLUTION BY CHOICEThere is certainly an air of inevitability about the American Revolution, isn't there? After all, the colonists were thousands of miles away from Mother England, nourishing their own political and cultural values for ge
Ouachita Baptist - HIST - 2113
MODULE 5: THE EXPERIMENT BEGINSThe United States, then and now, has been described as &quot;the Great Experiment.&quot; Those who use that moniker tacitly ask: can a large, diverse republic built upon democratic institutions survive over time? The path from w
Clemson - IE - 456
Bullwhip Effect means it increases variability as they travel up the supply chain. Centralized information Observes customer demand, forecasts the demand mean and variance using a moving average with p demand observations, finds target inventory lev
MCPHS - PSB - 332
Biochem Outline Chapter 9Lipids have 3 biological functions: 1. Lipid bilayers - essential components of biological membranes 2. Lipids containing hydrocarbon chains serve as energy stores 3. Many intra- and inter- cellular signaling events involv
MCPHS - PSB - 332
Biochem Outline Chapter 7 1. Myoglobin a. Myoglobin Structure i. Most of its 153 residues are members of eight alpha-helices (usually labeled AH) ii. Contains a single heme group 1. Conjugated system with a central Fe(II) atom liganded to four N ato
MCPHS - PSB - 329
Gould Chapters 17 &amp; 18 Blood and Lymphatic Disorders Blood critical part of body's defenses, carries antibodies and WBCs. Also helps control body temperature. Clotting factors in blood are readily available for hemostasis, and helps maintain a stabl
MCPHS - PSB - 332
Biochem Chapter 24 Outline DNA Replication, Repair, and Recombination 1) DNA Replication a) Semiconservative when replication results in two molecules of duplex DNA&lt; each consisting of one polynucleotide strand from the part, and one brand new one b
MCPHS - PSB - 332
Biochem Outline ch. 11 1. General Properties of Enzymes a. As compared to normal chemical catalysts: i. Have higher reaction rates (several orders of mag. Higher) ii. Can operate in milder reaction conditions. Chemical catalysts generally need high
Berkeley - GEOG - 20
Geography 20: Globalization Spring term 2008 Final examination review notes A. Country studies 1. Why was it possible for Japan to industrialize through internal capital formation but impossible for India to do so? - industrialization did not come ab
Berkeley - GEOG - 20
Lecture 1: A new world order? Welcome to this course, Geography 20, Globalization. My name is Bob Acker, and my office hours and e-mail address are on the syllabus thats being distributed. Your grade is comprised as follows: there will be a takehome
Berkeley - GEOG - 20
Lecture 2: Is this anything new? The first point for today is whether organizing the world economy on a global scale is something completely new, or whether it's actually the continuation and culmination of trends that have been in place for some tim
Berkeley - GEOG - 20
When and why did the current wave of globalization begin? As I was saying last time, the first era of globalization ended with the First World War. I put the article called Sinking Globalization in the reader because it deals with the question of whe
Berkeley - GEOG - 20
Lecture 4: Geography of Transportation Here's today's plan: I want to start with an overview of the basic concepts of transportation geography, which will enable us to see why lowering transportation costs is so key to globalization, and then discuss
Berkeley - GEOG - 20
Lecture 5 Containerization: The Port of Oakland and the Panama Canal. This course used to be titled The Local and the Global, and it was all about how the quality of everyday life is affected by globalization-you know, you go to 99 Ranch and there's
Berkeley - GEOG - 20
Lecture 22: Modern demographics The next three lectures will concern modern demographics and migration in the era of globalization. This lecture will be about modern birth and death rates and population growth, the next lecture will be about the hist
Berkeley - GEOG - 20
Lecture 22: Modern demographics The next three lectures will concern modern demographics and migration in the era of globalization. This lecture will be about modern birth and death rates and population growth, the next lecture will be about the hist
Berkeley - GEOG - 20
Lecture 20: Education and retraining 1. Question time What was responsible for the European recovery after World War II? How big a role did the US play? This is an interesting question because it brings up something called the Marshall Plan, named af
Berkeley - GEOG - 20
Lecture 19: What's the problem? Question time: Didn't you go a little overboard? Last time I said in effect that the WTO's Dispute Settlement Body was a court. This is a bit overstated. It looks and acts like a court in that it weighs evidence and ma
Berkeley - ASIAN STUD - 20A
Lecture 23: Migration Like the demographic transition we discussed last time, migration is intimately related to the two waves of globalization, and also intimately related to the of the United States and in fact, to that of the entire New World, Nor
Berkeley - GEOG - 20
Lecture 18: International trade part 3: The GATT and the WTO Review chart Thanks to this brilliant chart, you can review the comparisons drawn yesterday between tariffs and subsidies:Economic interests affectedEffect on consumer pricesEffect on
Berkeley - GEOG - 20
Intellectual Property (IP) and GlobalizationIP and GATT Your reading makes it seem as though IP was a natural extension of GATT from goods only, to goods and trade, to goods and trade and this thing called IP, which is just another piece of the mod
Berkeley - GEOG - 20
Lecture 11: International and finance and currencies Definition Today's lecture and next Wednesday's are about international finance, the passing of money internationally. The topic for today will be international investments and loans, and next week
Berkeley - GEOG - 20
Lecture 12: Currency fluctuation Today's lecture will describe the exchange of one currency for another, buying Mexican pesos or Japanese yen or Euros with dollars or the other way round. Currency fluctuations. There are two main kinds of currencies.
Berkeley - GEOG - 20
Lecture 13 Speculative attacks The last main topic I want to bring up today is whether speculators can bring about exchange rate fluctuations. The basic point I want to make is that speculators can't bring them about by themselves. There has to be an
Berkeley - GEOG - 20
Lecture 14: Corruption. There are serious problems associated with corruption. The most obvious one is that it costs money. It's just not good when you have to earmark five or ten percent of the cost of a project to give away as gifts to government o