Showing posts with label silverlight. Show all posts
Showing posts with label silverlight. Show all posts

Saturday, January 3, 2009

MIX09 10K Smart Coding Challenge

I entered a Zleek Silverlight application into the MIX09 10K Smart Coding Challenge. Please Vote for my entry by rating it 5 stars!

It is a very "lite" version of Zleek that contains only a single page where you can upload images, manipulate them using drag/rotate/scale, and save your layout. You can't share layouts with other users, but the application will remember your last saved layout.

The idea of the competition is to fit as much functionality in only 10KB of source code. Here's a snippet of what size constraints will make your code look like (note that my actual submission was all on a single line of text):
I should write code like this at work! I'm sure everyone would appreciate how easy to read it is! Anyway, it was fun putting together code completely at odds with my normal coding style. For you geeks out there thinking about entering, here is what I learned from the experience:

  • var is your friend.
  • Use lambdas where possible. The implicitly typed arguments are great for shaving off type names (just like var).
  • LINQ extensions to IEnumerable and IList are great. ForEach and Cast will save you a lot of code especially when combined with lambdas.
  • Use fields over properties. Remember that leaving off the access modifier will mark them private.
  • Question every single framework call you make and whether or not it makes sense to encapsulate it. I ended up taking a bunch of the common ones and creating static methods that wrap the calls.
  • If you have a function that takes multiple parameters of the same type, use an array declaration instead. (e.g. CalcDistance(Point a, Point b) becomes CalcDistance(Point[] p) -- and of course the actual function name should be trimmed to 1-2 characters)
  • XAML vs. Code vs. external image -- In many cases, code is preferred over XAML. The obvious exceptions here is XAML that makes heavy use of Path.Data (code does not accept the shorthand notation, AFAIK). The code for downloading an image using WebClient is fairly small. Definitely worth looking at. Note that downloading remote XAML is frowned upon by the contest moderators and should not be used.
  • Consider subclassing commonly-used non-sealed framework classes. Unfortunately, all of the common long-named classes I was using were sealed, so I couldn't do this... but I wanted to try and subclass framework classes that I used a lot so that I wouldn't waste space with the type name that often.
  • Place all of your CODE in a single file so that you only have to take up space for "using" directives once. (Note: you might have to add some class assignment directives as well e.g. using Path=System.Windows.Shapes.Path when System.IO is also imported)
  • Cleanup all of the whitespace. Remember special spacing rules like int[]a and int?a are valid and do not require spacing after the type name due to the non-alpha character.

Friday, May 30, 2008

Silverlight Project Updates

Wow, it's already been a month since my last post... and it's been busy one. I've been working non-stop in my spare time on a Silverlight 2.0 project. I should be going live with it in the next week or two, so watch this space! I'm pretty excited about it. If you've read my earlier posts you can probably guess what it's going to be about. Anyway, check out this post on Tim Heuer's blog. It would be pretty cool if this is where the web is headed: http://timheuer.com/blog/archive/2008/05/29/new-deep-zoom-samples.aspx

Monday, April 28, 2008

Connecting Families with Silverlight

One of the biggest hassles my family has concerns pictures. We take pictures on our digital camera, stick them on our PC, and let them sit there for months on end. Occasionally we may print a few or e-mail them to family. True, we could use a site like Flickr to provide an online listing of your photos that family can share. This still leaves a lot to be desired. When we're with family, we can show them printed pictures. They can handle the pictures, rotate them, look closely at fine details. If wehave the time we might create a photo album to show them, containing page layouts, possibly grouped around a specific theme, with the photos positioned however we like. Why can't we do this on the web? I would like to be able to take pictures on my camera, stick them on my PC, upload them to a web site, and create a virtual photo album just how I want. I also want my family to be able to virtually "handle" these pictures by rotating, zooming, repositioning however they want. Stay tuned as you'll be hearing more about this in the near future...

Friday, April 25, 2008

Silverlight Development

I am working on a Silverlight 2.0 project right now and got pointed to Tim Heuer's blog on one of my queries and found out that Tim is now working on the Silverlight team along with Jesse Liberty. Tim is a great guy who lives in the Phoenix area and helped me when I was a consultant with Sogeti, as our local Microsoft developer evangelist. If you're working with Silverlight and have any questions, check out his blog: ~ Method Of Failed ~. Aside from that, I'm pleasantly surprised at how easy it is to learn XAML and the Silverlight model. I previously had no WPF experience (my .NET 3.0 experience was limited to WCF), so I had no prior knowledge of XAML, but was able to pick it up pretty quickly. Granted, I made (and keep making) plenty of newbie mistakes, but overall the learning curve has been pretty gentle. Of course, coming from the perspective of working with Microsoft CAB and the Smart Client Software Factory, just about anything else will have a gently learning curve... but that's a topic for another post altogether. By the way, if you're working with that stuff, Ward Bell rocks.

Wednesday, April 23, 2008

Rebooting the Web

If you're not a geek like myself, you probably haven't heard about Silverlight, Microsoft's new web technology. As both a web developer and a client developer using the .NET platform, I see the strengths and weaknesses on both sides of the thick/thin client coin. Silverlight, especially Silverlight 2.0, blurs these lines. It allows developers to write what are essentially client applications on the web. A few years ago, AJAX (using a technology created by Microsoft, and made popular by sites such as Google Maps), greatly enhanced web applications by doing away with the page refreshes between mouse clicks. This allowed developers to create a new generation of web applications that behaved more like client applications. This revolution was called Web 2.0. It was a great improvement, however web applications were still handicapped by the visual confines of HTML and the browser. Of course, a compelling user experience could still be created with Flash, but that meant that the Flash content would not be indexed by a search engine. Silverlight is the next evolution of the web. As Jeff Prosise put it last year, Microsoft "rebooted the web" by giving developers a declarative programming model using XML (XAML), that allows for the creation of Flash-like user interfaces that can also be indexed be search engines (not to mention it has killer performance). In the past year since the announcement of Silverlight (formerly WPF/E), there have been some great ideas developed around it. Most early adopters used Silverlight simply for streaming HD-video, but that is just the tip of the iceberg. Check out the Silverlight Showcase to see what is possible with Silverlight 1.0. Silverlight 2.0, currently in Beta 1, expands on the Silverlight model by including a version of the .NET platform to write code against. This opens the door for .NET developers who have never touched Flash to write applications on the web that provide experiences that users never thought possible on the web. It will be interesting to see how quickly this technology (or alternatively, Flex, but I'm rooting for Silverlight) is adopted and how the web will be transformed. It is an exciting time to be a web developer.