Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Re-factoring
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01577083
Message ID:
01577179
Vues:
59
>>One quick question - what would you use if you have 10 string columns (starttime1, starttime2, etc.)? I need some sort of the collection here, I am thinking about a dictionary of fields, but want to learn better alternative.
>>
>
>Since it looks like your code is running a loop across those fields, I'd probably create a List<DateTime> for them. That way I could just reference them by an index. A dictionary is really meant for when you want to do lookups by a "name" or some other unique key. You could do that by setting the key to "starttime1", "starttime2" but honestly that's just code you don't even need; an index into a List will work just fine.

This is what I've done yesterday. I also decided to use a List. The columns are String in the table although they need to be converted to datetime based on the date parameter. I thought about passing that date to the constructor, but at the end decided to have them as List of Strings and do conversion into dates in the method itself (because I log bad date formats there also).


>
>I know you've gotten other feedback, but for porting VFP code to .NET I actually found it was easiest to convert the code almost as-is (I even just paste the VFP code into a comment in .NET). Then I'll start translating - that helps me to understand what the heck the code is supposed to do. Depending on what I'm doing I may decided it's easier to replace the VFP code with a stored proc. (or a view), especially in sections of code that do a lot of queries, then queries on the results of those queries, etc.
>
>I also start refactoring the code like you're doing by looking for sections of code that may repeat themselves, or for sections of the code I'm finding difficult to understand - or even just read because of a lot of visual noise like your code that keeps casting DataRow fields to the correct type. The real trick is to keep refactoring it until it's cleaned up and not just stopping after the initial conversion (since that code is going to be REALLY ugly, probably really slow, and a maintenance nightmare).


That's what I also found - in some cases I did replace VFP code with stored procedure and in some cases I just tried to make the methods smaller. Yesterday after your idea about the row I introduced another simple class as well - DateRange. I was wondering why I didn't introduce it earlier as I could have used it in many methods also. I did a quick re-factoring of another method I already had. I will do several passes in that code once I finish this long VFP class conversion (I have about 7 more methods to convert - I left the hardest methods till the end).
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform