I alway had a question in mind whether to have two function in our
programme or one function with "if statement"
for two task having some part common.
I try to explain through example
-First implementation
Node * GetNextFile(ListState state)
{
... //common statements for file and directory processing
... // File specific statement
}
Node * GetNextDIR(ListState state)
{
... //common statements for file and directory processing
... // Directory specific statements
}
-Second implementation
Node * GetNext(ListState state , NodeType type)
{
... //common statements for file and directory processing
if (type == FILE_TYPE)
{
... // File specific statement
}
else
{
... // Directory specific statements
}
}
Let me know your thoughts on this
I think if common processing statements are less , we can go first
implementation . 5 1213
shaanxxx <sh******@yahoo.comwrote:
I alway had a question in mind whether to have two function in our
programme or one function with "if statement"
for two task having some part common.
It Depends.
HTH; HAND.
Richard
(No, really. It depends. Not just on the task at hand, but also on the
system(s) you intend to use.)
On Dec 24, 4:07*pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
shaanxxx <shaan...@yahoo.comwrote:
I alway had a question in mind whether to have two function in our
programme or one function with "if statement"
for two task having some part common.
It Depends.
HTH; HAND.
Richard
(No, really. It depends. Not just on the task at hand, but also on the
system(s) you intend to use.)
How it could be dependent on system ?
(my thoughts are , first implementation will have more code because of
code duplication. This duplication of code be avoided using by
replacing with function. This will result into more CPU cost . Its
like if i try to save memory , i lose on cpu cycle)
shaanxxx <sh******@yahoo.comwrote:
On Dec 24, 4:07=A0pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
shaanxxx <shaan...@yahoo.comwrote:
I alway had a question in mind whether to have two function in our
programme or one function with "if statement"
for two task having some part common.
It Depends.
HTH; HAND.
Richard
(No, really. It depends. Not just on the task at hand, but also on the
system(s) you intend to use.)
How it could be dependent on system ?
Well, take only your own example. On some systems it would make sense to
treat a directory as a specialised kind of file; on others, it would
not.
Richard
On Mon, 24 Dec 2007 04:09:32 -0800 (PST), shaanxxx
<sh******@yahoo.comwrote in comp.lang.c:
On Dec 24, 4:07*pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
shaanxxx <shaan...@yahoo.comwrote:
I alway had a question in mind whether to have two function in our
programme or one function with "if statement"
for two task having some part common.
It Depends.
HTH; HAND.
Richard
(No, really. It depends. Not just on the task at hand, but also on the
system(s) you intend to use.)
How it could be dependent on system ?
(my thoughts are , first implementation will have more code because of
code duplication. This duplication of code be avoided using by
replacing with function. This will result into more CPU cost . Its
like if i try to save memory , i lose on cpu cycle)
Where are the profile results that prove that your program is too
slow?
Where are the memory requirements and statistics for your program as
it is, proving that is uses too much memory?
Where are the test results proving that your program is complete,
correct, and meets all of its requirements?
If you don't have all of these things, you are wasting your time
thinking about memory versus execution speed tradeoffs.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
On Mon, 24 Dec 2007 01:57:45 -0800 (PST), shaanxxx
<sh******@yahoo.comwrote in comp.lang.c:
I alway had a question in mind whether to have two function in our
programme or one function with "if statement"
for two task having some part common.
I try to explain through example
-First implementation
Node * GetNextFile(ListState state)
{
... //common statements for file and directory processing
... // File specific statement
}
Node * GetNextDIR(ListState state)
{
... //common statements for file and directory processing
... // Directory specific statements
}
-Second implementation
Node * GetNext(ListState state , NodeType type)
{
... //common statements for file and directory processing
if (type == FILE_TYPE)
{
... // File specific statement
}
else
{
... // Directory specific statements
}
}
Let me know your thoughts on this
Both of your approaches are wrong.
I think if common processing statements are less , we can go first
implementation .
If you think that, do that. Get lost counting statements and lose
sight of important things.
T1 common(T2 param)
{
/* ... */
}
T1 type_one(T2 param)
{
/* ... */
}
T1 type_two(t2 param)
{
/* ... */
}
T1 some_func(t2 param, t3 other)
{
common(param);
if (other == /* ... */ )
{
type_one(param);
}
else
{
type_two(param);
}
/* ... */
}
Search "refactoring".
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Eakin, W |
last post by:
After recently coming back to php after working in asp for several
years, I want to do things well, so I'm very concerned with learning
good coding practices.
Also I'm trying to seperate logic...
|
by: Natt Serrasalmus |
last post by:
After years of operating without any coding standards whatsoever, the
company that I recently started working for has decided that it might be a
good idea to have some. I'm involved in this...
|
by: s.subbarayan |
last post by:
Dear all,
In one of our projects in a document about C coding standard it is
stated as
"Always check a pointer is NULL before calling free. Always set a
free'd pointer to NULL to try to protect...
|
by: Josh Golden |
last post by:
i lead a small development team (based on some of my posts that might cause
some people to choke themselves, but have no fear, i am NOT the lead
developer, the people on my team are great - i'm...
|
by: Ren |
last post by:
Hi All,
I'm still rather new at vb.net and would like to know the proper way to access
private varibables in a class. Do I access the variable directly or do I use
the public property?
...
|
by: Robert Seacord |
last post by:
The CERT/CC has just deployed a new web site dedicated to developing
secure coding standards for the C programming language, C++, and
eventually other programming language.
We have already...
|
by: burgermeister01 |
last post by:
First, let me say that this question is a rather general programming
question, but the context is PHP, so I figured this group would have
the most relevant insight.
Anyways, this is also more of...
|
by: dom.k.black |
last post by:
Can anyone recommend a good existing C++ coding standard - parctical,
pragmatic and sensible?
A company I joined recently are moving from C to C++, they are very
much into coding standards. But...
|
by: gentsquash |
last post by:
On some of my course pages, I quote (with attribution)
small sections of Wikipedia and the like. E.g, the top
of
http://en.wiktionary.org/wiki/entropy
has "entropia" in Greek font,
...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |