About Adam Young

Once upon a time I was an Army Officer, but that was long ago. Now I work as a Software Engineer. I climb rocks, play saxophone, and spend way too much time in front of a computer.

Backwards Alphabet

To Learn the Alphabet backwards, you need to have a mnemonic.  The mnemonic for learning it forward is Twinkle Twinkle Little Star.  We can use that same song to sing it backwards.  Here is the grouping

ZYX

WV

UTS

RQP

ONM

LKJ

IHGF

EDCBA

Now I’ve said my  my Z to A

Think I’ll go outside and play

Hers how the phrases of the original map to the backwards

ABCD  -> ZYX

EFG->WV

HIJK->UTS

LMNOP->RQP

QRS->ONM

TUV->LKJ

WX->IHGF

YZ->EDCBA

Don’t be surprised that some of the phrases are longer or shorter than you sing in the orignial, They don’t even have to match the number of syllables.  In many cases, you either drop the last note of the phrase, or double up on nodes.   For instance, the note where you sing ‘D’ does not have an analogue in the backwards one, as it is really a grace note between the BC phrase and the EFG phrase.

Swamped

Tyrone you are an artist of the ultimate degree
Your work I say if the truth be told
Is awesome, terrible a marvel to behold
Unfortunately I haven’t even one half hour free

So much to do but yet so little time
trying to plan all of the festivities
the country of Florin’s anniversary
Ensuring the wedding will just be devine
I can’t do everything I want
I’m Swamped

In the parade all the nobles will march
and if Duke follows baron the unrest will spread
And all these decisions will fall on my head
Which villain to hang from the victory arch
Everybody has something they want
I’m Swamped

Then theres the seating inside of the church
Ensuring we have the right food for the feast
Who will get Salmon or Chicken or Beef
None of the Nobles can be left in the lurch

Seating my Uncle Near my Aunt
I’m swamped

Rugen:
It certainly is hard waiting to be king
If I might be so bold as to suggest
set aside some time to get sufficient rest
If your’ve not your health you don’t have anything

You look just a little gaunt
You’re swamped

Refactoring: Introduce Builder

As I move more and more towards Immutable objects, I find myself extracting the building logic out from the usage of an object on a regular basis.  The basic format of this pattern is

mutable object =>  immutable object + builder

There are two aspects to using an object: creating it, and reading its state. This pattern splits those two aspects up into different object, providing a thread safe and scalable approach to sharing objects without restoring to locking. Modifications of the object are reflected by creating a new object, and then swapping out the immutable

There are two ways to go about making the builder. If the object is created as part of user interface or networking code, it make sense to use a generic map object, and in the build method, confirm that all required properties are there.
so code like:

if (inputStringKey.equals(‘x’)) obj.setX(inputStringValue);

becomes

builder.set(inlutStringKey, inputStringValue)
obj = builder.build();

If, on the other hand, the original object tends to be modified by other code, it makes sense to split the object so that the setters are on the builder object.  Thus the above code becomes:

builder.setX( x);
obj = builder.build();

The immutable object shouldn’t have getters, you should use public properties for them, make those properties public and immutable themselves. In Java, this means tagging them as final, in C++ make them const.

It the immutable object is fetched from a data store, there are two approaches to updating that datastore.  The simplest and least flexible is to have the builder update the store as part of the build function.  This mixes functionality, and means that you can only update a single object per transaction, but it does increase consistency of viewing the object across the system.  The more common approach is to have a deliberate call to store the immutable object in the datastore.  Often, this is a transactional store, with multiple immutable objects sent in bulk as an atomic commit.

Here are the steps to perform this refactoring:

1. Append the word builder to the class name

2. Create a new internal class for holding the immutable state of the the object and give it the name of the original object.  Give  the builder and instance member field of the internal type.  The internal class should have a no-args constructor.

3.  Push all fields down to the new class by  moving the fields .

4. Add a method called build that returns the internal type.

5.  Replace all calls of the form getProperty()  with

x=  builder.build() ;

x.property;

It is important to use the local variable, and to share it amongst all the places in the code that reference the local object.  If you don’t you will end up with one instance per reference, probably not what you want.

6.  Remove the getProperty methods on the builder.

7.  Give the internal class a constructor that takes all of its fields as parameters.  It should throw a standard exception if one of the parameters is null.

8.  Change the build method so that it returns a new instance, that gets all of its fields set via the new constructor.  This instance should just use the fields in the internal instance of the (soon-to-be) immutable inner object.  You will have to provide dummy initializers for the newly immutable fields.  The build method should thrown an exception if any of the values are missing or invalid.  It is usually required that you return all errors, not just the first one.  Thus this exception requires a collection of other errors.  These can be exceptions, or some other custom type, depending on the needs of your application.

9.   For each setProperty method on the builder, provide a copy of the field in the buidler object.  Make the corresponding field in the inner object immutable, and change the build method to use the field in the builder instead.

10. When you have finished step 9, you should have an immutable inner object. Provide an appropriate copy constructor.

11. Remove the no-args constructor from the immutable object.

12. remove the default values for the immutable fields.

You can now create a new builder object based on a map.  The keys of the map should be the names of the fields of the builder.  The Build method pulls the elements out of the map and uses them as the parameters for the constructor. This approach showcases one of the great limitations of Java introspection:  Parameter names are lost after compilation.  We only have access to the types and the order of the parameter names.  Thus, maintaining this map would be error prone.

A more performant approach is to extend the builder object above with a setProperty(String, String) method that sets the values of the builder fields directly.

Any Java object can act as a map if you use introspection.  Thus, you could do what the Bean API does and munge the key into the form “setX” by changeing the case on the first letter of the key name, and then calling

this.getClass().getMethod()

You could also use  property introspection like this:

this.getClass().getProperty(key)

Since you are using introspection, even though you are inside the class that should have access to private members, Java treats you as an outsider.  You can either drop permissions on the fields at compile time by making them public, or do so at runtime using one of various hacks.

This is one case where it makes sense to make the member fields public.  There is no information hiding going on here.  There may actually be some client codethat is better off calliing

builder.property = x

Than

builder.setProperty(x)

In C++, we have fewer choices, as there is no way either at run time nor at compile time to provide an iteration through the fields of a class.  The best you can do is to create a map of functors.  The keys of the map are again the fields of the builder, the values are functions which set the fields.  You end up with a setProperty function on the builder that looks like:

void setProperty(String& key, Strin& value){

propsetmap[key](value);

}

although with logic to handle erroneous keys.

A builder is a short lived, single threaded, mutable object.  It is up to the calling code to provide enough data to populate the builder.  The builder pattern works nicely with  inversion of control frameworks.  Code that uses an object should not call the builder directly, but rather fetch the object from the framework, where as code else where builds the object and adds it to the container.

If your code has interspersed sets and gets of properties, it is going to be really difficult to introduce the builder.  Chances are you are going to want to do additional refactorings to separate the concerns in your code.

BProc 5.0 is in Git

Penguin Computing has graciously provided their version of BProc to the
project. Special Thanks goes to John Hawkes, the Director or Software
Engineering and Andreas Junge VP of Engineering at Penguin for making this
happen. In the next couple of weeks, we’ll work at getting some packages
made from the code and posted on the files portion of the Sourceforge
site.

The code is targeted at a RHEL 5.4 Kernel, due to development priorities
at Penguin. Expect to see a set of RPMs for the Kernel and the userland
codes for the unified process space code.

For now, we are going to focus on the kernel side of development. Our
goal is to get the necessary changes into the upstream Kernel. We will
begin work shortly on a version of BProc that targets the current
development Linux Kernel.

As such, the beoboot and related code is going to be left untouched in the
CVS tree.

The Git Repository is live here:

http://bproc.git.sourceforge.net/git/gitweb-index.cgi

Expect it to go through some changes in the future as we get it cleaned up
and ready for distribution.

I still have an emergency hold on all email traffic to this list due to
the high percentage of SPAM. I will pass through all message that come
from real human beings, and that are regarding the BProc code base.

The code is very different from the last released version of bproc 4.0. I
will post more details in the future about how to get a Kernel built, why
we made the decisions we did, and what the plan is for the future. I am
very excited about this project, and hope to get some community momentum.

Thanks Again to everyone who made this happen.

My Grandfather’s Flag

The Following post was written by my Mother.

My Grandfather's Flag

My Grandfather's Flag

To the best of my knowledge, my father was given the flag while he was still in the army. He was not discharged immediately after the war but spent many years in the reserves. I remember him packing to leave for Camp Drum, as it was called in those days. He was not called up for Korea, but I think he was still in then because I can remember him going to camp for two weeks every summer for several summers. I was too young to remember him going in Ohio, and we moved to Merrick in 1949. I would have been too young to remember many summers when Korea broke out in 1950.

I remember him saying that when the war ended in Europe, they were preparing to go to the Pacific. As they were about to depart, the war ended in Japan. He said they then sailed back to NY, instead, and upon entering NY Harbor, they all through their mess kits overboard.

He became active in some military organizations. In Merrick the more active group was the American Legion, vastly different from what it has become today, a drinking, non-tipping hangout. He was an officer in that post. I am not sure which group gave him the flag, the VFW or the Legion, or the government. I remember him marching in some parades in Merrick on Memorial Day and Veterans (Armistice) Day, and they were a big group. The VFW post was, I think, in Freeport.

He won several medals which we played with, broke, lost. We were children, and he didn’t mind.

He didn’t keep up with any of the men he served overseas with but did with some of his reserve buddies.

Although he is not buried with that rank, he had told us that he was Chief Master Sargeant. I don’t know what that rank actually is. Maybe it was honorary. The chevron on his arm had lots of stripes and something in the middle. I think he is buried as a First Sgt.

As you know, his name is engraved on the memorial at Silver Lake in Baldwin. His name is spelled wrong, two L’s instead of one.

Grandpa always flew the flag on holidays. I continue to fly his flag for him and for all the men and women who have served in defence of this country. That includes just about every male member of my family–except your father. I only fly his flag on special holidays like Memorial Day, Independence Day, and Veterans Day.

Uncle Gene has the flag that was presented to me at his funeral. I gave it to Uncle Gene because, like his father, he served. I would have loved to give it to you, but I thought Gene really deserved it. I will give you this 48 star flag. It is older and signifies much more. And, of course, it was definitely before Alaska and Hawaii became states in 1959. So, for whatever the story, it really is Grandpa’s army flag. And he was proud of it.

Popup notifications

I am easily distracted. If a build takes more than say, three seconds, I usually will flip to doing something else. This means that I often miss when a build is completed, and end up losing a few minutes here, a few minute there.

Well no longer. I use Zenity! What is this you ask? I didn’t know either until today. Zenity is a command line tool for making a popup window appear.

Now My build scripts look like this:

mvn -o -Pdev install
zenity –info –text “Build is completed”

This kicks off the build, and, when it is done, I get a lovely popup window telling me: the build has completed.

As the Corollary to Murphy’s law states: If its stupid, but it works, it ain’t stupid.

Why zenity? I mean, there are at least a dozen different ways to popup a window. Well, in keeping with that Cardinal programmer virtue of laziness, it is because zenity is in the Fedora11 repo, and I am running Fedora 11. yum install is my friend.

Yes, I realize that if I were cooler, I would make my script tell me success versus failure, and pop up the appropriate window for that. I’m not that cool.

OK, I wanto to be cool. Here’s the new version:

mvn -o -Pdev install && zenity –info –text “Build is completed” || zenity –warning –text “Build Failed”

This pops up a warning message box on mvn returning non-zero for failure. Note the use of the && and the ||. The evaluation of this is kind of cool: The && (logical and) has short circuit semantics, so the second portion only gets evaluated if the first part evaluates to true. However, the || (logical or) only gets evaluated if everything before it fails.

Inigo’s Tale

(Flamenco)
Inigo:
The city of Toledo
gathered much acclaim
known for great sword makers
The best in all of Spain

The finest was  Domingo
His sword were straight and true
His family name: Montoya
That is my last name too.

One day we had a visit
From a most important man
He needed a custom foil
For his six fingered right hand

My father loved the challenge
and said he’d forge it right
for weeks he worked unstopping
from dawn to late at night

The six-fingered man demanded the saber
at one tenth the price agreed on at the start
my father refused and the six-fingered man
slashed my father right through the heart.

I loved my father dearly
he raised me to be true
though I was but eleven
I challenged him to a duel

The man he left me bleeding
with the marks you see here
That’s the last time I saw him
It has been twenty years

Twenty years of training
to duel as best I can
Twenty years of searching
For the Six Fingered man

I will find my father’s murderer
I will look him in the eye and say
Hello my name is Inigo Montoya
You Killed my Father
Prepare to Die.

Brawns, Brain, and Steel

This one is a minor I-IV-II-V number based on a melody I wrote a long time ago.  It is acappella until Fezzik starts.

Brawn, Brains and Steel

Vizzini: I was wondering if you’d help us
We’re performers from the circus
Lady up there on your horse
Can you help us find our course

How far to the closest town
Buttercup: There is none for miles around
Vizzini:There is no one near this scene
so nobody will hear you scream

Fezzik: If you want a job done right
bring along a man of might

Inigo: To bring the plan into accord
get yourself a hired sword.

Vizzini: For a plan thats circumspect
needs a cunning intellect

For proper execution you’d best combine
Fezzik:My strength
Inigo: My Sword
Vizzini: My mind

First of all you need a plan
Vizzini he is your man
If you have some heavy work
You get Fezzik, the might Turk

To protect your gotten gain
Inigo the sword from Spain
The only way to close the deal
You need brawn and brains and steel.

If you’ve a mission coming on
you need steel and brains and brawn

Highlander Syndrome in Package Management

Somewhere between systems work and application development lies the realm of package management. There are two main schools of thought in package management: inclusive or exclusive. If you are inclusive, you want everything inside a package management system, and everything should be inside one package management system. If you are exclusive, you want the system to provide little more than an operational environment, and you will manage your own applications thank-you-very-much.

One problem with the inclusive approach is, in the attempt to clean up old versions, you often end up with The Highlander Syndrome. There can be only one version of a library or binary installed on your system. The Exclusive approach is more end application focused. I may need to run a different version of Python than is provided by the system, and I don’t want to be locked in to using only the version installed system wide. In fact, I may require several different versions, and each of these require their own approach.

CPAN, Pear, and Maven have provide language specific approaches level APIs to resolving dependencies at the per application level. Maven is particualrly good at providing multiple versions of the API: I errs so far this way that often the same Jar file will exist multiple times in the maven repository, but under different paths.

There should be middle ground for the end user between all or nothing in package managemnt. As a system administrator, I don’t want users running “just any” software on their system, but as an end user I don’t want to be locked in to a specific version of a binary.

If the role of application maintainer is split from the role of system administrator, than the people that fill those two roles may have reason to use a different approach to package management. Since the app developer can’t be trusted, the sys admin doesn’t provide root access. With no root access, the app developer can’t deploy an RPM/Deb/MSI. The app developer doesn’t want the system administrator updating the packages that the app depends on just because there is a new bugfix/feature pack. So, the app developer doesn’t use the libraries provided by the distribution, but instead provides a limited set. Essentially, the system has two administrators, two sets of policy, and two mechanisms for applying that policy.

Each scripting language has its own package management system, but the binary languages tend to use the package management system provide by the operating system.  Most Scripting language programmers prefer to work inside their language of choice, so the Perl system is written in perl, the emacs system is written in LISP, the Python one in Python and so on. The Wikipedia article goes into depth on the subject, so I’ll refrain from rewritintg that here.

A Package management system is really a tuple.  The variables of that system are:

  • The binary format of the package
  • The database used to track the state of the system
  • The mechanism used to fetch packages
  • The conventions for file placement

There is some redundancy in this list.  A file in the package my also be considered a capability, as is the “good name” of the package.  A package contain empty sets for some of the items in this list. For example, an administrative package may only specify the code to be executed during install, but may not place any files on a file system. At the other extreme, a package may provide a set of files with no executable code to be run during the install process.

Of these items, it is the conventions that really prevent interoperability. This should come as no surprise:  It is always easier to write an adapter on top of an explicit interface than an implicit one. The Linux Standards Base helps, as does the standards guidelines posted by Debian, Red Hat, and other distribution providers. However, if you look at the amount of traffic on the mailing lists regarding “file X is in the wrong place for its type” you can understand why automating a cross package install is tricky.  Meta package management schemes attempt to mitigate the problem, but they can really only deal with thing that are in the right place.

Take the placement of 64 bit binaries.  For library files, Red Hat has provided a dual system:  put 32 bit libriares under /usr/lib and 64 bit libraries under /usr/lib64.  Debian puts them all into the same directory, and uses naming to keep them apart. In neither case, however, did they provide a place to make 32 and 64 bit binaries co-exist. How much easier would migration have been if we had /usr/bin32 and /usr/bin64, with a symlink from either into /usr/bin?

Thus we see a couple of the dimensions of the problem.  An application should have a good name:  web server, mail client,  and so on.  A system should support multiple things which provide this capability, a reasonable default, and customizability for more advanced users.The system should provide protection against applications with known security holes, but provide for the possibility of multiple implementations released at different points in time.

An interesting take on package management comes from OSGi.  It is a language specific package management approach, specifically for Java.  It takes advantage of portions of the the Java language to allow the deployment of multiple versions of the same package inside a since Process. When I mentioned this to some old time Linux sys admins, they blanched.  OSGi does not specify how to fetch the packages, much like RPM without YUM or DPKG  with out APT.  OSGi packages are installed into the application.  As such, they are much more like shared libraries, with specific code sections run on module load and unload.  Different OSGi container provide different sets of rules, but basically the packages must exist inside of a subset of directories in order to be available for activation.  I have heard an interesting idea that the JPackage/RPM approach and OSGi should ideally merge in the future.  To install a Jar into your OSGi container, you would have to install an RPM.

One additional issue on the Java/RPM front is Maven.  Both Maven and RPM want to run the entire build process from start to finish.  Both have the concept of a local Database of packages to resolve dependencies.  For long term Java/RPM peaceful coexistence, RPM is going to have to treat Maven as a first class citizen, the way that it does make.  Maven should provide a means to generate a spec file that has the absolute minimum in it to track dependencies, and to kick off an RPM build of the Maven artifacts.