473,405 Members | 2,421 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,405 software developers and data experts.

Redundant behavior in coding guideline

Some of the coding guideline are mandatory, and even the format or
layout of the text of the source code also should be followed. There's
plenty of codes like the following snippet.

Do you think the "re-evaluating the previous condition" is necessary
and should be avoided though it's one of your coding guideline? And
yes, there's plenty of code like this in many projects.

78 /* Error handling */
79 if ((NULL == p_SrcNm) || (NULL == p_DestNm))
80 {
81 lb_RetVal = false;
82
83 /* some other things special here ... */
84
85 if (NULL == p_SrcNm) /* Re-evaluating the previous
condition */
86 {
87 /* some other things special here ... */
88
89 ErrorEntryAdd(p_SrcNm);
90 ErrorHandle();
91 }
92
93 if (NULL == p_DestNm) /* Re-evaluating the previous
condition */
94 {
95 /* some other things special here ... */
96
97 ErrorEntryAdd(p_DestNm);
98 ErrorHandle();
99 }
100 }

Nov 15 '05 #1
2 1148
lovecreatesbeauty wrote:
Some of the coding guideline are mandatory, and even the format or
layout of the text of the source code also should be followed. There's
plenty of codes like the following snippet.

Do you think the "re-evaluating the previous condition" is necessary
and should be avoided though it's one of your coding guideline? And
yes, there's plenty of code like this in many projects.

78 /* Error handling */
79 if ((NULL == p_SrcNm) || (NULL == p_DestNm))
80 {
81 lb_RetVal = false;
82
83 /* some other things special here ... */
84
85 if (NULL == p_SrcNm) /* Re-evaluating the previous
condition */
No, it's not re-evaluating. (NULL == p_SrcNm) || (NULL == p_DestNm) does
not equal or even imply (NULL == p_SrcNm).

If you mean that the boolean expression (NULL == p_SrcNm) is
"recalculated", then yes. However, comparing a pointer to NULL is such a
trivial affair that it doesn't warrant a separate boolean to record the
outcome rather than just repeating the check.
86 {
87 /* some other things special here ... */
88
89 ErrorEntryAdd(p_SrcNm);
90 ErrorHandle();
91 }
92
93 if (NULL == p_DestNm) /* Re-evaluating the previous
condition */
94 {
95 /* some other things special here ... */
96
97 ErrorEntryAdd(p_DestNm);
98 ErrorHandle();
99 }
100 }


I'm pretty sure the calls to "ErrorEntryAdd" are wrong, because they're
just adding NULL pointers as whatever an "error entry" is. That seems
rather useless. Are you sure you didn't forget quotes? Don't you need to
pass a string with an error description or something?

S.
Nov 15 '05 #2
On Thu, 27 Oct 2005 12:58:45 +0200, Skarmander wrote:
lovecreatesbeauty wrote:
Some of the coding guideline are mandatory, and even the format or
layout of the text of the source code also should be followed. There's
plenty of codes like the following snippet.

Do you think the "re-evaluating the previous condition" is necessary
and should be avoided though it's one of your coding guideline? And
yes, there's plenty of code like this in many projects.

78 /* Error handling */
79 if ((NULL == p_SrcNm) || (NULL == p_DestNm))
80 {
81 lb_RetVal = false;
82
83 /* some other things special here ... */
84
85 if (NULL == p_SrcNm) /* Re-evaluating the previous
condition */


No, it's not re-evaluating. (NULL == p_SrcNm) || (NULL == p_DestNm) does
not equal or even imply (NULL == p_SrcNm).

If you mean that the boolean expression (NULL == p_SrcNm) is
"recalculated", then yes. However, comparing a pointer to NULL is such a
trivial affair that it doesn't warrant a separate boolean to record the
outcome rather than just repeating the check.


An alternative structuring would remove the outer conditional and repeat
the code indicated by the outermost "some other things special here"
(possibly including "lb_RetVal = false;"), within each inner conditional
body.

The drawbacks are dual-maintenance of that code and the likelihood of
extra generated machine code.

The dual-maintenance could be dealt with by encapsulating the code in a
function; the extra complexity is a drawback to this approach, and unless
the function were inlined, the function call overhead would likely exceed
that of the removed conditional.

Since this is error-handling code, performance is likely not critical and
the current structuring seems preferable.
86 {
87 /* some other things special here ... */
88
89 ErrorEntryAdd(p_SrcNm);
90 ErrorHandle();
91 }
92
93 if (NULL == p_DestNm) /* Re-evaluating the previous
condition */
94 {
95 /* some other things special here ... */
96
97 ErrorEntryAdd(p_DestNm);
98 ErrorHandle();
99 }
100 }

[...]
--
http://members.dodo.com.au/~netocrat
Nov 15 '05 #3

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

Similar topics

17
by: Ray Gardener | last post by:
I've always wondered what other C++ programmers fail to do while coding even though they know what they're doing is... naughty (and some of the items below occur in other languages, of course). ...
1
by: jarit | last post by:
Hi, Found these coding guidelines for C#, HTML, Javascript, Java, HTML, PL/SQL, T-SQL, VB and VBScript. Well written and free to download. www.demachina.com/products/swat Jeroen
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
14
by: Ian Pilcher | last post by:
It's pretty common to see declarations such as: static volatile sig_atomic_t caught_signal = 0; C99 defines sig_atomic_t as a "... (possibly volatile-qualified) integer type of an object that...
0
by: lovecreatesbeauty | last post by:
Some of the coding guideline are mandatory, and even the format or layout of the text of the source code also should be followed. There's plenty of codes like the following snippet. Do you think...
40
by: Neo The One | last post by:
I think C# is forcing us to write more code by enforcing a rule that can be summarized as 'A local variable must be assgined *explicitly* before reading its value.' If you are interested in what...
6
by: Andrea Williams | last post by:
Responding to this link in an old thread: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/ht ml/cpconnetframeworkdesignguidelines.asp According to that naming...
4
by: Dotnetjunky | last post by:
Hi, So far, I've found tons of documents describing recommended coding standards for C#, but not a single piece on VB.NET yet. Anybody here knows such a coding standards guideline on VB.NET...
3
by: ct-86 | last post by:
http://www.cdbook.cn/book.asp?id=2393 Organizational and Policy Issues 1 0. Don't sweat the small stuff. (Or: Know what not to standardize.) 2 1. Compile cleanly at high warning levels. 4 2....
7
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...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.