View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Discussion 2 - Peter Budny

Part 1: Describe the Portland Form. Why is it useful?

The Portland Form is a generic structure for a document that describes a design pattern. It is not a standardized form, but more of a guideline, and it does not call for specific formatting. Rather, the Portland Form is a way of laying out a narrative that discusses a design problem and shows a solution.

A document written in the Portland Form first states, in natural language, the kind of problem it attempts to solve. This is typically written as a statement of fact, like, "When you are doing X, you have to do Y." It also explains why the problem has to be solved. It then explains a solution to the problem, again mostly using natural language. Having explained the solution to this problem, the next section discusses the next logical problem the developer would run into.

The Portland Form is useful because its natural language structure makes it very easy to read, and puts the developer at ease regarding their dilemma. It also leave little room for distinction between big and little problems; they are all treated matter-of-factly as just a single hurdle to get over.


Part 2: Describe one design pattern or pattern language in your own words.

While their use sounds obvious, Temporary Variables are a design pattern, and an extremely useful one. Using Temporary Variables means pulling out sub-expressions and assigning them to variables with a limited scope, and then using those variables later on. The advantage is in readability and maintainability for developers. A function whose only purpose is to calculate a value and return would be very hard to read if the body were "return" followed by seven lines of math. By using temporary variables, sub-expressions are given human-friendly names, which aids in understanding what the math is computing, and by making the individual steps visible, can even aid debugging and eliminate sources of error.

Temporary variables are occasionally eschewed by programmers because they can theoretically reduce program efficiency, but all modern languages are optimized to the point that temporary variables are identified as such and optimized away.

I have written and worked with programs written both with and without the use of temporary variables, and I have found programs that use temporary variables to be much easier to read and understand. The only caveat to this is that temporary variables, with their limited scope and short lifetime, should not be difficult to add when writing code. Some languages require all variables to be declared, sometimes (like C) at a specific place. Having to interrupt your train of thought to scroll up and declare a new variable is frustrating, and I think it often contributes to the lack of use of temporary variables. Temporary variables are most often used in languages like Perl where they can be used without first being instanciated.


Links to this Page