Better Software - March 2008 - (Page 14) Code Craft The Other Side of Complexity by Chuck Allison Civilization advances by extending the number of important operations we can perform without thinking. – Alfred North Whitehead Software development has always been an exercise in managing complexity. It has progressed as a discipline as good minds have created abstractions that transform complexity into simplicity. There was a day, for example, when you had to write something like this: ISTOCKPHOTO mov add mov eax, DWORD PTR _x$[ebp] eax, DWORD PTR _y$[ebp] DWORD PTR _z$[ebp], eax instead of this: int z = x + y; Consider the function in listing 1 to reverse a list. ML uses pattern matching to select which branch of a function definition to execute. In the case of reverse, if the argument is the empty list (nil), then nil is returned. Otherwise the first list element is bound to the variable h and the rest of the list to the variable t to set up a recursive call. The point of this example, however, is revealed in the reverse function’s type signature: val reverse = fn : ‘a list -> ‘a list High-level languages encapsulated the complexity of programming at the machine level. Writing logical and quantitative expressions became simple again. Just as a statement is an abstraction of lower-level instructions, a function, or subroutine, is an abstraction of groups of related statements. Subroutines were the first software abstraction to facilitate things we take for granted today, such as refactoring and reusing code. Hence, functions enable the crucial practice of “separation of concerns” at the procedural level, so developers can build functional units independently. Function Abstraction If writing a function constitutes “statement abstraction,” what is “function abstraction”? I see a number of ways of looking at this. One approach is to group related functions into a single, logical unit, like the functions in C’s header or the static methods in Java’s Character class. But does this really represent a substantively higher level of abstraction? Perhaps function overloading is a slightly better example of function abstraction—but only slightly. Instead of coming up with unique function names on your own, the compiler does it for you. About the same time Dennis Ritchie was designing the C language, researchers in Scotland were working on ML, a strongly typed functional language. ML was the first statically typed language to generalize function definitions across types. fun reverse nil = nil | reverse (h::t) = reverse t @ [h]; Listing 1 The token ‘a is a type variable, like a template parameter in C++. The reverse function can process a homogeneous list of elements of any type, as you can see in the sample execution in listing 2. - reverse[1,2,3]; val it = [3,2,1] : int list - reverse[“one”,”two”,”three”]; val it = [“three”,”two”,”one”] : string list Listing 2 Now you know where C++ got the idea for template type parameters. Accommodating a family of related functions in a single definition surely qualifies as function abstraction. Data Abstraction and Beyond You would think that the next logical step would be to group data and related functions together into a coherent unit. It would have been, too, if it hadn’t already been done almost a decade earlier in the form of classes in Simula-67. Simula-67 introduced classes, inheritance, and subtype polymorphism, the type of function abstraction you achieve every time you override a (virtual) method in a subclass. 14 BETTER SOFTWARE MARCH 2008 www.StickyMinds.com http://www.StickyMinds.com
Table of Contents Feed for the Digital Edition of Better Software - March 2008 Better Software - March 2008 Contents Mark Your Calendar Contributors eLightenment Technically Speaking Code Craft Test Connection Management Chronicles Cover Story: Breaking Ground On SOA Software Development Worst Practices Mind the Gap Product Announcements 10 Things You Might Not Know About... The Last Word Ad Index Better Software - March 2008 Better Software - March 2008 - (Page Intro) Better Software - March 2008 - Better Software - March 2008 (Page Cover1) Better Software - March 2008 - Better Software - March 2008 (Page Cover2) Better Software - March 2008 - Better Software - March 2008 (Page 1) Better Software - March 2008 - Better Software - March 2008 (Page 2) Better Software - March 2008 - Contents (Page 3) Better Software - March 2008 - Mark Your Calendar (Page 4) Better Software - March 2008 - Mark Your Calendar (Page 5) Better Software - March 2008 - Contributors (Page 6) Better Software - March 2008 - Contributors (Page 7) Better Software - March 2008 - eLightenment (Page 8) Better Software - March 2008 - eLightenment (Page wp1) Better Software - March 2008 - eLightenment (Page wp2) Better Software - March 2008 - eLightenment (Page 9) Better Software - March 2008 - eLightenment (Page 10) Better Software - March 2008 - eLightenment (Page 11) Better Software - March 2008 - eLightenment (Page 12) Better Software - March 2008 - Technically Speaking (Page 13) Better Software - March 2008 - Code Craft (Page 14) Better Software - March 2008 - Code Craft (Page 15) Better Software - March 2008 - Code Craft (Page 16) Better Software - March 2008 - Code Craft (Page 17) Better Software - March 2008 - Test Connection (Page 18) Better Software - March 2008 - Test Connection (Page 19) Better Software - March 2008 - Management Chronicles (Page 20) Better Software - March 2008 - Management Chronicles (Page 21) Better Software - March 2008 - Management Chronicles (Page 22) Better Software - March 2008 - Management Chronicles (Page 23) Better Software - March 2008 - Cover Story: Breaking Ground On SOA (Page 24) Better Software - March 2008 - Cover Story: Breaking Ground On SOA (Page 25) Better Software - March 2008 - Cover Story: Breaking Ground On SOA (Page 26) Better Software - March 2008 - Cover Story: Breaking Ground On SOA (Page 27) Better Software - March 2008 - Cover Story: Breaking Ground On SOA (Page 28) Better Software - March 2008 - Cover Story: Breaking Ground On SOA (Page 29) Better Software - March 2008 - Cover Story: Breaking Ground On SOA (Page 30) Better Software - March 2008 - Cover Story: Breaking Ground On SOA (Page 31) Better Software - March 2008 - Software Development Worst Practices (Page 32) Better Software - March 2008 - Software Development Worst Practices (Page 33) Better Software - March 2008 - Software Development Worst Practices (Page 34) Better Software - March 2008 - Software Development Worst Practices (Page 35) Better Software - March 2008 - Software Development Worst Practices (Page 36) Better Software - March 2008 - Software Development Worst Practices (Page 37) Better Software - March 2008 - Mind the Gap (Page 38) Better Software - March 2008 - Mind the Gap (Page 39) Better Software - March 2008 - Mind the Gap (Page 40) Better Software - March 2008 - Mind the Gap (Page 41) Better Software - March 2008 - Mind the Gap (Page 42) Better Software - March 2008 - Mind the Gap (Page 43) Better Software - March 2008 - Mind the Gap (Page 44) Better Software - March 2008 - Product Announcements (Page 45) Better Software - March 2008 - 10 Things You Might Not Know About... (Page 46) Better Software - March 2008 - The Last Word (Page 47) Better Software - March 2008 - Ad Index (Page 48) Better Software - March 2008 - Ad Index (Page Cover3) Better Software - March 2008 - Ad Index (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.