logo       

Re: A question of design... to Refactor a webform or not.: msg#00149

windows.devel.dotnet.web

Subject: Re: A question of design... to Refactor a webform or not.

> Does anyone here normally practice Refactoring on relatively non OOp
> code? Have you found it makes a difference or has it lead to further
> bugs and other issues?

Always look to split code into component parts, whether procedural or
not. This *reduces* bugs. The code is clearer and cleaner. This allows
you spot errors and potential performance issues.

Some basic guidelines in when to split code into subroutines:
- Duplication. If there is any duplication (even for just a couple of
lines), split it into a separate routine.
- Clarity. If you are doing a single operation that takes 4 say lines of
code, it is better to split that out into a separate routine.

Moving things to subroutines also allows you to group code that
logically belongs together. One good candidate to move to a subroutine
is the contents of a for/while loop. Another excellent candidate is code
the pulls data from some source.

Incidentally, before I moved to .Net I wrote a lot of code in classic
ASP, which is basically straight procedural. All the pages I wrote were
separated out into their respective subroutines, and where applicable
into include files. I found that after working with the language for a
little while that this was the only way to manage it effectively,
particularly as things got large. One single page was over 1000 lines of
code had 17 include files and 12 subroutines. You should start to feel
twitchy if you have a single block of code that is longer than about 75
lines.

regards
David Cameron

Robert Dickson wrote:
Hello All,

My normal coding for most web forms is to use perl-cgi stuff or PHP, however
in forcing myself to learn new things I have been conducting a series of
experiments duplicating various pages and web forms in ASP.Net for the sheer
versatility and learning experience it can bring. One of my pages done without
codebehind, just embedding the C# right into the form and doing most of the
development with WebMatrix was code that read 7 entries at random from an XML
file of 70+ entries. This fairly simple yet pitfall filled task was done in
about 80 lines of code in just a single method, Page_Load.

I was wondering what the general consensus is to refactoring this short of
code into a series of smaller functions and if doing such would improve or
degrade the actual performance of the page in terms of load time. The code
itself is fairly straightforward proceedural stuff and in fact I suspect my
method of accomplishing the whole thing is grossly inefficent. However since I
haven't actually had formal programming courses I am not entirely sure.

Does anyone here normally practice Refractoring on relatively non OOp code?
Have you found it makes a difference or has it lead to further bugs and other
issues?

--
Best regards,
Robert mailto:robert-lists@xxxxxxxxxxxxxx
-------------------------------------------------------------
Today's Random Observation:

Foolproof operation: All parameters are hard coded.

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise