Properties or Methods?

I am writing a .NET application which has a number of classes that are basically just data holders. They are instantiated by Factory objects that know about the DB but they themselves are just a collection of data members. For example, the User object has Email, Name and other such values but does no real work.

I did create all the getter methods (there are no setter methods as all values are put in the constructor) as methods but then I discovered Properties — one of the few things different between C# and Java. I am now in the process or replacing all get methods with Properties. Probably because I’m used to Java though code like this, “user.Region.Currency.Code” seems strange. I suppose its no different to “user.Region().Currency().Code()” but it just looks wrong!

I can’t find anything on the web about when to use properties and when to use methods (they are the same thing really) and the fact that I don’t really use setter methods means I don’t get that much benefit from Properties anyway. But I am using them to be more idiomatic and why not. What do you think?

Soulseek Down?

Soulseek is not down — its just moved! slsk.org no longer works and the new site is www.slsknet.org

You can make your old version of soulseek work by adding the following lines to your hosts file:

38.115.131.131 sk2.slsk.org
38.115.131.131 www.slsk.org
38.115.131.131 mail.slsk.org
38.115.131.131 server.slsk.org

Enjoy!

Soulseek Filesharing Has Widest Availability?

I think i came to the party late on this one but a number of my long-term filesharing wishes have just been satisfied on soulseek like When in Rome Kill Me by Cud and Long, Lonely Day by the Go-Betweens. Also the only filesharing system with genuine Razorlight (best new band of the year) songs.

Update 2004-04-24: Soulseek is now based at slsknet.org so I’ve corrected the above URL.

Best of this

These are just too good:

LRB subscribers – get six free issues and your money back if you’re not entirely satisfied with Market Rasen monkey (M, 78) – ‘The most serious and radical love monkey around’. Direct debit forms, and dried fruit, to Box no. xx/xx.

My previous contributions to this column were self-serving and contained many glaring omissions. This one gives it to you straight: I’m fat, thick, 48, still have uncooked semolina between my toes after an Aga-related accident in 1995, and look like the dwarf in Fantasy Island who yells: “Da plane! Da plane!” And I live in Ipswich. Any takers? Box no. xx/xx.

Many good ones ommitted. Best reader-contributed column in the history of man.

Spell Checker for Blogger

Adam wanted a spellchecker for his new blog without paying for it. I outlined a possible solution:

if you want to do it with writing as little code as possible then you 
will want to do it in Bash where you have "spell" and "cat" already. www.cygwin.com 
however, if you want to do it in the easiest way for you possible perhaps an 
ASP page on your local machine that you fill in the details on which spell 
checks against the attached dictionary file offering both a preview with 
highlighted possible spelling mistakes

The spell check is just:
' remove all punctuation symbols with Replace
' replace all whitespace chars with spaces
' recursively replace 2 spaces with one space (this step may be unnecessary)
' split on space and compare each var in resulting array with file (contents
' of which are in memory - its just an InStr(vbCrLf & strWord & CrLf, strDict)
' warning: dict file may be newlines only not CRLF

Or better yet get the words with a regex (supported in IIS5) along the lines 
of [^.;&
]* and then cycle through the matches.
So program flow is like this:
    Big text box with Preview and BlogIt buttons
    Preview => Show text from box with possible spelling mistakes in red
        and box appears below for editing with Preview and BlogIt buttons
    BlogIt => Force it through to submit page of blogspot.

Cool!

And while he messed with how to get the spellchecked story to post from his local machine to his blog I wrote it (in ASP).

Then it turns out that the blogger API is for XML-RPC which ASP can’t do (easily). So he wants me to rewrite, preferably in PHP which is what he has the submission stuff in.

I had never written any PHP before but I did the conversion which apart from a few sticking points was very easy (JSP/ASP/PHP are very very similar in the fundamentals).

The code shortened to 298 lines (from 363) and no longer requires an external sorting library as there is one built in to PHP.

Part of this reduction in size was due to the inlining of the ExtractWords function as with PHP’s regular expression support (just like Perl’s) it was a two-liner.

BUT there is no equivalent of Option Explicit in PHP! The best you can do is set ERROR_ALL in php.ini which is not the same thing at all. I must be overlooking something but I can’t find information about it anywhere on the web.

I still have some kind of problem with escaped apostrophes (PHP’sbastard hack called magic_quotes which I was happier not to know about) and the sorting is irrelevant because the algorithm does not take advantage of it and stop searching the dictionary when there is no longer any chance the word is in there (for that matter the dictionary isn’t sorted either!)

get_aspx_ver.aspx

Finally I get a solution to my missing get_aspx_ver.aspx 404 and alert email:

"VS.NET looks for this file if it needs to determine what version of the framework you’re using. Since it doesn’t care about the contents of the page, it just looks in the headers and ignores the Internal 500 message. — The file doesn’t exist, but VS has to call *something* to get a response header."

"It’s not actually a problem, it’s “supposed to work that way”. Heh whatever. It’s still a pain. Suggested workarounds from Microsoft include changing your error handler to ignore calls to the file or to just create an empty one."

Server did not recognize the value of HTTP Header SOAPAction

Seeing as nowhere on the internet can I find an explanation of this error I thought I’d share the fruits of my long search for this bug.

It means (at least in my case) that you are accessing a web service with SOAP and passing a SOAPAction parameter in the HTTP request that does not match what the service is expecting.

I got in a pickle because we moved a web service from one server to another and thus I changed the “namespace” (don’t get confused between web service namespaces and .net namespaces) in the calling C# file to match the new server. But the server doesn’t care about the actual web reality of http://yournamespace.com/blah it only cares that you send it what you have said you are expecting on the server. It doesn’t care if there’s actually anything there or not.

So basically the web service was moved from http://foo.com/servicename to http://bar.com/servicename but the “namespace” of the web service stayed as http://foo.com/servicename because no one changed it.

And that only took about 4 hours to work out!

If you’re having a similar problem but can’t work what I’m saying here, feel free to mail me on bakert+web@gmail.com – I wouldn’t wish my four hours on anyone!

Unit Testing for .Net

Had to take over a medium-size ASP.NET application at work and so I’m writing unit tests in the excellent, idiomatically translated NUnit, a port of the brilliant JUnit. I’m using Visual Studio 2003 and thus framework 1.1 which means I needed this fix to use NUnit with .Net framework 1.1