Layered architectures come up again and again in software design, being a natural byproduct of the recursive nature of computing. Any function call that never references its parent is effectively a new layer.
Of course, we don't always call these things layers: to do so would be to cheapen the term. In software architecture, a layer generally consists of a swappable set of functions that maintain the integrity of the overall layer stack. The traditional network layers are an excellent example of this. UDP could transmit HTTP data, even though TCP is generally used for this. Different devices use different physical links, and a countless set of application-layer protocols without imposing any required changes to the layers beneath.
The network stack also reveals something about the dynamic nature of architectural layers: as long as your interfaces are stably defined, new layers can be inserted, removed, or combined as necessary. The original OSI model for network stacks established 7 layers for digital communication, including a "data-link" layer (separate from the physical layer), and a "presentation" layer (separate from the application layer). Functionally, these are important layers. Practically, their implementation wound up combined with other layers in the stack such that they are now rarely discussed independently. The "session" layer, responsible for maintaining a dialog between remote application is now functionally part of the transport and application layers: TCP will guarantee message delivery, and HTTP will manage a client/server session. SSH can easily be used as the application layer, wrapping any other application layer within it. Because the interfaces are well-designated, these layers can be added without affecting the system as a whole.
Another example of the evolution of layers due to well-designed interfaces is in virtualization. Any program that executes on a computer goes through a number of translations, often being translated from managed code into assembly code, assembly into bits traversing a system. Memory access is converted from virtual to physical addresses, physical to block/offset locations. Anywhere a conversion takes place, a new layer can be inserted, as long as its external interfaces communicate consistently. This notion has enabled computers to run multiple simultaneous operating systems. New layers are added, translating kernel's system instructions into lower-privilege commands, and translating the operating system's "physical memory" addresses into the real physical memory addresses. The end points can communicate just as they had previously, however.
Granted, the addition of new layers will always reduce performance. So developers have turned to concepts such as paravirtualization, effectively combining separate layers into a single one, maintaining consistent behavior at the end-interfaces, but internally operating differently than if the layers were distinct. For example, a paravirtualized operating system may delegate memory paging to the hypervisor, rather than handling it by itself to improve performance. Thus, one step in the memory translation is saved. Similar approaches are taken for devices: rather than have a layer to deal with driver translation, hypervisor-level drivers can be accessed by the hosted operating systems.
A rough analogy of this set-up can be found in law. Layered architecture is like federalist government: the responsibilities of each layer of government (federal, state, local) are determined by the functionality of the layer above it. These layers operate by consistent interfaces (law and funds) but internally have theoretical freedom in their implementation. Realistically, this is often not the case: governments can often micromanage state spending by strongly incentivizing certain actions ("sure, you don't have to drop your local speed limit to 55, but then you unfortunately wouldn't qualify for highway funds"). In this respect, government is more like a "relaxed" layered system... higher-level layers can interfere with lower level ones.
So, would government an ideal government be able to defy this desperation of layers? Does good software expose the internals to lower layers? Is it even remotely fair to treat the answers to these questions as related? Of course not. Thus, in celebrated ignorance of this conclusion, I present to you: an abbreviated interview with Thomas Jefferson, political theorist on federalism.
Kurt: Mr. Jefferson, it is with great privilege that I needlessly interrupt your studies. I have but a simple question for you:
Jefferson: What, man? Who the hell are you? I've never seen cloths so fu--ed up before. Holy sh--. Georgie boy bought me the good stuff this time. I cannabalieve it. Heh, heh. Get it?
Kurt: Mr. Jefferson, are you...?
Jefferson: Yeah, man, what?
Kurt: I'm embaressed to even be asking this question... are you... well... in a condition to speak?
Jefferson: Sh-- man, I do all my writing fu--ed up. It's the best fu--ing way, man. Best fu--ing way.
Kurt: Ah... well. I guess I'll just... just, how do believe that governments should be arranged? What amount of authority should a federal body have over smaller ones?
Jefferson: God damn, field me the easy ones, freaky alien dude. The several states composing the United States of America are not united on the principle of unlimited submission to their general government; but by a compact under the style and title of a Constitution for the United States, and of amendments thereto, they constituted a general government for special purposes and delegated to that government certain definite powers and whensoever the general government assumes undelegated powers, its acts are unauthoritative, void, and of no force. To this compact each state acceded as a state, and is an integral party, its co-states forming, as to itself, the other party. The government created by this compact was not made the exclusive or final judge of the extent of the powers delegated to itself, since that would have made its discretion, and not the Constitution the measure of its powers.
Kurt: So... maintain a strict separation then?
Jefferson: God I am fu--ed up.
I... I really don't know if I feel comfortable applying that advice to my programs. But I'm not sure if I'm comfortable applying it to government any more either. Damn.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment