Section 1

.pdf

School

Simmons College *

*We aren’t endorsed by this school

Course

350

Subject

Computer Science

Date

Apr 25, 2024

Type

pdf

Pages

6

Uploaded by miraclezexist on coursehero.com

6/6/2021 Section 1.10 - COMPE 160: Introduction to Computer Programming https://learn.zybooks.com/zybook/SDSUCOMPE160PaoliniSpring2021/chapter/1/section/10 1/6 "My program is correct, but the system is complaining about output whitespace. " 1.10 Why whitespace matters Whitespace and precise formatting For program output, whitespace is any blank space or newline. Most coding activities strictly require a student program's output to exactly match the expected output, including whitespace. Students learning programming often complain: However, correctness often includes output being formatted correctly. PARTICIPATION ACTIVITY 1.10.1: Precisely formatting a meeting invite. 1. This program for online meetings not only does computations like scheduling and creating a unique meeting ID, but also outputs text formatted neatly for a calendar event. 2. A calendar program may append more text after the meeting invitation text. 3. The programmer of the invitation on the right wasn't careful with whitespace. "Join meeting" is buried, the link is hard to see, and the "Phone" text is dangling at a line's end. 4. The programmer also didn't end with a newline, causing subsequent text to appear at the end of a line, and even wrap to the next line. This output looks unprofessional. Kia Smith is inviting you to a video meeting. Join meeting: http://www.zoomskype.us/5592 Phone: 1-669-555-2634 (San Jose) 1-929-555-4000 (New York) Meeting ID: 5592 ------------------------- Reminder: 10 min before Kia Smith is inviting you to a video meeting. Join meeting: http://www.zoomskype.us/5592 Phone: 1-669-555-2634 (San Jose) 1-929-555-4000 (New York) Meeting ID: 5592 ------------------------- Reminder: 10 min before F db k? Captions Start 2x speed
6/6/2021 Section 1.10 - COMPE 160: Introduction to Computer Programming https://learn.zybooks.com/zybook/SDSUCOMPE160PaoliniSpring2021/chapter/1/section/10 2/6 PARTICIPATION ACTIVITY 1.10.2: Program correctness includes correctly-formatted output. Consider the example above. 1) The programmer on the left intentionally inserted a newline in the ±rst sentence, namely "Kia Smith ... video meeting". Why? 2) The programmer on the right did not end the ±rst sentence with a newline. What effect did that omission have? 3) The programmer on the left neatly formatted the link, the "Phone:" text, and phone numbers. What did the programmer on the right do? Feedback? Probably a mistake So the text appears less jagged To provide some randomness to the output Correct The two resulting lines are closer to the same length, which may look more appealing to a reader. On the right, the text just wraps when reaching the end, which isn't as neat. "Join meeting" appears on the same line No effect Correct On the left, "Join meeting" is clearly visible due to a preceding blank line. But on the right, "Join meeting" is easy to miss, appearing directly after the previous sentence. Also neatly formatted those items Output those items without neatly formatting Correct The output on the right is not neatly formatted. The link is harder to see, and "Phone" is in the wrong place due to a missing newline.
6/6/2021 Section 1.10 - COMPE 160: Introduction to Computer Programming https://learn.zybooks.com/zybook/SDSUCOMPE160PaoliniSpring2021/chapter/1/section/10 3/6 4) On the right, why did the "Reminder..." text appear on the same line as the separator text "------"? 5) Whitespace _____ important in program output. Programming is all about precision Programming is all about precision . Programs must be created precisely to run correctly. Ex: = and == have different meanings. Using i where j was meant can yield a hard-to-±nd bug. Declaring a variable as int when char was needed can cause confusing errors. Not considering that n could be 0 in sum/n can cause a program to fail entirely in rare but not insigni±cant cases. The difference between typing x/2 vs. x/2.0 can have huge impacts. Counting from i being 0 to i < 10 vs. i <= 10 can mean the difference between correct output and a program outputting garbage. In programming, every little detail counts. Programmers must get in a mindset of paying extreme attention to detail . Thus, another reason for caring about whitespace in program output is to help new programmers get into a "precision" mindset when programming. Paying careful attention to details like whitespace instructions, carefully examining feedback regarding whitespace differences, and then modifying a program to exactly match expected whitespace is an exercise in strengthening attention to detail. Such attention can lead programmers to make fewer mistakes when creating programs, thus spending less time debugging, and instead creating programs that work correctly. PARTICIPATION ACTIVITY 1.10.3: Thinking precisely, and attention to detail. Because programs behave erratically Because the programmer didn't end the output with a newline Correct Programs should almost always end with a newline, so that any subsequent text appears on a separate line. Here, not only does the next text "Reminder..." appear on the same line (which looks bad), but that text also wraps, making the text even harder to read. is is not Correct Learners often want to ignore whitespace, but most programs that have output must take care to create neat output, with spaces and newlines carefully placed (and usually ending with a newline). Feedback?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help