Practical WebObjects

A new WebObjects book by Charles (Chuck) Hill and Sacha Mallais arrived on my doorstep last week (literaly, Steve accidentally ordered two copies, and I benefited from his Amazon click happiness). Practical WebObjects is aimed at intermediate WebObjects developers and I think it succeeds nicely. From talking about integrating Unit testing and contract programming to examples of Kerberos authentication it offers plenty of practical examples and lots of stuff to think about.

Not having taken the WebObjects courses offered by Apple (and others), I’ve done the majority of my learning relying on books, the web, the docs, and playing. Practical WebObjects is a solid book that adds depth to the existing offerings. I wouldn’t suggest it as a first book to someone getting started (Joshua Markers Visual Quick Pro Guide and Apple’s Tutorial are a better bet there) but for someone who is looking to expand their horizons or for a best practices guide I think it does an admirable job.

Thanks Chuck and Sacha!

Java 1.4 regex fun

I’m sure that everyone knows that Java 1.4 added regex capabilities through the java.util.regex package. I have existing applications using regex (from Jakarta Oro) that were built pre Java 1.4 so I haven’t looked at this support closely until now.

What I hadn’t realized was that you don’t need to use the Pattern or Matcher classes in java.util.regex to do simple regex substitutions, that capability is built right into java.lang.string!

An example of this usage would be formating phone numbers for storage or display. I usually like to store phone numbers as 10 character strings, and apply formating when they are displayed. This is easy using regex substitution. To format for storage:

String source = "(555) 555-5555";
String result = source.replaceAll("^1|\\D+", "");

The result will be "5555555555".

Conversely, to format for display:

String source = "5555555555;
String result = source.replaceAll("^(\\d{3})(\\d{3})(\\d{4})", 
				  "($1) $2-$3");

The result will be "(555) 555-5555".

The documentation for String.replaceAll is here and it is fairly straight forward:

public String replaceAll(String regex,
                         String replacement)

The first example used the regex: "^1|\\D+"  It says; match the first character if it is a "1" (^1) OR (|) any character that is not a number (\\D+) and replace with "" (the replacement).

The second example used the regex: "^(\\d{3})(\\d{3})(\\d{4})"  It says; match the first 3 characters and put them into a variable ($1) do the same for the next 3 ($2) and the final 4 ($3). Then using the replacement: "($1) $2-$3" wrap the contents of $1 with "()" add a space and the contents of $2, followed by a "-" and the contents of $3.

A good regex primer can be found here

No, not dead

The past month has been crazy. I’ve been working my tail off to complete one project (that should go live very soon) and just started a full time contract that is suppose to last a month…

So, no I’m not dead, but I do wish I were sleeping…

WWDC: Friday

Last day of the show, It felt better attended than Friday last year. Man, do they ever tear down quickly. The last session in some of the rooms was 5:00 PM and by 6:00 the drapes and stages were down.

The WebObjects feedback session was the last session I attended this afternoon, and although not a love-in (not even close), it was much better than I expected. Everyone was very civil and Apple was quite forthwrite and frank about the future of WebO. The news was not all good (or all bad for that matter) but it was good to know. They took suggestions for improvements to the tools and frameworks, and we’ll have to see how much effect that has.

I enjoyed the show, but it will be good to get home, sleep in my own bed, and see Al and the girls again. I’ll have to see what happens over the next year but depending on the release date of Tiger it might not be worth the expense and time to attend WWDC 2005. Time will tell