| Profilo di StevenDevelopmentalBlogElenchi | Guida |
DevelopmentalFlinging crap at other monkeys in the development forest |
14 ottobre Visual Studio Tooling, Resharper, and the Developer Circle of LifeVisual Studio is pretty good. 2008 came a long way and I really enjoyed jumping to it with some production apps with the beta 2 release. But I also had those same thoughts about VS2005, and to be honest, VS2003 was a god-send after VS2002. I guess the point is that when something is new, such as an IDE or a language, you start to learn all the little tricks, and they’re all great. Productivity is enhanced, you discover new ways of doing things, and you hit this little peak for the year where you really enjoy what you do. Invariably that peak levels off as the new and interesting becomes the common place. You start looking forward to the NEXT release and the productivity gains it will bring. I call this the ‘Developer Circle of Life’. We are invariably bound to it and cannot escape. Whatever we have now, we want it faster, with new features, and some new technologies to boot. Its those middle months that suck the most, the longing, wishing you were using V.Next on your current project, and that everything is so hard and slow. So what can you do until that beta 2 ‘go live’ license to improve your developer experience? Where can you get more productivity gains? Well there’s a suite of plugins and tools you can install that work integrated or in parallel with Visual Studio out there. One of the most common is Resharper, and I’d like to share some of its qualities with you. Resharper Ok so I used to be that guy that wanted everything vanilla. Default options all the way. It allowed me to move between client sites easily and be completely operational immediately. When I hit a computer with Resharper, I’d immediately know because VS would start closing my brackets and quotations for me automatically; that was the hallmark of R#, and I would immediately disable it. But in the last year I’ve been really focusing on doing WPF work (I’m even launching a new WPF blog – coming soon) and found the VS2008 XAML editor to be loathsome. I mean, it just seems to be notepad with syntax highlighting and a little bit of intellisense – that’s it. Others around me were using R# so I bit the bullet and installed the trial. Ok I got used to the closing brackets/quotation thing quickly. Even VS will close XML elements and quoted attributes for you. I got over that issue pretty quick and to be honest, I could only find two other griefs with it (I’ll mention them below) – otherwise there wasn’t much else to complain about. But the benefits? Wow. There’s so many things that you just keep discovering all the time, but there is definitely a few standouts that I use all the time. Here’s 5 of my favourites: 1. XML Namespacing In XAML editor, you get a lot of improvements around refactoring but the feature I enjoy the most is the auto-discovery of namespaces. Lets say you have a control that you created and you want to declare it in XAML. In plain old VS (hereto referred to as POVS) you first have to find your namespace with the intellisense in the Window element at the top of your editor, declare the namespace prefix, then come back down to where you want your control, and instantiate it. With R#, you can just declare <myControls:SpecialControl /> and press the R# magic key combo of ALT+ENTER and walla! It discovers where SpecialControl is within your application and inserts the namespace automatically, and even calls it ‘myControls’ for you. This is a very quick operation that makes it easy to get your XAML bashed out faster, but also for the absent minded like me, means I don’t have to remember the namespace for my controls! 2. Convert Property to Backing Fields You’re probably familiar with code snippets in POVS. In VS2005 I used the ‘prop’ snippet all the time; this created a public property with a private field backing it. However when VS2008 came out, they replaced this snippet with a new one that created an ‘automatic property’ instead. Automatic properties are extremely short and concise already, so its beyond me why the VS team would not leave the original prop declaration as is. R# to the rescue! You can quickly create an automatic property, and then using ALT-ENTER convert it to a property with a backing field. Given I do so much WPF (and love the MVVM pattern), I tend to need properties with backing fields all the time (for my little friend INotifyPropertyChanged). I love this feature. Oh, and it converts back to an automatic property as well if you don’t like it. 3. Go To Implementation Or CTRL-F12. I also use a lot of IOC which means interfaces hiding my implementations a lot of the time. Also its a services world, and WCF patterns see interfaces for contracts as well. POVS had the F12 ability – go to definition, which bounced your cursor to wherever the item you clicked on was declared. BUT if this was an interface, well you got dumped at the interface. Fear not! R# lets you go to the actual implementation of your interface instead. You can actually count the time this saves in a day in terms of minutes I reckon. Oh and if more than one class implements the interface, it gives you a list to choose from of course! 4. CTRL-T I’m sure this has a proper name, but I just call it “THE GREEN BUTTON” since it is such an enabler. Basically, need to know where something is? CTRL-T will find it. Its the enhanced search aspect of R# but its killer feature is that you can type in the letters of your class based on its pascal case definition, and it will be returned as a search result. I know that crappy description really does describe it correctly, so I’ll use an example. Lets say you have a class called ‘VolumeIntegrationProvider’ (which I do) – you can press CTRL-T and type “VIP” and it will find that class! So you see what I mean about the pascal case? 5. Initialise Field From Parameter Another thing about IOC is that you inject a lot of classes into your constructors. Its then a manual task to create a private field within your class to store that parameter, and of course the code in the constructor to assign it:
This really is time consuming, but with R#, you only need to declare the constructor parameter and ALT-ENTER takes care of the rest! This is another one of those features that saves you minutes a day (hmm, there seems to be a few of them!). Dislikes The first is that sometimes the R# intellisense/autocompletion is not fast enough for me. Somehow I just know that a class name is unique after the first 4 characters (perhaps I’ve just typed it 3 times before) and so I’ll bash out the keys really quickly. For example, imagine I wanted to type this:
So I’d type the following characters: (CTRL-SPACE is auto-completion, so it should fill in the remainding characters for that class/interface) The only other dislike I have is that R# leaves your VS in a bit of a mess when you uninstall it, the worst part being that your intellisense and other features might actually be disabled. However this is pretty rare and really isn’t such a big deal. All I can say is that you have to give R# a try. Install the trial and see how you go. I bet that after the trial expires you’ll be forking out the measley few USD it takes to get it going again. =) Other Tools As a user of TFS, I quite like the TFS Power Tools. This provides some must-have extensions to the command line configuration of TFS, as well as shell integration for your source control. I also usually install the VS2008 Power Tools which gives you some useful functions like being able to copy-paste your assembly references. I used to think RockScroll was cool, but lately I think it just steals too much screen real-estate and it doesn’t deal with collapsed code very well. Its not very 3rd party but when it comes to dealing with the designer aspect of XAML (building UI that looks good) I actually prefer to use Expression Blend, and I’ve even taken the leap into Expression Design lately to build some of my assets and icons. I’m really enjoying those products but am also suffering some of those random crashes people have been complaining about. Even still, Blend 3 is awesome and sometimes I just sit in there and bash out ideas for fun. 24 maggio WPF ListViewItem – Stretch to take the full widthI’m doing a bit of WPF at the moment for a company in Sydney and also working on a WPF project in my spare time. Tonight I came across this issue and thought I’d document the simple solution in case I run into it again in the future. I have a ListView that takes up the full width of my window. I’ve edited the ListViewItem template to put a border around the items. The code looked like this:
The problem was that the border was only as big as the content inside it, even though the listview was the width of the window. What I wanted was to show an equal sized border for each item despite the size of the content inside. The solution in the end was really quite simple: to add the HorizontalContentAlignment="Stretch" attribute to the ListView declaration. Easy! 24 marzo Ada Lovelace Day 2009 – Catherine Eibner
From: http://findingada.com/ I only heard about this today to be honest. Perhaps that makes me part of the problem, I’m not sure. I don’t want to go into the gory details of equality in the workplace. What I do want to say is that there is definitely a clear lack of female role models in the industry. That’s why this pledge is so important: there are a lot of women out there doing excellent things in the community and that’s why I’m writing this post: my pledge to talk about a woman in the industry that I admire: Catherine Eibner. Catherine is one of the most community focused people I have ever met, male or female. A single mother who also started her own company, while kicking off the Sydney CRM user group, a podcaster and geek girl, a regular attendee of Sydney user groups in general and frequent speaker herself, Australia wide. Catherine was awarded the MVP status from Microsoft, only to have it recalled when she became a Microsoft full-time employee for the DPE group: just two more indicators of how much the community appreciates her involvement. Whenever I am in Sydney and looking for the local community events, Catherine is always there to show me the way! Thankyou Catherine, and keep up your good work. The world’s a better place for having you. You can find Catherine here: I encourage all of you to post about a female in the tech industry you admire and why. If you don’t know one, at least spend the time to think about why that might be. 27 febbraio A Fractal Generator in C# for .Net 3.5Fractals are interesting creatures. They are the visual representation of complex mathematical functions. Writing a fractal generator was something I always wanted to do, and recently found the time. My initial motivation was to discover if fractals were able to be generated using parallel processing, which they most certainly are, so I set off with a clear goal in mind: a multi-threaded fractal generator. This post is the result of that work. I’ll start by linking to Snagy.Fractals.zip. This zip file contains 3 projects: a core fractal library, a console app, and a WPF app. The 2 apps use the fractal library to generate fractals in both single and multi-threaded scenarios. Mandelbrot One of the most common functions is the set of numbers defined by Benoit Mandelbrot in the Mandelbrot Set. This function relates to the concept of Complex Numbers and the plotting of co-ordinates on the Complex Plane. This particular branch of mathematics is complex and I’m not going to talk about it here (mostly because I still don’t know how it all works!). Suffice to say that the fractals generated from the Mandelbrot set are the most common and well documented. I selected the Mandelbrot algorithm for my fractal generator. Existing Generators Before I started this work I thought it more worth while to use an existing generator if one was available. There were some, but one of the key problems I discovered was that they were badly written and difficult to understand. Having said that, some might find the same problems with mine, and if that is the case, please let me know! Another problem I discovered was that some of these generators were written by mathematicians. This meant that the language and terminology used presumed an understanding of the maths (which I only have part of) and that made the code difficult to read. So my goal was to lose the jargon and stick to programming terms. Snagy.Fractals After spending some time on the mathematics, I followed some online guides to programming the fractal, as well as munging in some concepts from some example applications I found. Snagy.Fractals namespace is the end result, and here is an overview of the important classes within. FractalSettings – Contains just properties representing the required settings for a fractal How It Works This won’t be a math lecture so we’ll just cover some simple concepts. First, fractals are generated on a pixel by pixel basis. This makes them excellent candidates for parallelism: 2 pixels can be generated at the same time because there is no relationship between pixels. The work we do is broken up into ‘Strips’. Imagine we want a fractal that is 900x900 pixels in size. We can break this up into 200x900 strips, with the 5th strip only being 100x900 pixels. These strips allow us to break our work up into logical units. These strips are what get distributed amongst multiple threads. Scale Think about a 900x900 fractal image again. If we just run the standard co-ordinates through the functions (x = 1 to 900, y = 1 to 900) then the Mandelbrot fractal is quite small (a couple pixels). This doesn’t let us see anything interesting! So we need to simulate “zoom”. To do this we take a scale modifier and multiple the numbers against that. The best top level zoom starts at scale 0.01. This means we are supplying the algorithm with the numbers x = 0.01 to 9.00 and y = 0.01 to 9.00. But the most amazing art occurs much deeper still! Offsets Because Mandelbrot is based on quadratic equations (eg. y = ax^2 + bx + c ) then everything happens around the ‘Origin’. This means we need to introduce negative X and Y values, with the centre of our image being co-ordinate 0:0. To achieve this we need to offset calculations based on how big our image is (Height/2, Width/2) and also based on our zoom level. This moves the fractal to the centre of our screen (in this case, the centre of our bitmap that we are creating). Centre When we start zooming in, we don’t actually want to look at the exact centre of the image. If you look at pictures of Mandelbrot, you’ll see the very centre is empty! Nothing exciting happening there, so we actually need to zoom in at specific x/y locations. These locations have to take into account the offsets mentioned above, and of course the scale factor. Iterations The colour of any pixel is decided by the number of iterations of the Mandelbrot function that can occur. What we mean by this is that the function : f(n) can be called on itself recursively “i” number of times while satisfying the core equation (see complex quadratic equations for details). So if the deepest we can go at a particular point is f(f(f(f(f(n))))) then this means we reached 5 iterations. Forget the math though; the MandelbrotBase class will calculate the iteration for you based on the x/y co-ordinate. However this x/y co-ordinate is actually relative to the centre mentioned above, so is in fact quite a small number pair, rather than the actual X/Y of the bitmap we are calculating. To Infinity – And Beyond! If you zoom in on an ‘edge’ of a fractal, you will see that you can keep zooming.. forever and ever. Well this isn’t technically true: the app is hardcoded to 1000 iterations max, which means that there are defined edges between the fractal and space. But theoretically.. .there is no such edge! Snagy.Fractals.Console All the fractal work is done in the class library, so its really very easy to consume and use in your own application. The console application is a perfect example of this. All the code in this app is around getting command line parameters and turning them into a FractalSettings instance, and then saving the resulting fractal image. Use this application as a guide to using the fractal classes. Snagy.Fractals.WPF This is a simple harness that will show you the fractal based on your settings on the left. Enter a scale and centre point, then click create. I did attempt to put some navigation into it, but its very flaky. There is this tendency for UI events to “queue” while the fractal is being generated. As a result the experience is rather poor, but the framework is there if someone wants to work on it and make it work better. Summary This is open to anyone to use. Since its unusual to embed a fractal generator in a commercial app, I’m not too concerned about what you use it for. But if you do republish an app with my code, I’d appreciate a mention and a link through. =) Thanks I have to thank Buddhike for his help around the threading. Bud helped me get the locking sorted along with the right threading classes. So thanks Bud! I’d also like to thank Paul Stovell for making me ditch my original Win Forms harness and use WPF instead, which resulted in more work to convert bitmaps, recreate my flashy UX, and fight against dispatchers. The WPF navigation (pan and zoom) was based on this article on the topic. 30 gennaio TFS Shared Resources in MeshI was lucky enough to get an early invite to Live Mesh (I was working at Microsoft at the time). Back then it seemed more like a concept than an implementation there were that many flaws. I tried it for a while, but fell back to folder share and other technologies. Mesh got uninstalled. To be honest, I hadn’t looked at Mesh since that time. Until today. It all started as the result of a TFS engagement I had just finished consulting on down at the Gold Coast. I decided to build a TFS Resource Pack for all the common files you typically need on a TFS engagement. For example, VSTS SP1, TFS 08 SP1, SQL Server 2005 SP1, TFS sync tool, TFS migration tool, Branching Guidance document, TF Power Tools, Team System Web Access SP1, the list goes on! Usually I just download these tools on site at the client but I figured it would be easier to have a portable HDD with all these items (I don’t own such a HDD but was willing to buy one). I ran the list of items in my pack past some internal Readify guys and one of the responses was: ‘Why not mesh?’ Why not indeed! There’s 5Gb worth of space in the cloud that I can use so why not put all these resources in one place where I can always get them? Maybe not the 1Gb ISO’s for service packs, but certainly the rest can go there. So as of today, there is a folder in mesh with all this information, and I plan on continuing to add to it over time. Want access? All you need is a Live Mesh account and send me your email: I’ll invite you to the folder so you can get the files as well (read access only if I don’t know you). And then just email me if you think I should add any particular file or application.
|
|
|||||||||||||
|
|