Tuesday, June 10, 2008

The Resharper cult members already know this, but for those who haven't joined yet, version 4.0 released today with VS 2008 support -- huzzah,  huzzah.  No longer able to resist the chanting and promises of eternal coolness I donned my robe and installed my free copy.

I clearly should have joined sooner.  Resharper has already changed my life.  First it pointed that I had redundant overrides  in the control I was working on, which I had really meant to delete.

Then it reminded me about the new implicit type declaration keyword var, so this...

XmlDocument SomeDoc = new XmlDocument();

becomes...

var SomeDoc = new XmlDocument();

Granted, that's not too exciting, but if your type declaration is something like...

Dictionary<SomeStrangeType,ANamespace.AnotherLongType> SomeDictionary = new Dictionary<SomeStrangeType,ANamespace.AnotherLongType>();

with var it becomes...

var SomeDictionary = new Dictionary<SomeStrangeType,ANamespace.AnotherLongType>();

Then Resharper pointed out something I didn't realize was available in C#, the object intializer?? VB.NET has long had something similar with the With statement (now with object initializer goodness too).  What's nice about this is that it saves repeating the instance name in front of the properties.  So this...

var MenuBinding = new MenuItemBinding();
MenuBinding.DataMember = MenuItemElementName;
MenuBinding.TextField = DisplayTextAttribute;
MenuBinding.NavigateUrlField = NavigationUrlAttribute;
MenuBinding.Depth = Depth;

becomes...

var MenuBinding = new MenuItemBinding
  {
     DataMember = MenuItemElementName,
     TextField = DisplayTextAttribute,
     NavigateUrlField = NavigationUrlAttribute,
     Depth = Depth
  };

I was staring at this new construct when I realized that -- it shouldn't work. The project I was working on was a Framework 2.0 project and these things were in 3.0 syntax.  But the darn thing compiles and works.  Not even a single warning.  WTF?  It turns out that since 3.0 and 3.5 are based on 2.0, these are simply compiler tricks -- there is nothing fundamentally different about the types.  Here's a blog post that explores in more detail what is happening under the covers.

Not bad for 15 minutes of tooling around.  Guess I am an official member. Where's the Koolaid?

.NET | 2.0 | 3.0 | 3.5 | Resharper
Tuesday, June 10, 2008 10:24:01 PM (Eastern Standard Time, UTC-05:00)   #     Comments [1]  | 
Thursday, June 05, 2008

Every month or so, someone posts a question on one of the .NET forums I frequent asking if such and such will work, or if you can do so and so. The post will detail the background of the issue, including theoretical approaches, possible drawbacks, imaginary contingencies and tangential concepts.  Invariably the poster wants to know the "proper way" to code something, and yet 6 paragraphs later hasn't shown what he or she has already attempted.

Why?

Because the poster hasn't written any code yet

Philosophical development discussions can be fun. Reviewing fundamental design issues, or exploring the possibilities of a new technology or entering a new problem space beg for "what if" questions. It's good to have an idea where to go, a vague notion how to get there and to find out how others attempted the journey.   Those are fun questions to answer.

Another excellent time to ask "what if" questions is when facing an irrevocable upgrade or configuration change.  When a wrong step can wreak havoc it wise to ask for advice. That's what a forum is for -- to get pointed in the right direction or pushed back on course or to be told to hurry back to shore.

No, what makes a coding "what if" question a total waste of time and bandwidth is when it asks how to write a relatively small amount of code. The post itself is longer than the most convoluted possible solution. To put it programmatically...

if(Post.Length > Code_Needed_To_See_If_It_Works.Length)
    WasteOfTimeAndBandwidth();

In other words, if the poster had actually tried to code one of the carefully penned theoretical approaches, he or she would have ended up typing a lot less and would have discovered the solution without a trip to forum land. 

Some examples (and I wish I were making these up):

  • Is it possible to set SomeObject.SomeProperty = SomeValue?
  • Can I put this control inside this other control?
  • How long will SomeObject.SomeMethod() take to run?

Programming is a wonderfully empirical undertaking. With IDEs (Integrated Development Environments such as Visual Studio) it is easy to create code and test it.  At the level of of a function or even a web page or windows form, there is no need for thought experiments or theoretical ponderings -- the code either does what it is supposed to or it doesn't.  There is no need to write about it -- just write it.  If it doesn't work, then you can post a question that is based on something real.

Unless you are doing something silly like working on a production system, the cost for trying something out is minimal.  In the worst cases, bad code throws an error or just doesn't work.  Things don't explode, no one dies.  With source code/version control (which everyone should get into the habit of using), it is trivial to roll back to a previous working version. 

So please, for your sake and Pete's, try it first.  See what happens.  You'll save some time and might be pleasantly surprised.

Thursday, June 05, 2008 7:59:09 PM (Eastern Standard Time, UTC-05:00)   #     Comments [0]  | 
Thursday, May 29, 2008

Received a surprised IM this morning from Jeff Schoolcraft, Code Camp Organizer Extraordinaire and sometime blogger.   He was struck dumb by the fact that I  actually used the online editor to pen my blogs.  He tried very hard not to question both my sanity and intelligence when I told him that the #2 pencil was my first choice but it only updated my monitor.

He patiently explained to me that there was a pretty nifty desktop tool available and it was free.  He even sent me a link to download it. 

So I installed Windows Live Writer and am taking it for a spin. So far, so good. Much more space to work with, a nice clean interface and no worries that my connection is going to die or my blog app is going to recycle while I am writing an overlong post. 

If you are reading this, it means that it posted successfully.

Thursday, May 29, 2008 8:31:20 PM (Eastern Standard Time, UTC-05:00)   #     Comments [2]  | 
Wednesday, May 28, 2008

I hate upgrades.  I usually put them off until:

  1. Something (someone) puts a gun to my head
  2. There is a compelling feature available
  3. I'm feeling lucky

Case 1 is the usual situation.  When things won't work any more, I'll bite the bullet.  If things are working, I have a tendency to leave them alone because vast experience has taught me that the Law of Unintended Consequences usually makes itself known whenever something gets upgraded.  I don't care how many versions behind it is.  I don't like to blow half a day getting back to where I was before the upgrade.

 

Case 2 actually popped up twice in the last month.  I moved to Vista finally because I wanted to play with the new PeerToPeer.Collaboration namespace in 3.5.  It hasn't been too horrible, (except for the file search function which is even more obtuse than it was in XP -- which I thought was an impossibility).  It was also just a move to a fresh machine.  I also upgraded my SecretServer install, because I wanted to take advantage of the ActiveDirectory feature.  I was only 3 major versions, 2 minor versions and 30 revisions behind, but with some help from the good support folks at Thycotic I was able to get it current without too much hassle.

 

Case 3 is something I should avoid.  I should know better, but it happened while I fooling around with this blog last week.  I realized that the blog software (dasBlog) was many versions behind and I figured the last upgrade hadn't been too bad.  There were also a couple quirks I figured would be handled by the new version.  So  I downloaded all the new stuff, merged my web.config file, made the few other changes and pushed everything up.  Worked, mostly.  I couldn't edit or enter new entries.  The FreeTextBox component was displaying a "was not installed correctly" error.  Hours of googling, typing, begging and swearing later still no luck.

 

So tonight I decided it was time to move on.  dasBlog supports other editors, and John Forsythe has created a lovely little addin for the TinyMCE rich text editor.  I downloaded, uploaded, recycled the app, changed the configuration and behold my dasBlog install once again is back where it was a week ago -- I have a text editor to create entries.

 

On the positive side, TinyMCE is has more features and the new dasBlog goodies are nice, so I guess it was a worthwhile exercise.  I'm just posting this to remind myself that I should "never feel lucky" when considering an upgrade.

 

UPDATE:  Just discovered Comments weren't working because I had the Resolve IP Setting turned on. Looks good now. Not that I get lots of comments, but I would like to provide the outlet.

 

 

Wednesday, May 28, 2008 9:22:05 PM (Eastern Standard Time, UTC-05:00)   #     Comments [0]  | 
Monday, May 19, 2008
While crawling around in VS 2008 to work on the P2P presentation for RockNUG and the NOVA Code Camp, I stumbled upon a lovely little feature under Intellisense on the Edit menu called Organize Usings.  A simple click can remove unused using statements, sort the statements or do both.  Cleans up code faster than a life style diva on a nicotine binge.

Visual Studio has default templates for all project items and they frequently includes using statements for namespaces, that well, never get used.  The class template, for example really, really wants you to use the LINQ and the System.Text namespaces. If you haven't gotten around to modifying the default templates, you'll have lots of unneeded using statements cluttering up your code.  The Organize Usings feature can help save other developers (or the future you) from wondering, "Where the heck did he use LINQ in this class?".

And just so you don't strain yourself, it is only available for C#.


Monday, May 19, 2008 11:52:34 AM (Eastern Standard Time, UTC-05:00)   #     Comments [0]  | 

Theme design by Dean Fiala

Pick a theme: