On Thu, Aug 29, 2013 at 3:16 AM, David Jeske <[email protected]> wrote:
> On Wed, Aug 28, 2013 at 12:08 PM, Jonathan S. Shapiro <[email protected]>wrote: > >> On Wed, Aug 28, 2013 at 3:39 AM, Bennie Kloosteman <[email protected]>wrote: >> >>> +1 for typed typedefs .. too many ints in C it would be very usefull >>> even in business apps to have say typedef int CustomerKey ; will stop a >>> lot of bugs when you use the wrong foreign key in CRUD code. >>> >> >> From a language design perspective, typedefs are an interesting issue. >> The question is: does a typedef introduce a new, distinct type? If so, then >> we're really talking about NewType, and all of the operators on the >> underlying type do not work on the new type (unless suitably extended). The >> type rules for that extension aren't always simple. >> > > From your comments I can see some of why they omitted it. > > The cases I'm thinking of involve defining a new distinct type.. because I > specifically want to prevent any implicit casts or operations on it. (Such > as a "user-id" which happens to be an int, but for which increment a really > bad thing to do) > > That said, these cases are handled easily enough by making a "struct > UserID { int _id; }" which hides the details and AFAIK is just as efficient > as passing around the original int. > I tried that 2 projects ago but its a lot more verbose ( and it is very common) and i eventually pulled .. eg obj.ID = new UserID ( db.Id) ; everywhere ... and you do need to cast it to int sometimes for loops in the end it wasnt worth it , as it gave trouble with EF and WCF.. despite those bugs being truly annoying ..
_______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
