Tangential comments about Software Development

Monday, January 31, 2011

Clever Code and Simple Names

A new departure this month has been writing code for a handheld device running .Net Compact Framework and talking to a web service. It's gone well.

One challenge has been to hold a cookie on the handheld so that the web service session can be held. Credit goes to a fine bit of code by Alex Feinman which provided everything I need. Here's the code in action:

public List FetchReferenceData()
Service w = new Service();
RequestData ReqData = new RequestData(w.Url);

That's the only reference to the ReqData object, while the service w logs in, downloads data and logs out. So when I copied the code to do an upload as well, I removed the RequestData line as being redundant. The upload failed, of course, because the "redundant" code was actually causing the cookied web request to work.

What to conclude? My class now talks to a lazily created Service as shown below. But I feel that I should rename RequestData so that its usefulness is made clear. Does RequestWithCookie sound better than CookiedRequest?

private Service MyService
if (m_service == null)
m_service = new Service();
m_requestdata = new RequestData(m_service.Url);
return m_service;