Jim's Blog Ramblings about novels, comics, programming, and other geek topics

15Jul/105

Which direction is better for sorting multi-column list items?

Google AdSense

As I was working on a web site, one of the beta testers responded saying they didn’t like the default sorting (vertical) of the CheckBoxList elements used on a ASP.NET web form.

The CheckBoxList web control has a property called RepeatDirection which can be either Vertical (default) or Horizontal. Below shows two examples of how the data items will be rendered using each of the two RepeatDirection options.

1Aug/080

Creating an OpenSearch Provider

Google AdSense

4Guys From Rolla wrote a nice article titled "Helping Visitors Search Your Site By Creating an OpenSearch Provider". Scott Hanselman of Computer Zen also blogged about this a few days ago on his post named "Adding OpenSearch to your website and getting in the Browser's Search Box".

One of the nicest features of modern browsers like Mozilla Firefox and Microsoft Internet Explorer is the search bar in the upper right corner. With this tool you can quickly search any number of websites without having to first visit their search page.

-- Scott Mitchell, 4 Guys From Rolla .com

19Dec/070

Programming perspective

Having the benefit of writing lots of code over the last decade or so, I quickly came to realize that the best written function/application doesn't mean it will be accepted by the client.

I've had some awfully written applications that were loved and my best written applications (using the correct design patterns along with new methologies and techniques) were disliked.

I was even thinking about blogging about this before Jeff Atwood of Coding horror posted the article titled "Nobody Cares What Your Code Looks Like". Jeff concludes stating:

remember this: nobody cares what your code looks like. Except for us programmers. Yes, well-factored code written in a modern language is a laudable goal. But perhaps we should also focus a bit more on things the customer will see and care about, and less on the things they never will.

This has been my philosophy over the last few years. It doesn't mean that I need to write poor code - especially since I'm usually the one who needs to maintain the code base. It does mean that nobody really cares how it is written as long as it works the way the client wants it to work.

This is especially true on web development projects. I've studied web design trends, usability, navigability, and all those other user experience categories of web design. However, in web development everyone who uses an Internet browser believes themselves to be a certified web designer and can (and does) comment on the page presentation.

So just like in code, clients usually won't care about your best web design, web standards, or even a standard presentation schema (layout, colors, fonts, etc. across every page of a web site). Just remember, it's their product and you're just a vehicle to get there.

I've dubbed this egoless programming - putting aside the way you want things to be done in order for your clients to get their product. The clients will ask for things that will result in a sub-par product from your own viewpoint and standards.

But the client doesn't want your product, they want their product. Even if their product looks like someone used Front Page (or MS Word) to design it. The best we can hope for, is that the product is accepted and used and -maybe- we'll get another shot at fixing it later...

Unfortunately, these applications usually become showcases and are forever associated with you as the developer. Even if you disagree with how the client wanted it implemented, you're now stuck with it for better or worse.

I also discovered the Ten Commandments of Egoless Programming as written about in Jerry Weinberg's book The Psychology of Computer Programming. Commandment number two fits in nicely with this article and should be repeated to yourself on a daily basis. Here's a few other commandments to keep in mind.

  • You are not your code.
  • Treat people who know less than you with respect, deference, and patience.
  • The only constant in the world is change.
  • Fight for what you believe, but gracefully accept defeat.

Repeat the mantra: you are not your code

5Oct/0715

How to convert a street address to longitude and latitude (geocoding) via web services

Several years ago, I had a school project that required converting some addresses to longitude/latitude coordinates. We then took the coordinates and placed them on a street map for a mobile device application. The addresses came from a "Yellow Pages" like system lookup service which provided a phone number, street address, name, and business category. But the Yellow Pages service didn't provide a geographic coordinate.

First, I tracked down a free and very useful web service that provides this functionality. The web site GeoCoder.us provides a few different free web services including geocoding on street address, ZIP code, or city and state. GeoCoder.us offers SOAP, XML-RPC, REST-ful RDF, and REST-ful CSV formats.

We'll use the web service the requires a street address, so we can get a more accurate coordinate.

string street = "1060 west addison street";
string city = "chicago";
string state = "il";

The GeoCoder.us URL requires a specific parameter format. Here we append the street, city, and state to the base URL.  Then we create and load the URL into an XML document. By passing the URL to the XmlDocument Load method, it will handle calling and reading the web response.

string geocoderUri = string.Format(
    "http://rpc.geocoder.us/service/rest?address={0},{1},{2}",
    street, city, state);
XmlDocument geocoderXmlDoc = new XmlDocument();
geocoderXmlDoc.Load(geocoderUri);

Next, we need to add a namespace manager since GeoCoder.us uses the W3.org Basic Geo (WGS84 lat/long) vocabulary.  Below is an example of this vocabulary and the actual response that was loaded into our XmlDocument.

<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" 
         xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" 
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<geo:Point rdf:nodeID="aid62658379">
<dc:description>1060 W Addison St, Chicago IL 60613</dc:description>
<geo:long>-87.655788</geo:long>
<geo:lat>41.947372</geo:lat>
</geo:Point>
</rdf:RDF>

The namespace manager is needed so that we can select the long and lat XML nodes. Below we select the two XML nodes and parse them.

XmlNamespaceManager nsMgr =
    new XmlNamespaceManager(geocoderXmlDoc.NameTable);
nsMgr.AddNamespace("geo",
    @"http://www.w3.org/2003/01/geo/wgs84_pos#");

string sLong = geocoderXmlDoc.DocumentElement.SelectSingleNode(
        @"//geo:long", nsMgr).InnerText;
string sLat = geocoderXmlDoc.DocumentElement.SelectSingleNode(
        @"//geo:lat", nsMgr).InnerText;

double latitude = Double.Parse(sLat);
double longitude = Double.Parse(sLong);

Console.WriteLine("Lat: " + latitude + " Lon: " + longitude);

Finally, the coordinates are printed to the console and appear as:

Lat: 41.947372 Lon: -87.655788

Update: 10/6/2007 Once you have the coordinates, you can perform radius searching. For example, you can query for all records within 5 miles of each other or find the nearest record to another record. Troy DeMonbreun provides an example of how to calculate the distance between two geographic coordinates using a SQL Server UDF (User Defined Function). The GeoCoder.us blog also discusses how to calculate distances using two geographic coordinates.

Update 2: 10/19/2007 Yahoo also provides a very nice Web Service for geocoding at Yahoo! Maps Web Services - GeoCoding API. Yahoo uses the same REST method for the accessing the Web Service, but with separate URL parameters for city, address, and state. Yahoo's XML response doesn't use namespaces and won't require the use of a NamespaceManager. You'll be able to just use SelectSingleNode(@"//Longitude") and SelectSingleNode(@"//Latitude") to collect the geographic coordinates.

 

kick it on DotNetKicks.com

15Aug/070

Corporate Web Standards

Scott Gledhill of Digital Web Magazine wrote an interesting article a few months ago on Corporate Web Standards. Since my move back into the life of a corporate developer, I found most of these to be enlightening and applicable.

My past development experiences have now taught me to stop and think about the bigger picture when dealing with large corporate websites. Problems ... can be prevented - but first let’s see how they might occur.

I’ve had a chance to create some corporate web sites (both internal and external) and there’s a lot that Scott talks about that lines up with my experiences - both good and bad.

My Related Posts: ,