Entangling Type changes

Would it be reasonable to mirror/entangle what a user types when changing a Type over an equals sign?

Example:

Starting from here:
List<IOrderWarehouseExtended> orderWarehousesToInsert = new List<IOrderWarehouseExtended>();

If I decide to change the type like this:
From
List<IOrderWarehouseExtended>
To:
List<IOrderWarehouse>

The result will be this:
List<IOrderWarehouse|> orderWarehousesToInsert = new List<IOrderWarehouseExtended>();

Note:  |  represents the cursor.

It would be nice if there was a fast way to do some "quantum entanglement" between the two types so you only have to type changes once.

So, instead you'd get:
List<IOrderWarehouse|> orderWarehousesToInsert = new List<IOrderWarehouse|>();

And you'd only have to type on one side, where the "entangled cursor" takes care of the other side.

This is the same thing that happens with HTML tags now, where you start typing an opening tag, and at the same time the closing tag is automatically filled in.
<asp:Table|></asp:Table>

I know there are rare instances where we'd want the types to be different, but probably RARELY over "= new TYPE".

This would be a small time saver that could get daily use.

0
4 comments

For local variables, "var" will solve this:

var orderWarehousesToInsert = new List<IOrderWarehouseExtended>();

0

'var' is often abused.  The argument that it is DRY is over-stated.  The code is sometimes less readable.

foreach (var stuff in randomEnumerableClass)
{
     // what type is stuff?
     // When writing new code, you might not care because it either has what you want or it doesn't.
     // But if you're reading through/debugging quickly, it isn't so easy to read and figure out what type you're working with.
     // And I don't believe in the answer "pick up your mouse and hover over it," nor "go to the type definition".
     // How about "just don't use var when you know the type".
}

With intellisense, it sometimes requires typing MORE characters, despite what some may suggest.

It also makes searching for strings that contain types far less accurate because it can't pickup non-specific types (e.g. search for "List<IOrder> orders" vs "var orders" vs "orders").

'var' is a "loss of information" on the declaration statement.  It should be used only when necessary.

0

But in the case of:

ThisIsAVeryLongTypeName something = new ThisIsAVeryLongTypeName(...);

you don't lose any information by changing it to:

var something = new ThisIsAVeryLongTypeName(...);


Whilst I agree that it can be abused, as your example demonstrates, this instance is a perfectly valid use of "var".

0

cryptc wrote:

foreach (var stuff in randomEnumerableClass)
{
     // what type is stuff?
     // When writing new code, you might not care because it either has what you want or it doesn't.
     // But if you're reading through/debugging quickly, it isn't so easy to read and figure out what type you're working with.
     // And I don't believe in the answer "pick up your mouse and hover over it," nor "go to the type definition".
     // How about "just don't use var when you know the type".
}

The above code is a good example of a bad naming issue, which is a very important issue in code readability. I would argue that anytime var makes code difficult to read it is because of bad naming.

A good version of your code above would be for example:

foreach (var customer in customers)
{
}

Anytime you need to check the variable declaration to understand what a variable represents you should consider if the naming could be improved.

0

Please sign in to leave a comment.