Re: Opinion on coding style.
- From: Tim Roberts <timr@xxxxxxxxx>
- Date: Sat, 22 Dec 2007 19:03:46 -0800
"Leo V" <LeoV@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
So, to use int with the same syntax you would use if you were constructing
an class object using a specific constructor, to me seem like poor style.
int iVal;
DWORD dwVal = 40;
iVal = int(iVal); // Poor and unclear programming style
The above is the same syntax you might use if you were calling the DWORD
constructor on an "int" object. Whereas, in the spirit of what the
developer is really attempting to cast an int to a DWORD, it seems
counter-intuitive to code it as shown.
I don't understand why you want to draw such a huge distinction between
compiler-supplied types and user-defined types. It just gets in the way.
In my opinion, it's a better "mental model" to think of them as two
individuals of the same species.
What is the matter with thinking of "int(dwVal)" as a constructor for class
"int" that happens to accept an unsigned int? The net result of that
operation is exactly the same as the C concept of a cast.
That's my argument. When the dev is casting, why code it like a class
object construction?
Because they are exactly the same operation. The fact that the compiler is
able to optimize the "int" constructor shouldn't affect the mental model.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- References:
- Opinion on coding style.
- From: Leo V
- Re: Opinion on coding style.
- From: Tim Roberts
- Re: Opinion on coding style.
- From: Leo V
- Opinion on coding style.
- Prev by Date: Re: is such exception handling approach good?
- Next by Date: Re: is such exception handling approach good?
- Previous by thread: Re: Opinion on coding style.
- Next by thread: Re: Opinion on coding style.
- Index(es):
Relevant Pages
|