It’s just data

Abstractions vs Patterns

What follows is some random thoughts on simplicity and abstract/unrestricted vs explicit/uniform/constrained.

Networks

In SOAP/WSDL, the network is abstracted away.  A service is associated with a port, which is associated with a binding, which is associated with a transport and a port type.  Port types can define any number of operations, each of which associates input messages with output messages. 

In REST/HTTP, the network is explicit.  Every resource is associated with a URI that is expected to implement a uniform set of operations (in particular, GET, POST, PUT, DELETE).  In particular, much as every Java object is expected to implement toString, every URI is expected to respond to GET.

See also REST + SOAP.

Other Examples

Smaller, and sometimes less clear, examples:

Rasmus Lerdorf states that Database abstraction is mostly a myth; and describes the “shared nothing” architecture of PHP — essentially touting the lack of a feature as a selling point of PHP.

In JDO, persistence is explicit.

In E4X, XML is explicit.

In HTML, presentation is often intermixed with content.  In CSS, presentation is every bit — if not more so — as explicit; it is simply re-factored into a uniform mechanism.

The implementation of Ant dispatches the information found in the build.xml file to tasks implemented in Java based on a simple design patterns and introspection.

In Java Web Application Archive files, and in Ruby on Rails, directory names (and in some cases, file names) convey important information.

DuckTyping replaces pre-planned hierarchies with similarities in structure.  In Python, it is common for a method to accept a file-like object as opposed to requiring that such an object explicitly inherit from a specific file class.

In Python, indentation is uniform and constrained.

Identifiers

Identifiers in Java may be associated with packages, classes, interfaces, methods, fields, constants, variables, or parameters without restriction. 

In Ruby, the first characters of a name indicate how the name is used.  Local variables, method parameters, and method names should all start with a lowercase letter or with an underscore. Global variables are prefixed with a dollar sign ($), while instance variables begin with an ‘at’ sign (@). Class variables start with two ‘at’ signs (@@). Finally, class names, module names, and constants should start with an uppercase letter.

In Perl, sigils convey data type information.  In C/C++, Hungarian notation was once quite popular.

Some Java and C# programmers adopt prefixes for privately scoped class members (example: prefixing with an underscore or m_).

Patterns

JavaBeans is a pattern that requires the developer or IDE to write more code.  In general, public properties need not be named the same as the protected or private field that “backs” it.

In Python, you only write data descriptors when you need to override __get__, __set__, or __delete__.  The nearest equivalent to the concept of “private” involves a naming convention.

In Ruby, public members and the private members that back them are associated with attr declarations.

In all three languages, constructors/initializers tend to contain a lot of logic of the form this.foo=foo (or self.foo=foo in Python, or @foo=foo in Ruby).

Parting Thoughts

A toddler can often recognize a cat by pattern.  It is not until high school or college that a teenager understands the classification of felis domesticus.

Patterns tend to surface common details.  Abstractions tend to hide unnecessary details.  Those that favor abstractions see them as hiding complexity.  Those that don’t tend to see abstractions as adding complexity.  “Now you have two problems”

Depending on your point of view, this example is either complex (two or four languages, little separation of concerns), or simple (view-source, copy paste, one can safely make simple changes without understanding how everything works).

Once people lock into either patterns or abstractions, they tend to become religious about them.

Despite the emotional attachments that people have with both, there is no universal abstraction or universal set of patterns that everybody will agree upon.  There certainly is no universal consistency in the examples cited above.  Additions and counter-examples in comments and trackbacks are welcome.

In the long run, I feel that “fewest moving parts” generally wins out over “hides the details I don’t care about”.


Sam Ruby: Abstractions vs Patterns

Sam Ruby: Abstractions vs Patterns: In the long run, I feel that “fewest moving parts” generally wins out over “hides the details I don’t care about”....

Excerpt from Keith's Weblog at

Sam Ruby trying to put a definition to the word “simple”. Seriously, it’s not as easy to define as you think....

Excerpt from del.icio.us/rtomayko/kiss at

Garbage collection was still a controversial abstraction a couple years ago. These days? I dunno. Also: October 45th?  No problem!

Posted by Robert Sayre at

How do you relate your thoughts to the chapter about abstraction and patterns in Patterns of Software by Richard Gabriel?

Posted by Giulio Piancastelli at

Homing in on a detail, the quiz relies on PHP’s shuffle converting a “dictionary” to a “list”. The description of shuffle is just “This function shuffles (randomizes the order of the elements in) an array”. It’s only until you scroll down the comments that you find out it also replaces the associative with indexed keys.

Think there’s a sharp learning curve there for anyone who wants to understand the code but is not familiar with PHP’s idea of an array, be they programmer or not. Would that make it a candidate for hiding or is the learning curve worth it?

Thinking along the lines of the this;


good API designs happen when designers think of ... client programmers as users.

An interesting study could be when the school puts a version of the quiz on their website to help other students. Can imagine some helpful, volunteer, Java-dad, having scratched their head over how it works then recommending a switch to JSP.

Also interesting to compare apis like libcurl to the like of XMLHttpRequest.

Posted by anonymous at

Anne van Kesteren : Abstractions vs Patterns - Need some time to read this and links....

Excerpt from HotLinks - Level 1 at

Somebody took the simple out of SOAP and I hate him.

Posted by Randy Charles Morin at

That was a successful test of the Moron-Ruby peace treaty.

Posted by Randy Charles Morin at

Robert: There certainly is an abstraction underlying garbage collection, much as there is an abstraction underlying malloc.  I’d certainly lump garbage collection into the same category that I placed TCP/IP into.

Giulio: It seems to me that Richard is focusing mainly on macro-patterns at an architectural level, and I am focusing on micro-patterns at a syntax level.  That being said, we seem to have a similar outlook, and I particularly like some of the images that he shares which span the overlap between the two, like the following:

What he learned about painting surprised me. I expected that the lessons would talk about drawing skills and how to reproduce what you saw in reality by attending to each detail in order to create an accurate reproduction. What he learned instead was that by using the nature of the medium, the paint, the brush, and brush strokes, he could create the same effects as those of reality through reflected light and by the oil on canvas. So, instead—as I expected—of spending hours painting each branch on a conifer, my father would dab and push with a thick brush to create the effect of needled branches, and from a proper viewing distance his conifers looked as real as real.

anonymous: One thing I particularly like about PHP is not that the functions are well named or that the documentation is perfect (neither are true), but when I need something, I often find it.  I didn’t set out to demonstrate the use of shuffle, I set out to create a vocabulary quiz application.  In any case, I’d welcome anybody to try to recode that example into JSP.  You quickly end up with the code/data ratio getting to the point where the webpage is obscured, so you refactor your business logic into a bean, and then create a WAR file, and... 

Randy: You can do better.

Posted by Sam Ruby at

Sam, feel free to play and to look at the source. I didn’t search for an alternative implementation, just ported every single functionality to Java.

Still no need for a bean, WAR file, or whatever. The amount of Java code needed to implement the missing features with respect to PHP (that is, shuffle and array_flip) is more or less equal to the JavaScript code needed for your dynamic magic: if the latter doesn’t obscure the web page, the former does not as well; indeed both could be factored into separate files, but then you’d need additional packaging, and the View One Source trick would be lost.

What I didn’t like implementing my Java version:


But, I don’t know if don’t get your point, or if I get it because it’s nothing new: yes, typically, so-called scripting languages like PHP offer much more functionalities than so-called mainstream languages like Java; so, you end up fighting the language because of static typing (oh, I did not cast an Object to an Objecy[], silly me), but you also fight the library, which still lacks some interesting features.

As for the PHP features, at first they seemed strange and unnatural: flipping maps could be a danger, because you may end up with partially flipped maps, and substituting keys in a shuffled map it’s awkward. Indeed they seem to go well together, so perhaps someone put some thoughts designing them. Don’t know how many languages feature those, anyway: but PHP has always seemed to me a gigantic cauldron containing more or less everything and its dog.

Posted by Giulio Piancastelli at

Links for 2005-03-09 [del.icio.us]

Abstractions vs Patterns Whao! Ruby does a brain-dump on a bunch of programming/design thoughts. He edges “SOAP vs. REST” into “Ignorance is bliss vs. The Law of Leaky Abstractions.” Fired Google Blogger Lands A New Job Mark...

Excerpt from Cote's Weblog: Coding, Austin, etc. at

Patterns And Abstractions, Oh My!

Sam Ruby: A toddler can often recognize a cat by pattern. It is not until high school or college that a teenager understands the classification of felis domesticus. Read Sam’s comparison of patterns vs. abstractions here. It’s thought provoking....

Excerpt from davidwatson.org at

A vocabulary quiz application in JSP

Responding to a PHP vs JSP challenge to create a vocabulary test application....

Excerpt from Through the blogging-glass at

Misc

Some (not at all) random things, seen in the Matrix: Excellent post from Sam Ruby on “Abstractions vs. Patterns” Interesting description of “Speech-Act-Based Protocols in Computer-Mediated Collaborative Design”, seen at Carlos' site. ... And then...

Excerpt from Process Perfection at

Patterns And Abstractions, Oh My!

Sam Ruby: A toddler can often recognize a cat by pattern. It is not until high school or college that a teenager understands the classification of felis domesticus. Read Sam’s comparison of patterns vs. abstractions here. It’s thought provoking....

Excerpt from davidwatson.org at

Misc

Some (not at all) random things, seen in the Matrix: Excellent post from Sam Ruby on “Abstractions vs. Patterns” Interesting description of “Speech-Act-Based Protocols in Computer-Mediated Collaborative Design”, seen at Carlos' site. ... And then...

Excerpt from Process Perfection at

Hasty Generalizations

Jon Udell:  Only if you consider the Google maps interface of today and the MapQuest interface that existed at the time Google maps was introduced as being “roughly the same”.  I don’t.  The abstractions and patterns... [more]

Trackback from Sam Ruby

at

You need to look at this blog article https://midnightpapers.com/blog/disney-college-program-application for some tips on how to write great application for a Disney college program. I think it could be a real deal

Posted by Lisa Abrams at

Add your comment