Re: Opinion on coding style.



"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.
.



Relevant Pages

  • Re: Problem with linker
    ... but to have actually written a default constructor. ... such as overloading on int and pointer types. ... conversion of 0 to CString requires a user-defined conversion, ... acceleration operator *(distance d, time_squared t2); ...
    (microsoft.public.vc.mfc)
  • FAQ Suggestions
    ... It can only be applied to reference type variables converting to ... The .NET runtime can't guarantee that parameterless constructors will be ... performing by not having to call constructor code. ... number like casting an int to short) are always explicit. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Working with strings in c++
    ... int i; ... will create it if the syntax is changed to the round brackets. ... you may know about the word 'explicit' used in constructor ... declarations - to stop the conversions (single-parameter constructors will ...
    (microsoft.public.vc.language)
  • Re: Languages for embedded
    ... calling constructors of the structure's members. ... If I want to know whether xyz had a constructor, ... On the other hand, if I have a C struct xyz, and the API provides a ... If function ftakes an int by value, it can't modify any int value ...
    (comp.arch.embedded)
  • Re: How to escape the Ocamls superfluous parentheses and type declarations?
    ... > The constructor Mycons expects 2 argument, ... constructor applied to zero or more arguments. ... >> Because you haven't declared the union of char and int. ...
    (comp.lang.ml)