Tidying up some code that has what I consider to be a confusing line break structure:
return CommonContext.HttpWebService.DownloadXml(configuration.MethodUrl(APIMethods.CharacterSheet), postData);
If it were on one line it would clearly to be to long to be readable. As it stands it is not clear to me at a cursory glance how the ‘return’ and ‘postData’ are related to the long line. CommonContext and APIMethods are static classs, configuration is a local variable.
Thinking about this I would probably write the same in two lines as follows:
string methodUrl = configuration.MethodUrl(APIMethods.CharacterSheet); return CommonContext.HttpWebService.DownloadXml(methodUrl, postData);
Is this an effective way of spiting the code up or is there a better way? In this instance I am using C# 2.0.
Yes. It’s a good thing usually. It makes code more self-documenting (with a good variable name) and also makes debugging easier (allows putting a breakpoint on the first line, and when an exception is thrown from the first line, you can immediately distinguish it as opposed to the single line situation).