auto storage class - infer or RAII?

Jim Hewes jhewesNOSPAM at ix.netcom.com
Sun Nov 12 12:12:28 PST 2006


I hope you don't mind a comment from a lurker. :)

I had assumed that there was some more important purpose for type inference, 
such as that it was useful in generics or something. But if it's just to 
avoid having to declare types, I wonder if it's really that important to 
have.

"Walter Bright" <newshound at digitalmars.com> wrote in message 
news:ej6vb3$2s5m$1 at digitaldaemon.com...
>
> What is the type of foo.length? Is it an int? uint? size_t? class Abc? 
> Without type inference, I'd have to go look it up. With type inference, I 
> know I've got the *correct* type for i automatically.
>

However, you don't know what that type is. If you want to know, you need to 
go look it up. This is especially true if you're working on someone else's 
code. I think that's fine if you're working within an IDE that can tell you 
the type. I'm not a fan of Hungarian notation. When working within Visual 
Studio for example, there are multiple ways to find the type of a variable 
easily. You can hover the mouse over it. You can right-click on it and 
select "Go to Declaration". I think this obviates things like Hungarian 
notation. It would help with discovering the types of inferred variables.

But if you're using some editor like vi, then you may find it tedious and 
time-consuming to always search for the types of variables. I would be more 
likely to avoid type inference altogether and simply write the type just for 
the sake of documenting it.

> Now, suppose I change the type of foo.length. I've got to go through and 
> check *every* use of it to get the types of the i's updated. I'll 
> inevitably miss one and thereby have a bug.

I assume if you've made an assignment to the wrong variable type, the 
compiler will catch this (unless there's an implicit cast). At least the 
compiler errors should help you find all occurrences easily. Although, you'd 
still need to go through and manually change the type in each occurrence. I 
just feel that making these kinds of changes to code are more the job of 
development tools. Perhaps the line between language and tools can start to 
get a little blurry; that's another discussion. Anyway, I just wonder if 
there is a strong a case for having type inference at all.

Jim






More information about the Digitalmars-d mailing list