Archive for the ‘tools’ Category

Windsor, for real

Tuesday, September 16th, 2008

So, I finally got an implementation of an IoC Container (Castle Windsor) set up and being used in a production environment…. Based on the whole settings things up for mocking, it became very clear why they were needed!

On a current project, I’d set up and gone though writing tests as I went along.  It was a colleague’s task to write a bunch of integration tests.  (The question of how many full, top-to-bottom integration tests are actually needed is an interesting, but different question… regardless, they are well understood and trusted)  It turns out that all of these interfaces and the tons of newing up required for the dependency injection got to be pretty painful, and what’s worse, confusing and unclear.  Also, as I was refining things, I continued to refactor what was there, so the constructor signatures were changing… messing up AL those integration tests.  I think if he were less nice, he would have said “WHY do you have to make this so confusing??”

Exactly the situation IoC containers were made for.  And I think I got it all set up in about an hour, from download to finish!  Which is a few hours less than I’d expected.  I couldn’t quite get my create down to a single line a) because I was dealing with VB.Net, an irritatingly verbose, hard-to-scan language, but more importantly b) I had to pass in a configured object in to one of my objects, and then pass THAT on to the constructor of object I was really trying to get.  Previously, this chain was hidden among the plethora of newed-up stuff.  Once the container was in place, all I had were these special items, right after each other-this chain of dependencies on the configured object was very clear… the cluttering vanilla dependencies were out of sight.  I consider this a huge, and unexpected benefit.  If I need to change my constructors to break things up more (I have a few places in mind)  then I won’t break these complex integration tests.  My mocked out tests, sure… but they are each restricted in what they touch anyway, so the trouble there is much less.

I know, these were tests, and people often don’t use containers for tests.  However, because of their being integration tests, it felt appropriate.

An interesting point is that this is all going to end up being accessed through a single webservice, so the “live” newing up is only going to be in one place-so less *need* of a container for live.  This is just as well, because another team is doing the maintenance, and this way the unfamiliar stuff isn’t in actual live stuff that’ll could freak them out if something happens with it on live.  Same reason we went with VB…  Anyway, even if we don’t use it on “live” code, Windsor will still save us time.

Of note is really how all these things sort of come together as a package-  DI, mocking, IoC.  You want mocking, you do Dependency Injection, probably Constructor Injection.  You do much of that, and you’ll find yourself wanting something to magic everything up… thus your Inversion of Control Container.  I’d looked at containers a few months back (I’d heard them mentioned a LOT, and thought I should look into them), but I didn’t quite get a grasp of when or why you’d ever use them in practice.  I changed how I worked, and it became obvious.

Bazaar gets a GUI

Friday, April 18th, 2008

Looks like this is still in the early stages, but Bazaar, one of the new generation of distributed source control systems is getting a gui: http://bazaar-vcs.org/TortoiseBzr  Yeah, I know, “guis are for wusses” that’s fine and all, but when you’re checking in some files and not others, the checkboxes are kinda nice. 🙂 Not to mention the far more important reason:  If you’re on a project with Front End Developers (your slicer/HTML coder people, photoshoppers, etc) they may fight you with a vengance if you require them to use arcane command-line stuff to work on a site.   So, that’s limited choices for such projects to CVS, SVN, and the like.  It’ll be nice to have Bazaar as an option as well!

SharpDevelop Initial Review

Sunday, March 16th, 2008

As I mentioned in this post, I was interested in SharpDevelop, a free .net editor. I’ve been writing some with it a bit at home yesterday and today, and it strikes me as adequate for basic messing around at home on projects. Two months ago, I might have said it was super and all you’d need, but I’ve since experienced ReSharper, and I miss it at home! SharpDevelop does have syntax highlighting and Intellisense, though unlike Resharper, it does require a compile to pick up anything new, and doesn’t have marking of unused code, which has gotten me in the positively addictive habit of search-and-destroying.  It does have the ever-useful Go To Definition and Find References feature, as well as NUnit integration, which is nice.

The feel is a little bit homegrown- it’s definitely not the edges-polished look that VS/Resharper has. However, it so far seems extremely lightweight resource-wise, unlike VS/Resharper-when I had that with 1GB at work, my computer was practically useless.  My home computer with 1GB barely seems to notice SharpDevelop.  SharpDevelop  can work with Visual Studio solutions, which is very nice since most code you’ll find on the web is packaged that way.

Current judgment: VS with ReSharper really is fantastic, and is helpful in a thousand tiny ways. However, the combination would cost something like $400. At the office, it’s absolutely worth arguing it out with management to get it bought, and if you’re doing heavy work at home, it’s definitely worth the investment. That’s not everyone though-if you’re just doing small stuff, free stuff, just learning, or $400 is plain out of the question, SharpDevelop isn’t a bad way to go. It’s much, much better than notepad, and though less polished than Microsoft’s Express offerings, SharpDevelop is arguably more full-featured.

Is #Develop any good?

Friday, March 7th, 2008

http://www.icsharpcode.net/OpenSource/SD/ Haven’t looked at it yet, but since ReSharper plus VS staundard is a bit costly for futzing around at home for the soon-to-be-started SharpShop, I think I’ll give this a go.  Review to come in a future post…

Resharper rewrite

Wednesday, February 6th, 2008

OK, so the first ReSharper post was a written statement of resharper joy. However, it’s not the best format for getting me some $$ for ReSharper at work. So, let’s write up an informational document for the people who would make the decisions…

ReSharper is an add-in to Visual Studio that provides Visual Studio with a number of useful features. Overall, they help a developer code cleaner, faster and more efficiently.  ReSharper is produced by JetBrains, the company that also produces IntelliJ, a highly regarded IDE for Java.

Some Key Features

  • Find Usages – this is VERY different from a search. It finds anyplace a class, a class’s method, a property or a variable has been used… if another class has a method of the same name, that method won’t come up-only the ones you want. This is a huge time saver. It’s amazing the amount of time you want to know where something is called so you know if it’s “safe” to change, for instance
  • Related to “Find Usages” is Rename… rename a class at the site of an object declaration, and the class will get changed, the name of the class file, the constructor, all declarations of objects based on that class, and any private variables that seem to have a related name get changed. This is great because any code that’s been around for a while collects artifacts that are misnamed… among other reasons, because something ends up getting repurposed in unexpected ways, or a domain concept becomes better understood. These misnamings were previously a minefield that would inevitably happen. With rename, it’s very easy to give objects the proper name, so the code can become much more intuitive.
  • Highlight unused code. This isn’t really something that a user actively does, it’s one of the many things ReSharper does on its own that helps a developer code better. If a variable or “using” statement is not being used, it colors it gray. Then, unused things can be removed with a quick keystroke. Just another feature at keeping the code clean.
  • If you’re viewing an interface, there’s an option to go to implementors, and it provides a list. Yes, you could do a text search for the interface name, but if you ARE coding with interfaces, this saves time, and is a really intuitive way to navigate.
  • Code completion. If configured correctly, Visual Studio will do code completion, but it requires a code compile for methods to come up. Resharper parses code on-the-fly, so you immediately have classes and methods from other files available as you are working, even if things don’t compile. A little thing, but another timesaver-it saves on typing/guessing errors on your current work even when the code isn’t compiling.
  • It provides better inline method documentation. Again, you could get better documentation on the web, but having it right at your cursor as you type is instant (unlike a web search), and doesn’t require a context switch.
  • It autoparses the ASP.NET aspx files, and makes the content accessible via Intellisense in the codebehind file. Again, you could just spend time flipping back and forth, copying and pasting, but typing in the codebehind and having it pick up the elements in the aspx file helps reduce error (you can intellisense the name out so you KNOW it’s correct) and then you also have the elements’ methods immediately available via Intellisense, so you won’t have to manually type NavigateUrl, savinng type (and avoid possibly mistyping as NavigateURL)
  • Many refactorings are supported, such as “Extract Method” and “Extract Interface”. Refactoring is a way to impove the readability and maintainability of code though safe reogranizations and restructurings. This is something all good developers do as a matter of course, but this tool can help a refactoring happen in a few seconds instead of minutes or even hours. Making refactoring easy is going to make it happen more, which (when done appropriately) is very healthy for a codebase.

Items of note on ReSharper:

  • ReSharper works best on a properly organized Visual Studio project, with classes organized by namespace in folders (this is the recommended way anyway) … but to get best use out of ReSharper on a project that’s legacy and incorrectly set up, you will want to straighten things up.
  • It’s SLOW to open a project. … this is because ReSharper does a pass through of everything for parsing. Granted, things are fine once it does open, but if constantly opening and closing things in VS is your mode of working, You might want to either rethink ReSharper, or your mode of work.
  • It’s a memory hog. This is probably (I’m guessing here) somewhat proportional to the number of classes, since it parses, and holds the definitions in memory so it can do its magic. Anyway, JetBrains says 512 is a bare minimum, and recommends at least 1 gb. I have to say that with my machine set up normally, an ftp program open, and a web browser, I’m going WAY over my 1gb of memory, and am swapping like crazy. I’m guessing here, but looking at my real-world memory usage, I’d say not less than 2gb, and maybe more to be comfortable.
  • The current version is 3.1, but 4.0 for VS 2008 is coming out soon. Anyone who buys 3.1 now gets a free 4.0 upgrade license when it comes out.
  • As this is a plugin for Visual Studio, The developer must have at least Visual Studio Standard (the lowest non-free version, and the cheapest version taking plugins) to use ReSharper.

Cost:

 

  • Single-developer cost $149 for C# only, $199 for C# and VB.net support. They are non-transferrable. The license allows for installation of the software on different computers (at work and/or at home), provided that multiple instances of the software will not be used at the same time.
  • Commercical license is $249 for C# only, $349 for C# and VB support. Commercial licenses are based on a concurrent user model… as many installations as you want, but number of copies legal to be used at the same time limited by the number of licenses purchased. Non-transferable to other companies, but transferable within the organization.

ReSharper = manna from heaven

Friday, February 1st, 2008

This week, after having heard/read many, many times from a variety of developers that ReSharper from JetBrains was essential for any C# developer, I (finally)gave it a go. And after having only worked with it for about three days, I have to say that Resharper just might be the best thing I’ve ever downloaded. Sure, iTunes was fairly cool, and Google earth was nice and all, but the first time I loaded ReSharper up and got things set to use it (more on that later), and it told me what classes/methods were being used, plus it could tell me WHERE (this is very, very different from a text find)… and then, when I used its built in rename function, and it auto-renamed the class, the file name, anywhere that class was used, AND even listed the places it showed up in strings and comments, so those could be gone through separately/manually if desired …. well, that was exhilarating. To think I was no longer bound by the tyranny of my (and others’) old legacy names! That’s one of the things that has always annoyed me about working on an older project. As you get more familiar with a domain you inevitably realize that your original names for things reflected poor understanding, and are in fact misleading… however, you stick with them because of the nightmare it would be to change. Well, no more! (If only you could bottle this kind of glee…)

ReSharper also tells me what is not being used, which is just as important. Of course it’s important to give stuff a quick test after ripping stuff apart, but ReSharper actually encourages better coding. If things are not being used (using statements, variables, etc) it shows them as gray, and you get into a habit of commenting out, or even better, deleting stuff in gray by habit. It’s a simple thing that really helps keep the level of useless cruft down. It also tells you if you can declare variables in a smaller score, keeping things tidy (sometimes I decided against, for the purposes of declaring “starter” values all at the top of a method where they won’t get lost, but sometimes I went along and moved it-which involved just a click)

It even has features like go to implementors of an interface, and if you added things to the interface, you can click to have those methods added, albeit stubbed out with a “Not Implemented” exception… go to interface, or go to inheritors… Just lots of little things that all add up to a more seamless experience.

The initial setup was a fair bit of work, though I really can’t blame that on ReSharper. At work, I mostly support one large site that is several years old, and was really a learning experience for my organization. By the time I came on to the project, it was several years old, and had been through several developers. As a result, it was a hybrid of different approaches, and didn’t quite fit a “usual” .Net setup. To get ReSharper working fully, I had to move a number of directories around, and get the site into a real VS “Project” and “Solution”.. this all took a fair bit of rejiggering and such, but it was definitely worth it.

It’s $200 for the full version that also includes VB support, but I’ve already decided I don’t want to write C# without ReSharper. I’m at a small, mostly non-.net shop, but I hope I can sell my need of this anyway. If not, well, $200 is not too much to have a better working experience…