?

Log in

No account? Create an account

Previous Entry | Next Entry

WTF-coding...

I would like to use the opportunity to start something that might turn into a small series. I like to call it "WTF Coding". Since I'm "native" to the .NET world, it might also become "WTF# coding" at some time, but for now I'm keeping it open.

What's it about? Simple: WTF. What-The-F***!? As it "WTF were they smoking when they came up with that?"

Let me present you: Issue 1, the "collection initializer improvement in C#"


A newsletter recently announced a blog posting that struck me as interesting: a new way of writing collection initializers in C# 6.0, since the old one was sooooo bad (reference here, blog, I'm quoting the version of April 14th 2015 in case it's gone and I have it on file)

The blog says: "...gives you a new syntax that saves a few keystrokes but, more importantly, makes the resulting code easier to read by eliminating some curly braces and leveraging the equals sign." - OK... let's compare the two versions:

Old version


Dictionary<string, Customer> cList = new Dictionary<string, Customer>()
{
  {"A123", new Customer("A123")},
  {"B246", new Customer("B246")}
};


New version


Dictionary<string, Customer> cList = new Dictionary<string, Customer>()
{
  ["A123"] = new Customer("A123"),
  ["B246"] = new Customer("B246")
};


OK... so... how is that saving me keystrokes??? Let's dig deeper, just so you know what I mean. Cutting out the code that is 1:1 the same it leaves:

  {"A123", new Customer("A123")},
  {"B246", new Customer("B246")}


vs.

  ["A123"] = new Customer("A123"),
  ["B246"] = new Customer("B246")


And then, only comparing one of these to the new version directly and on top of each other:

  {"A123", new Customer("A123")},
  ["A123"] = new Customer("A123"),


Whoops... the new version is even longer by one character. Granted it's a whitespace that would be cosmetics but still: the number of functional characters is EXACTLY the same as before.

The new vesion might be better to read to newcomers as it more closely resembles the object initializers, a comparison that the blog post never even did, but overall I say it's more a question of taste than actual hard facts of "what is better".

What would be more interesting to me: does the new version also call a method "Add" on the initialized object or does it actually use the indexer? That is tech-info that I'd expect in a programmer's blog because that could break code. And if the new version calls "Add" to be compatible... it's wonky and misleading. So: Who came up with that change and when will that person be potty trained? Because it's childish changes like these that make our lives harder than necessary...

Comments

( 1 comment — Leave a comment )
c_eagle
Apr. 15th, 2015 06:32 am (UTC)
raebnc hehe!
( 1 comment — Leave a comment )

Latest Month

September 2018
S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829
30      

Tags

Page Summary

Powered by LiveJournal.com
Designed by Katy Towell