Five Things I Can’t Do with OS X Mail’s RSS

With the new OS X release of Leopard, there were amazing improvements in Mail. One of which was the addition of RSS feeds. Here are five things I can’t do with RSS in Mail that I wish I could… Apple, are you listening?

I notice with OS X 10.5 (Leopard)’s new Mail integrated RSS reader, once I have a feed there’s a few minor annoying limitations that aren’t available.

OS X Mail RSS1) While I can review what the RSS feed URL is by hovering over it, I can’t copy it to the clipboard.

2) If the RSS feed location changes, I can’t change the feed’s URL.

3) I’d love to be able to drag the RSS icon to a browser and have it open the page.

4) Or, I’d like to be able to right click the feed and have it open it in a browser or my default RSS reader (NetNewsWire).

5) Drag the RSS feed icon, or an article from the feed, into an open Mail message to share the URL.

I hope Apple will enhance the feature capabilities soon.

Reasonable Trial Durations: 30/30/30

I’ve come up with a way for trial software to be fair and recover lost sales opportunities. The secret: 30/30/30.

30/30/30While doing Java development, I was looking for a new IDE for Windows. Naturally, my hunt ended with IntelliJ, with Eclipse and NetBeans close on its heels.

What started the whole chain of thought for me, though, was IntelliJ’s trial period. Frankly, I really respect a company that has enough faith in their products that they let you use them, unencumbered, for a month in order to make an informed purchasing decision.

Oddly enough, though, it wasn’t enough. Allow me to explain.

The purpose behind a trial period is to allow end users to “log enough flight time” with the product that they know whether or not it meets their needs.

And here’s the problem. I have an existing code base of inter-related projects that I need to import into the IDE. And, since this is for work, my schedule is fairly swamped. I can only come up for air to do an evaluation once every week or two just for an hour or so.

What inevitably happens is this: I install the software, validate it installs, then a week or so later, I try to import; it fails, so I table the project until I have more time. A week or two goes by, and I try again, getting closer. Then, when I come up for air and try to get a bit further, the evaluation period is over. I’ve realistically had about less than three hours using the software, and none of it in the IDE writing code.

This happened to me last year as well.

And, what’s the natural conclusion at this point? I don’t know if it will meet my needs or not. Thus, a purchase doesn’t happen.

From marketing’s perspective, they think that the following scenario is the norm: a user downloads the project, tries creating a project, slings a bit of code, gets married to the IDE, and is willing to pay to keep the experience. In fact, I’ve done just this, and I really love IntelliJ.

But, no matter how much love I have for the product, if I can’t move our corporate applications into it from an existing source base, I can’t justify the site-wide purchase. End of story.

Oh sure, I could talk with the kind folks at JetBrains and ask for an extension, and I’m sure they’d give me one.

But that isn’t the point.

Being a software provider myself, I see this as a generic problem. What if I want to produce trial software that’s fair. I can’t have my customers not being able to make a well informed decision for running out of time.

Here’s my solution… 30 days, 30 invocations, 30 hours – Whichever Comes Last

Here’s how it works:

  • You’re guaranteed at least a month of physical time.
  • You’re guaranteed at least 30 invocations.
  • You’re guaranteed at least 30 hours.
  • When all three of the above goals are hit, stop the trial.

Implementing this isn’t be hard at all. It’s also quite fair and balanced.

If you are doing real work, making use of the application for 30 days, then you’re going to quickly chew through the 30 invocations and 30 hours.

If you have just haven’t even tried the software enough, you get 30 attempts.

Finally, the 30 hour rule recognizes if you haven’t had time to actually experience the software.

I’d like to see vendors start taking this approach. It’s a good one, too. It would certainly result in more sales.

Vista DeFrag Sucks

Vista’s Disk Defrag leave a lot to be desired. Here’s how to you can defrag your disk for sure.

Well before Vista was even real, I wrote about the problematic issues, bad practices for customers, and locked in formats that would make Apple Mac a highly attractive option. Pretty much most of the things people said couldn’t or wouldn’t happen have. It’s no wonder that the US Government would rather keep XP than move to Vista, that students on college campuses are reporting terrible problems interfacing with the IT departments and campus infrastructure, and that even Office formats are in dispute.

Even in our own offices, Vista has been one disaster after another, causing us all kinds of heart ache and productivity loss.

We thought the nightmare was over when we found a clever hack to make Vista think our networked HP LaserJet was a local printer (and we’d given up on being able to even use sound). However, we’ve been getting terrible disk performance on a laptop with Vista installed. Turns out the drive is badly fragmented.

Obviously, an XP user would simply run Disk Defrag and let that be that.

Not so with Vista. Sure, it has the program, but it provides no indicator of how much work needs to be done, and no visual interface at all about what’s being done. All you get is a stupid message that says the operation could take minutes to hours to complete.

So, we let Vista run overnight. And performance didn’t improve. At all.

You’ve got to see the conversation over on the Microsoft Developer Network about Vista’s defrager.

It seems that Microsoft expects you to leave your machine running all the time, and at some time like 2am on Wednesday, it will run the defrag automatically for you. Whether you want it to or not. And it will do the same crappy job.

If you’re running an enterprise service, you do not want to take an I/O channel hit “just because.” If you’re an IT administrator, you don’t want to screw with scheduling. If you’re a laptop user, you don’t want to leave your machine running.

Now I know I said I wasn’t going to give Microsoft support anymore. But I occasionally will share tips.

Grab the free version of Auslogic’s Disk Defrag. It will impress you. It’s clean, crisp, visual, astoundingly fast, and most importantly: it solved our fragmentation problems.

Hibernate: Duplicate Mapping and Imports

<GEEK BLOG ENTRY>
I ran into a very frustrating problem this evening, causing me to stay much later than I had intended, and to miss out on some fun socializing event that I was looking forward to. Unfortunately, there was little to no useful information on the Internet as Google was coming up with few and useless results.

I hope this post saves some poor soul from the same fate.

The Problem


I’m using the Hibernate library for persistence with a JBoss EJB using JPA. My code is sprinkled with annotations, my hibernate.cfg.xml file is clean, and I have no *.hbm.xml files. My code compiles. And it runs.

However.

When I try to access something that uses the Hibernate library, I get an odd message about “Duplicate Collection Role Mapping“.

The class in question contained a Set interface and a HashSet implementation for a member.

So, I commented out this container and tried again, hoping to simplify the problem.

This time I was greeted with a “[Mappings] duplicate import” and a “DuplicateMappingException: Duplicate class/entity mapping” set of error messages.

The only related web pages was a handful of archive with people asking similar questions in various online forums.

Almost always these fell into one of three responses:

  1. You’ve got a problem with the mapping element in your hibernate config file.
  2. You’ve got annotations and and class.hbm.xml file doing something wrong.
  3. This is an old bug in JBoss.

None of the symptoms existed in my case.

Here’s How I Solved It


Turns out that Hibernate makes the recommendation that you build a HibernateUtil helper class. Inside it, you’re supposed to make a singleton of the SessionFactory (and in the case of JBoss, you should use JNDI).

A co-worker had refactored the AnnotationConfiguration() to store a single copy, however, the routine that returned it happened to call .configure() on it before returning it each time. An honest mistake, which got integrated silently into my code when I pulled the latest version from version control.

Because .configure() was being called twice, to Hibernate it did look as if I had duplicate mapping directives in my hibernate config file.

Correcting the HibernateUtil method, which handled setting up and returning the AnnotationConfiguration solved the problem.

</GEEK BLOG ENTRY>

Rebuilding Spotlight’s Index on OS X (Manually)

Got problems rebuilding the Spotlight index on OS X or all you’re getting is an empty list with no files found? Here’s how I reindexed my system using just the Terminal and no special software – turns out there was one small thing that had gotten in the way.

After doing a number of disk clean up and optimizations, I found myself in the circumstance of OS X’s spotlight returning no results. Whether I searched for a keyword in Mail, or by Spotlight using Command-Space, I got no results backs – just an empty list for my troubles.

It turns out there’s a neat utility out there called Rebuild Spotlight Index 2.7 that does all the grunt work for you. Problem is, it didn’t work for me.

What’s going on is actually fairly trivial, and it’s possible to simply do everything via the command line.

The metadata utilities need to run as root, so to see what your drive is up to, you’d enter something like: sudo mdutil -s /

This shows the status on the root volume.

To turn indexing on for a volume, you enter: sudo mdutil -i on /

And, to force Spotlight to rebuild its index, you simply erase the master copy of the metadata stores on the volume like this: sudo mdutil -E /

However, while I did all this, Spotlight was still not building the indexed for me.

Here’s how I solved it, using just the Terminal.
First, I wanted to see the schema file, so I printed it out using to the standard input using: sudo mdimport -X

At the bottom of the schema listing, I say a reference to a schemaLocation, and took a shot in the dark that perhaps that Spotlight’s index rebuilding needed to check data against its schema before it would start. To do that, it might need network access, if not back to the local machine.

And, for good measure, I went to check the date/timestamp on the Spotlight directory using: sudo ls -la /.Spotlight*

While most of the files had the timestamp of when I tried to delete the index, not all the files had the current date and time. Additionally, the file sizes were not growing, a good indication the index was not being rebuilt.

Thinking to myself, “what could be causing network traffic, even internally, not to be working”, I realized that I had just rebooted and PeerGuardian2 was currently active and blocking traffic. This is a great tool for blocking malware and unwanted network visitors, but occasionally it gets in the way. So, I turned it off.

Then, I did the following commands to ensure indexing was on, the spotlight metastore was really gone, and that I wanted it rebuilt:
sudo mdutil -i on /
rm -rf /.Spotlight*
sudo mdutil -E /

The moment I did the last command, this time the system sprung to life, the directory /.Spotlight-V100 was created, and the files inside it were growing quickly. Spotlight on the toolbar showed a progress bar, indicating the system would be done indexing in a bit. The big difference? I turned off the network traffic blocker for a moment.

Ubuntu and Parallels Rescue Broken XP

How I recovered a badly damaged XP box with severe Windows Update problems using Ubuntu and Parallels for OS X.

Normally, I don’t provide XP support, however, because I was the one who recommended the owner perform a Windows Update that precipitated the total incapacitation of the machine, I felt a slight guilty streak of obligation.

Because of the horrible reputation of Windows Genuine Advantage disabling legal installations, the owner of the box disabled all Windows Updates for fear his system would become disabled and he’d lose his data. As such, when I recommended keeping the system patched, there were well over 60+ patches to start with.

Frozen XP DesktopProblem was, one of those patches was for the NVIDIA GeForce Ti 4200 graphics card, and during the installation process, when the Microsoft Version was applied, the machine froze, requiring a manual reboot via the reset switch.

Naturally, after a forced shutdown one should invoke a check disk. However something insidious occurred. Explorer, and I don’t mean Internet Explorer, no I mean Explorer – the GUI shell, would lock up shortly after login. The start menu would go dead, icons didn’t function, start/run couldn’t invoke programs, applications invoked from the command line wouldn’t work, Internet Explorer wouldn’t even start, and Windows Update did nothing. Even Ctrl-Alt-Del wouldn’t work, as the Task Manager couldn’t start. Nor could the user logout or shutdown the machine. Things were bad. It was like the desktop was there, but the underlying services that made it function were dead.

I’ve had easier recoveries from the blue screen of death. If you can get past that, usually you got yourself a working system. In this case, the system would boot, and even allow a login, but once there, the interface wouldn’t function.

Of course you’d think booting and reverting to the last known good configuration would help. It didn’t. Safe mode was equally hosed. Anything past the login prompt rendered the machine in a frozen state, popping up a message about a Windows General Services failing, with an option to report the problem to Microsoft.

That’s the state of the machine as I received it prior to repair.

Here’s how I fixed it.

The detail message reported that the offending file as WUAUENG.DLL. A quick Google search showed this was the Windows Update module. It seems between going from Windows Update to Microsoft Update, the DLL got corrupted. As Windows booted after login, it accessed the DLL, and the system froze.

My goal was to replace at least this file from a working system. Problem was, I was in a catch-22. I couldn’t access the broken system, and if it was possible, the files would be in use by the operating system anyhow.

I downloaded Ubuntu and burned it to a CD using OS X. I then booted off the live CD on the broken machine, however while it could see the NTFS volume, it couldn’t write to it.

So, I enabled all the repositories by going to System / Software Sources, making sure Universe and Multi-verse were included. Then I opened up the terminal and entered sudo apt-get install ntfs-config, and installed the package that allowed writing to NTFS drives.

I added root to the fuse group, and then went to Applications / System Tools / NTFS Configuration Tool. It was quick to tell me I needed to run ntfs /dev/hda1, which fixed the volume and set it to check the disk on boot.

I shutdown Ubuntu, booted Windows, which caused a check disk, and when I finally got to the login prompt, shutdown again without ever logging in.

I booted back off the Ubuntu CD, did the same trick as before with the repositories and installation of the NTFS driver, and this time was able to mount the drive as writable.

I went to the WINDOWS\System32 directory, and found the following files, to which I renamed them, appending .old to their extension for the purposes of a backup: wuaueng.dll, wuaueng.dll.mui, and wuaueng1.dll.

Then I booted Parallels on OS X, brought up a copy of XP, went to its C:\WINDOWS\System32 directory, and copied those three files to a USB stick. I unmounted the USB stick and shutdown Parallels.

With Ubuntu still running on the broken machine, I plugged in the USB stick, which instantly appeared on the desktop, and copied over three files to the broken machine’s system32 directory.

I then shutdown Ubuntu, removed the USB stick and CD, and booted into Windows. The error message was gone, but it was obvious things were still fragile.

Back on OS X, I downloaded Windows XP Service Pack 2, burned it to CD, and stuck it in the broken machine, executing it. A bit later, it finished and I rebooted.

I was suddenly able to run Windows Update again, and that downloaded 40+ updates, effectively jump starting the process by grabbing only the critical updates. In a rise-lather-repeat cycle, I did this until all the critical updates were obtained. Then I did the same with the optional software.

Each time I came in from a mandatory reboot, I made a system restore checkpoint.

Just to confirm it was the NVIDIA driver, I downloaded just that option from Microsoft, and the machine locked up. Which, to get out of I had to hit the reset button, screwing up the disk again. No problem though, I booted, holding down F8, and booted to the last known good configuration. When it came up, I right clicked properties on the C: drive, and forced a check disk, rebooting. The machine came up fine.

Going over to NVIDIA’s site, it was a trivial matter to download the latest driver for the GeForce 4200 card, and unsurprisingly, it worked without incident.

Ubuntu saved the day for being able to repair and manipulate the NTFS volume, while Parallels made it possible to see what needed fixing, where it went, and a working copy without having to have a second dedicated Windows box.

A recovery solution wouldn’t have been possible with an disc of an OEM version of XP alone. Honestly, I don’t know why users put up with this, or how Microsoft can sleep at night.

The recover process, non-stop, took from 10am – 7pm straight. No breaks. No food. No stalling. That’s nine hours of my life I’m never getting back.

Screen Calibration – Where’s my contrast?

If you’ve used Pantone’s huey for screen calibration, then you need to know about the hueyPRO. Additionally, if you think something’s up with your monitor because you can’t manually set the contrast, you want to read this. I bumped into this with a Dell 2001FP.

As someone who does a lot of photography, and I mean a lot of photography, I decided to invest in something that would do color calibration on my monitor.

A while back I purchased Pantone’s Huey and wrote a review saying just how much I loved it. [Pantone Software Update Page]

Since that review, Pantone has only made things better. My primary wish for dual monitor support has been granted in the form of the Pantone hueyPRO.

Once again, a fine quality product at an affordable price to end consumers rolls out the doors of Pantone. Not only do you get the device, a KlearScreen Starter Kit (with a polishing cloth), but you also get a Pantone Book of swatches of 100 Top Colors.

By simply dragging the application to the corresponding monitor, it’s possible to independently calibrate a monitor. That’s just plain cool, much better than drop down boxes and such.

This is where a new mystery appeared. As I was exploring how to manually calibrate a monitor, by setting the Brightness / Contrast by hand, I was startled to discover that my Dell 2001FP monitor wouldn’t allow me to adjust the contrast. It was like the firmware knew about it, but things were disabled.

Then I found this tidbit in the Brightness/Contrast section of the Dell 2001FP Documentation:

“Note: When using ‘2: DVI-D Input’, the contrast adjustment is not available.”

Makes sense. When a DVI connection is used, as I had done, the contrast control is no longer needed. My monitor doesn’t have a problem, all is well with the world.

REVIEW: Walt gives the Pantone hueyPRO a big thumbs up!!!

Mac to Windows: The Experience

I corrupted my Windows tech guru, turning him on to Apple. He explains from a Windows viewpoint what it’s like to deal with a bare-metal install on Apple compared to a pre-installed Windows system. In this review, we see a totally different perspective: rather than focusing on features, Marcus addresses the overall experience.

I have a good friend, Marcus. He’s a super-uber-master-wizard at Microsoft operating systems and has astounded me on numerous occasions with obscure tidbits of advice from secret registry edits to recovering from system crashes so bad that even Microsoft would recommend switching to Linux.

Why tell you about Marcus? Because I have corrupted him. Yes, it’s true — I showed him the Mac.

No, not the stupid little in-store demos where you can create a photobook with iLife; no, I gave him the real demo, the one reserved for hard core developers.

Marcus shortly thereafter obtained his own laptop, and quickly made the swap to OS X, abandoning in a fortnight over a decade’s worth of emotional ties to Microsoft.

Or so I thought. Marcus writes me, he’s got some new emotions pertaining to Microsoft.

What follows are Marcus’s own words, as only a Windows power-techie can explain. But this review of his isn’t about the features, it’s about the experience.

Marcus writes:

Macintosh. Every time I find another tool that Apple offers to make my life easier, I realize that the scale tips in there favor. I was able to rebuild that drive yesterday in under 2 hours using the transfer my data method from the OS CD. So as my positive experience increases with Apple, inversely that causes an increasing disappointment of Microsoft. I am still shocked that Apple will provide a utility that will allow you to replace your hard drive and automatically transfer not only your profile and files, but all of your applications and their licenses. I booted up and everything is working.

Marcus had an external Apple drive loaded with data and applications; he wanted to install a fresh new version of the OS on a different machine, but port over everything from the old disk – but not the older OS that was on it. Apple’s default OS installation does this automatically, cloning from another system.

Dell vs. McAfee. I bought a Dell Inspirion E1505 laptop for my nephew, Justin, to take to college with him. After putting in over ten years of technical support for various companies I’m now the technical support for the family when it comes to PC’s. I thought I would just open up the laptop and setup everything for Justin in advance. That way he could have one more kid moment when he opens the gift, it would be in a functional state and ready to work, i.e. play games.

I opened the box on a Tuesday night around 6pm. I got everything ready and turned on the laptop. Immediately things went wrong.

1) The network drivers were not loaded, so the system could not call Microsoft to register.

2) Once getting to the desktop, Internet Explorer crashed with a fatal error requiring a reboot.

3) McAfee was not installed correctly and reports too many errors to even cover. This required ALL of McAfee Security Center to be uninstalled.

4) Microsoft Update was not installed, rather they were using the old Windows Update. It crashed 3 times attempting to install this update. (Note: Microsoft Update patches all MS products, verses Windows Update, which only updates the OS.)

5) After Microsoft Update was installed, the real patches start to download. Two hours later on broadband, another GB of the hard drive gone, the system appears to be nearly functional.

6) At this point it’s getting close to 9pm on Tuesday. All of the Microsoft OS and applications are patched, registered and working properly.

7) I reinstalled McAfee. The installation appeared to go smoothly. The application no longer reports any errors and results in a HUGE green checkmark saying that my system is protected.

8) Next, I initiated the Update feature of McAfee and this is when it all goes wrong. A window pops up asking me to register my software now or later. Since I had purchased a 3 year contract with them, I would really like to do this to get full support from them. I select to register now and I got an hour glass suggesting something was going on, the screen flashed and nothing happened. I saw a little red circle moving next to the clock in the tool bar reporting that 16% of the updates were complete; however, the software was not registered. After the download is complete, it requested a reboot.

9) After the reboot, I did a right click on the M icon now next to the clock. This is McAfee Security Center’s ideal of easy access to their software. I was presented with several choices, but thought I would start with Product Setup. I selected that field, got an hour glass, a screen flash and nothing again. I decided to just select open Security Center this time. The application still reports everything is working properly within it’s horrible “Crayola” interface. I again attempted to verify if the updates were complete, so I selected Update. Again the register now button appeared and failed. After trying this several times, by 10pm I was completely done with this thing for the night.

Thursday (yes, I have a life and was busy on Wednesday):

1) I turned on the laptop and found that McAfee was still in the same state as I had left it.

2) I called India…rather, I called Dell’s technical support. They reported that this appears to just be a software problem and that I should call McAfee.

3) I called McAfee. Press # for Home Products. Press 1 to make a purchase, Press 2 for something, Press 3 for technical support. Technical support will cost you 2.90 a min, but feel free to use the free technical support on the web via right clicking the M on the toolbar and selecting Customer Support. (Note: You mean the M icon that’s broken and will not do anything for me. WOW, what a terrible idea!)

I decided to Press 1 to make a purchase. I told them I wanted to verify that I was a customer with them since I was paying for a 3 year subscription that I could not register. I gave them the Dell service tag number and I was not in the system. Then they asked for an email address or my customer number. I had to then explain again that their on-line registration was broken and that they would not have yet received any such information from me. They then asked for a phone number to look me up that way. Again reminding them that I had not given them anything yet to create an account. So, they manually created an account for my nephew. I thanked them for putting me in the system, but had to explain again that in now 6 days the application reports that if unregistered it will cease to function. They of course argued that I’m in the system and a paying customer. While on the phone, the application gave me yet another reminder to register.

Annoyed with McAfee’s mentally challenged support staff, I called Dell back.

I explained the situation of paying for software that is going to disable because it could not be registered. They worked with me for 45 min trying to find a solution. Then without pressing the issue any further, Dell informed me that I can simply request a replacement laptop within the first 21 days or my money back if I’m not satisfied.

Bottom line, Dell was so professional. Dell offered all the information I needed to just wash my hands of this whole matter. McAfee on the other hand really doesn’t seem to want to help anyone. Considering the choice between McAfee and Norton, I’m not really impressed with either, but at least Norton knows how to register their software.

To sum up, with OS X, Marcus was able to do something in approximately two hours that’s completely impossible to do with Windows: install an OS from scratch and move everything from an older system to it seamlessly.

On the Windows side of the house, even when it came pre-installed by an experienced vendor, it took him, a super Windows guru with a decade of experience multiple days and phone calls just to get Windows to a point where it could be given away as a gift.

Marcus, next time perhaps Justin would like a Mac? You did.

Unused local variables, a gotcha that’ll getcha

Removing unused local variables from your programs is actually quite safe, makes your code more readable, and helps get faster compiler times, and can even help produce a tighter, faster, more optimized executable. However, there’s one thing you really need to watch out for…

Recently I attended the No Fluff Just Stuff conference again and learned about a free, fantastic static code analyzer for Java, called PMD. It can use be used standalone or even integrated into many popular IDEs like NetBeans or Eclipse. For the curious, I’d tell you what PMD stands for, but no one really knows; worse yet, I can’t stop myself from typing PDM.

PMD has a nifty rule that allows it to locate Unused Local Variables.

Very quickly I was able to walk through our entire code base, identify things that were assigned to, and subsequently not used, and remove them.

Gotcha #0
The first major hit of the day is that you’ll want to do a Clean on your project before you start. Believe it or not, some project building steps can build intermediate .java, files from your master source code. Problem is, if they appear anywhere inside your project’s directory structure when PMD is making the sweep, they get analyzed to. And you don’t want that.

Gotcha #1
It turns out that there’s a reverse ripple effect in performing this kind of code cleanup and operation. After you’ve removed code, you’ll want to make sure you perform subsequent passes until all concerns are removed.

Take for instance this trivial case:
  B = A;
  C = B;
  // C is unused!

What happens is that once you remove C, it turns out B may no longer be used. Remove B, and it’s even possible A may no longer be used either.

Additionally, this can eventually lead to additional Unused Imports, which dealing with those can also decrease build time.

Gotcha #2 — The Real Evil
Normally, this kind of code clean up is absolutely harmless, although there’s one error of omission that a developer can make which will create problems and cause a silent failure.

Here’s a case where a static code analyzer recommends removing a very important line of code:

boolean doSomething(int x) {
  // Do something very important with x
  return result;
}

...
  boolean result = doSomething( x ); // Do Something Important
  // result not used
...

If the return value from a method isn’t used, then the static analyzer will assume the method doesn’t need to be called, and it will recommend commenting out the line — causing your program to silently break.

This is not a error on the part of the tool!

The error was actually that of the developer for not checking the return results of the method.

To correct the problem with the source code, the developer has three options:

  1. Change the method signature to be of type void.
  2. Throw an exception from the method.
  3. Check the return value of the called method.

Otherwise, the real error is that the method may attempt to do something, fail, and communicate back to the caller than something went wrong, but the caller blindly trusts that things are okay.

If you’re not going to check a return value, you shouldn’t be incurring the overhead of sending one. If the library writer provided one for a reason, then you should be using it.

Conclusion
When a code analyzer makes a recommendation, ask yourself what implied rules about your code the analyzer is assuming. Rather than blaming the tool, the better solution is fixing the source.

It may be best to comment out, rather than deleting, code that initially seems superfluous.

Finally, after a massive code sweep, run those unit tests.

Understanding jQuery

jQuery – it’s a AJAX library that uses a very terse notation to do an awful lot in JavaScript. Here’s a good explanation for developers that are unfamiliar with the library — it explains a mental picture of what’s going on, enough that you can pick up the library and start using it for more than just trivial tasks.

I’ve been playing a lot with AJAX recently, and have discovered a library that I’m quickly falling in love with: jQuery.

To provide you with context, I’m a software engineer and have been developing commercial applications for well over twenty years. I’ve played with Javascript when it was young, and I was unimpressed. I played with JavaScript when it was a little more mature, but because of Microsoft’s horrific incompatibilities with Internet Explorer verses the way the rest of the world worked, I gave up. Perhaps prematurely. But, none the less, I didn’t pay any more attention to the world of scripting on the web than whatever problem I had to demanded.

Then along came Ruby on Rails. I was surprised to learn that someone had actually written a library to abstract away JavaScript differences — what a clever solution! To that end, I started looking at Prototype and became impressed at the cleverness of the helper functions. That got me to look at Scriptaculous, and suddenly the world of JavaScript didn’t seem so bleak.

But jQuery. Wow. This library resonated with me very quickly, and I started thinking in and doing more functional programming than I had ever done before (opposed to procedural and object oriented). The library was so easy to use, that I was able to do quite a lot with it without understanding it. That was months ago, but today something clicked. I started to see in my mind’s how exactly how jQuery does its magic, and in such a way as to describe it to someone who’s never used one of these AJAX libraries before.

Javascript, she ain’t that bad


Javascript allows one to define classes. Those classes can be extended — don’t think in terms of derived subclasses, but rather actually plastering on additional methods to a pre-established class. Additionally, those methods can have overloaded signatures. And for the sake of brevity, identifiers we’d never use in other languages, are perfectly acceptable short names. We’ve been taught that although identifiers can start with things like dollar signs and underscores, to stay away — these are for library writers and operating systems people. Even though a single dollar sign might be legally syntactically, one should never do it; though in the world where network speed and space matters, such short names are encouraged. Finally, blocks of code, the very stuff you would call functions, can exist all on their own — all you need is a reference to them, they don’t need a name.

Accept all the above as a given, and a tribute to what’s become of JavaScript while you’ve been playing in other languages.

Groking jQuery


Now at this point, I’ll express my conceptual view of jQuery, and while it may not be technically correct or even how it’s implemented, the mental model will give you gross insights has to how you ought to use the library.

Imagine if you will a class called jQuery. Rather than having to type out jQuery each time, we use an alias, a simple dollar sign (the shortest legal identifier that’s not alphanumeric). Its sole job, internally, is to maintain a collection of references to pre-existing elements in your DOM. This collection may be empty, contain one, or more elements. As the developer using jQuery, you need never see this list; you only deal with the jQuery object itself. Ever.

jQuery has many overloaded constructors, which is how it learns what elements to keep in its internal list. You can provide it a reference to an element, a kind of element, an id of an element, a CSS class used by elements, an XPath to one or more elements, straight blocks of HTML, etc. It can even use another jQuery object (which contains a list). jQuery has exotic syntax for picking very specific elements based on conditions and attributes; it even has filters to removing elements from the list.

The actual list isn’t important, because after it’s done with the constructor, all you have is a jQuery object. And the only thing you can do at that point is call jQuery methods. But, oh how clever is jQuery!

Anytime you call a method of jQuery, it does an internal for-each across its internal list, applying your method to every DOM element in its internal collection. Once more, when it’s done, it returns the very jQuery object that was just used.

Object oriented developers know what this means: you can chain methods, creating long strings of behaviors!

jQuery directly manipulates the DOM in a browser-specific manner under the hood, so that you get one, simple, transparent, elegant way of expressing what you want. The actual implementation details are no concern; if a method exists, it works the same way everywhere, regardless of browser.

And, because jQuery operates on numerous elements by twiddling the DOM, it’s possible to write a small piece of code but hook it in all over the place… a process that used to be quite tedious, but can now be done after the fact, meaning your raw HTML is uncluttered.

The Simple Example


Let’s look at a simple tutorial like example.


$(“.xyzzy a”).click(function(){
alert(“Magic!”);
return false;
});

Quite literally, this says create a jQuery object that is a collection of every anchor in containers with a class of ‘xyzzy’, then assign its onClick event handler to reference a function (that has no name!) that displays an alert message.

In Conclusion


That’s pretty much it. The two things to learn are the number of various constructs and types that can be passed to the constructors and filters, and the other thing is the various methods that affect those elements. That’s the meat of it.

jQuery has other helper functions and such, but those are easily mastered. And, once you’ve got those under your belt, check out the plug-ins that are additional methods bolted on to the jQuery object.