Site Sponsors:
Pay-As-You-Go -v- Global Initialization 
While easy to understand in Java, the opportunity to initialize data & classes prior to their use is a well known technique.

Here is a Java:


static ColorPair[] colors = null;

static {
List<ColorPair> array = new ArrayList<ColorPair>();
Color[] ccc = {
Color.BLACK,
Color.BLUE,
Color.CYAN,
Color.DARK_GRAY,
Color.GRAY,
Color.GREEN,
Color.LIGHT_GRAY,
Color.MAGENTA,
Color.ORANGE,
Color.PINK,
Color.RED,
Color.WHITE,
Color.YELLOW
};
for (Color a : ccc) {
for (Color b : ccc) {
if (a == b) {
continue;
}
array.add(new ColorPair(a, b));
}
}
colors = new ColorPair[array.size()];
array.toArray(colors);
}


Indeed, when we are guaranteed to use static content, then taking the time to pre-initialize objects is a common practice. Why would anyone want to do anything else?

Yet when calculating the total latency in pre-execution load times, on more than one occasion I have been found re-factoring static initializers so as to allow programs to be more responsive.

Pay As-You Go


Given that the above example has been defined as package-protected, surely it can be declared private.


private static ColorPair[] colors = null;


After so hiding the data structure, the very next thing to do might be to expose the structure with a more visible member function.


public static ColorPair[] GetDefaultColors() {
return colors;
}


Once so exposed, a far less costly initialization strategy can be created. -Specifically, rather than requiring colors to be pre-initialized, we can now pay-as-we-go by only allowing the initialization loop to run when the data are needed:


private static void init() {
List<ColorPair> array = new ArrayList<ColorPair>();
Color[] ccc = {
Color.BLACK,
Color.BLUE,
Color.CYAN,
Color.DARK_GRAY,
Color.GRAY,
Color.GREEN,
Color.LIGHT_GRAY,
Color.MAGENTA,
Color.ORANGE,
Color.PINK,
Color.RED,
Color.WHITE,
Color.YELLOW
};
for (Color a : ccc) {
for (Color b : ccc) {
if (a == b) {
continue;
}
array.add(new ColorPair(a, b));
}
}
colors = new ColorPair[array.size()];
array.toArray(colors);
}


Note in the above that the initialization still takes place as before, but not every time our program is loaded. Rather, we can "pay as we go" by allowing the structure to be initialized only if, as well as when, the data are required:


public static ColorPair[] GetDefaultColors() {
if(colors == null)
init();
return colors;
}


Conclusion


Whenever I find myself migrating a bit of code from a project into a support library the first thing I look for is an opportunity to convert any global / static initializers into a pay-as-you-go strategy. Of course, given that one of the first principles of good Object Oriented Design is Encapsulation, from a puritanical point of view many often find very little justification for doing anything else.

Enjoy the Journey!

-- Rn

[ view entry ] ( 639 views )   |  permalink
Criminal Incompetence, or Simply Evil? 
It was time to get another phone. Since I have plenty of Android devices, for the sake of comprehensive R&D testing I decided to get a resource constrained iPhone.

After I logged into the web site using my 10+ year account, I was told that my new IPHONE 5C would be a free upgrade, with no contract required. Happy days.

After ordering the phone, I tried to cancel the order a mere 5 minutes after ordering the unit. Unlike what one might expect from a self-sourcing equipment vendor, I was told that it was impossible to cancel my order!

Sadly, by the time I received my phone you might as well forget that ludicrously-lame 14 D-A-Y return policy. I simply needed a phone in-the-field, as well as ANY phone to support my own Apache Cordova R&D testing plans.

So not only did I have to pay full price for the phone + an activation fee, but imagine my dismay when I was not even able to activate the device after its arrival without agreeing to a 2 year contract!

Then there would be a restocking fee?

Further outrage might have taken place when - upon visiting the Apple Store - we saw that this exact same phone was being offered by at&t for free!

So please: If the people at at&t mobile phone support division are not evil or stupid, then surely their software research & software development teams are completely lacking any semblance of technical ability!

Better still: When we tried to register the phone at the at&t web site (via wifi,) even the Safari would not work until Javascript was disabled!

Certainly it seems that SOMEone who surely checked off the "okay" box on this entire use case might have not even been able to pronounce the word "t-e-s-t"?

Yet one cannot help but to wonder: Is this farce merely yet-another case of pathetic corporate software developer incompetence, or simple money-grubbing deception?

Either way, one must conclude that this is not your daddy's AT&T!

So what was the total cost + commitment for my "free" phone in consideration of our decade++ support of at&t, you might ask?

A mere $3,320.oo!

It seems that P.T Barnum was right - yet if you do not want to be the sucker who got sucked in, then you had better not order on-line with at&t!


[ view entry ] ( 636 views )   |  permalink
UML: Getting Started 
I've no idea why so many software developers seem to be afraid of creating & sharing diagrams. --Not only is a picture worth 1,000 words, but when we work with others to chart-out the things we need to do, a set of diagrams will often save a similar number of defect, meeting, & R&D hours.

Of course diagramming common knowledge is often a guaranteed time waster, as well! --But when requirements are vague and / or the tasks are complex, then knowing how to depict systems in an industry-standard manner should be of obvious value?


So please allow me to share our free training on the Unified Modelling Language (UML). By way of a bonus, the video series includes an example of an Open Source Project designed by using a very few UML artifacts to both capture & describe project operations.

[ view entry ] ( 708 views )   |  permalink  |  related link

<<First <Back | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Next> Last>>