473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

extract method for better readability

hey all,
i have about a 40 or more lines in my switch statement and was just
wondering if it was worth extracting out the individual case statement which
would involve passing a Table object, 2 ints and a string?

What's the rule of thumb?

thanks,
rodchar
Nov 14 '07 #1
5 1238
You are going to have to provide more information than that. In what
way do you want to extract out that case statement?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:24**********************************@microsof t.com...
hey all,
i have about a 40 or more lines in my switch statement and was just
wondering if it was worth extracting out the individual case statement
which
would involve passing a Table object, 2 ints and a string?

What's the rule of thumb?

thanks,
rodchar

Nov 14 '07 #2

"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:24**********************************@microsof t.com...
hey all,
i have about a 40 or more lines in my switch statement and was just
wondering if it was worth extracting out the individual case statement
which
would involve passing a Table object, 2 ints and a string?

I think I would in that case.
What's the rule of thumb?
If naming the block is more helpful than seeing the code, then make it a
helper function.
>
thanks,
rodchar

Nov 14 '07 #3
hey all,
i have about a 40 or more lines in my switch statement and was just
wondering if it was worth extracting out the individual case statement
which
would involve passing a Table object, 2 ints and a string?

What's the rule of thumb?
Your question isn't very clear. Presumably you mean invoking a function for
each case statement or some particularly long case statement (or some
variation of this). If so then you should normally do that anyway IMHO
unless (perhaps) there's one (trivial) line per case. Note BTW that a case
statement (or equivalent "if" statements) often indicates a design problem
in OOP. I have no idea if that applies in your own case but testing
multiples values in a switch statement is often better replaced with objects
that have virtual functions (all derivatives of some common base class). It
depends on the situation of course since there's always a judgment call to
make and not everyone will always agree. It's typically better however to
invoke a virtual function on some object in a collection then to test a type
in a switch statement. You should always consider this whenever writing a
switch statement. For instance, switching on employee type such as
"manager", "architect", "developer", etc., and then calling a
"SalaryRange()" function for each employe type is poor design. It's better
to provide an abstract "Employee" class and an abstract "SalaryRange()"
function. You then create one derivative for each employee type and override
this function accordingly.
Nov 14 '07 #4
What's the rule of thumb?

I would say that the rule of thumb is: "If it makes your code easier to
understand and more maintainable do it".
Nov 14 '07 #5
sorry for the brevity of the OP but the feedback was helpful nonetheless.
thanks,
rod.

"rodchar" wrote:
hey all,
i have about a 40 or more lines in my switch statement and was just
wondering if it was worth extracting out the individual case statement which
would involve passing a Table object, 2 ints and a string?

What's the rule of thumb?

thanks,
rodchar
Nov 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
13
by: Tony Girgenti | last post by:
Hello. Using VS.NET 2003 VB. If i have a string similar to the attached, how would i extract the "Truckname=" data from it in a loop and stay in the loop until the end of the string is reached...
5
by: Milos Prudek | last post by:
I perform a XML-RPC call by calling xmlrpclibBasicAuth which in turn calls xmlrpclib. This call of course sends a HTTP request with correct HTTP headers. The response is correctly parsed by...
4
by: Steffen Bobek | last post by:
Extension methods are made for use with instances. I'd like to "misuse" them as static methods, too. Let me tell you my ambition: I use an extension method to serialize objects somehow like this:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.