Archive for the ‘Development’ Category

ASP.NET

Thursday, December 31st, 2009

I’ve gotten a lot done this past week building a web site.  From the master page, to the web forms, to user controls, I’ve been working hard to create a layout that facilitates changes and is easy to reuse.  The scripts are saved in separate JavaScript (ECMAScript) files, CSS is pulled out in most places rather than in-line, and I’m using jQuery to wire up behaviors to elements.

Some important tips and tricks:

  • Declare a ScriptManager in the MasterPage.  Only use ScriptManagerProxy objects in pages and controls.  This ensures that you will be able to attach scripts at any level without that warning about having more than one ScriptManager object.
  • Create separate JavaScript files for each page and control, then reference them using the ScriptManagerProxy on the object.  Name the script files based on the object name for convienience.
  • If you are using jQuery, make sure that you download the Visual Studio documentation file.  This vsdoc/vsdoc2 file must be place at the same location as the main library file.  Do not reference the vsdoc file from anywhere.  Just make sure that it has the same file name as the main file with the “–vsdoc” added (including version number or anything else).
  • In external script files, Visual Studio has no context for other script files that are loaded in the object.  To get around this, reference the file like this:
    /// <reference path=”jquery-1.3.2.js”/>
    This does nothing at runtime, but gives you that wonderful Intellisense at code-time.
  • Use multiple style names on elements.  Unlike C#, Java, and other object-oriented languages, you can have multiple inheritance in CSS.  Some can affect layout, some behavior, and some will just end up being decorators to help you with jQuery selectors.
  • Databind wherever possible.  If there’s one thing that I’ve learned from WPF and Silverlight, working with ControlName.Text or ControlName.Value is no fun!  Learn how to do binding to simplify your life.
  • If possible, leave the design work to someone else!  Focus on div elements anywhere that you can.  Drop in a CSS sheet from someone else and markup the div’s with class names and let that be taken care of.  It may not work out that cleanly, but ideally, do as little layout and design as you can and get the functional bits working.  Keep design out of it as long as possible.
Share

jQuery

Sunday, December 27th, 2009

I finally bit the bullet!  I’ve been reading about jQuery for some time now, but I never took the plunge.  I just don’t do much web development.  Very little really.  I’m currently working on a web site though and decided to see what the fuss was about.

I’m sold!  The web dev work that I have done over the past years has always been a huge exercise in frustration.  Trying to do something as simple as get a reference to an element couldn’t seem to be a consistent activity.  It would work in one browser but not another – unfortunately a common theme with most web work, of course.

What does jQuery do?  Well, jQuery takes care of finding elements and doing things with them.  It’s easy to find an element by its name, class, id, property value, or more.  Using expressions, ancestor/parent relationships, and other such relative reference makes it possible to locate what you need in a logical way.

Just getting an element isn’t very helpful without actions to perform on it.  jQuery makes it easy to set CSS properties or manage events on control elements — all without using the onclick properties in HTML.  I’m all for the DHTML-specific extensions on HTML elements, but I’d rather not use them for reasons of cleanliness.

That’s a lot of what it comes down to.  Clear, concise code.  Being able to embed scripts into external files, pulling style attributes into CSS declarations and then saving them to external files, and now finally, we can really minimize script-related references within elements.  My ideal is to have HTML that describes content in terms of blocks (divs) tagged with labels to assist with layout (ID/class/style).  The actual text is marked up with semantic meaning through the use of paragraphs, lists, spans, and other markers.  I don’t want HTML to have any control over its presentation or behavior.  Without resorting to manual tedious fragile cross-browser code constructs. I can trust the heavy lifting to jQuery.

Link: jQuery

Share

Silverlight Training

Monday, December 14th, 2009

I spent last week assisting with a Silverlight training.  What a great experience!  I’ve been writing WPF applications for some time now, but I don’t enter the browser-based world very often.  I was there to focus on the developer side and to assist with student projects.  It was a week well-spent.

Since I’m typically on the developer side, I’m not vey comfortable with Blend.  I can see that XAML development/design is easier in Blend than in Visual Studio, but it’s so different.  Blend is nothing like any developer tool I’ve used before.  The UI controls don’t have any of the typical look-and-feel so it’s a real struggle at first.

On top of that, XAML itself is just so different from VB and C#.  It’s a great benefit though.  By learning XAML you can eliminate the need to write most of the code.  Making a control become disabled based on another checkbox, binding data to business objects, even creating advanced effects like motion and highlighting can be achieved in a strictly declarative sense.  Code ends up being used as glue like it’s supposed to be!

There are plenty of things that you can’t do in XAML, but some of those things can be achieved by using code shims called behaviors or converters (a few other things as well).  You write these once, declare them for XAML consumption, then use them declaratively as needed.

Debugging can be a real problem though.  Figuring out which parent element has an explicit size set when you are working for a dynamic layout, or figuring out where a resource went which was being picked up just fine a minute ago can be difficult.  Crashes can even occur at runtime even though everything is well-formed.  For example, if two timelines (animation definitions) that run at the same time make changes to the same property of an object, it will fail.  This might not be obvious during design-time.

For all that though, it’s worth working through the pain.  I went from being a fair WPF programmer to a pretty good one just from what I learned about Silverlight and Blend  Of course I’m much better prepared for Silverlight development now too!

Share

Hot Stuff

Friday, December 4th, 2009

At Aeshen we work on a lot of new technologies.  We’re often on the forefront of products before they are released.  This makes for a fun time getting to explore the new features to learn about how developers can benefit.  A big part of our job is taking these features and making their value propositions really clear.  The thing with developing is that there are an almost infinite number of ways to do anything.  If I read about a feature that allows data querying in a novel way or that adds some new troubleshooting features, I might be excited by the prospect of it.  Almost always though, people are already doing the same thing using other tools or techniques,  Even if this way results in less code or is easier to maintain, it’s not necessarily a slam-dunk in the eyes of all developers.

Everyone has their favorite ways of doing things.  It’s usually based on custom code, specific tools, third –party libraries, and that special extra touch that they bring to the table.  It takes a pretty big benefit to justify the cost of changing,  There’s the time to learn the new technology to the level of the other choices.  There’s the question of updating existing code or not.  There’s the question of licensing, installation, training for support people, and a host of other questions.  It’s no wonder new features and products are rarely embraced by the general community as quickly as I expect them to be!

The final issue, in my mind, is the question of future.  Every new release is a bit of a gamble.  Will it be deprecated by a new version in a few months?  Will it be abandoned between final beta and release  Will a new product supersede it?  Will it fall by the wayside due to a competitive offering?  It’s a big deal to invest in something new when everyone knows how brutal product lifecycles can be.

I can’t ever help out with that side of things, so I dig into the new stuff and create content to show it off in the best light.  If it doesn’t remain relevant, then I usually feel pretty disappointed.  After all, I’m invested in the new technology due to work required to ramp up and “sell” it.  If it doesn’t take off, and I sense apathy from the greater developer community, I feel like maybe my work wasn’t what it needed to be.  In the end though, the community chooses.  I get to play with shiny new things, and hopefully I helped to inform some decisions!

Share

PDC ‘09

Monday, November 23rd, 2009

Well Microsoft PDC ‘09 has come and gone.  I spent a good chunk of time in the expo area (vendor fair) and I was pretty disappointed.  It really seemed like attendance was lower, and there were fewer non-Microsoft booths hawking their wares.  There was actually a good number of Microsoft technologies and product groups represented.  If you want to meet the people behind the magic, then you were probably happy.  If you were looking to learn about third party products, you might have felt let down.

Personally, I like to talk to the Microsoft folks and hear about what excited them.  Seeing them demo their products is fun and being able to provide such direct feedback is gratifying.  Many of them are actively seeking this feedback, others are happy to hear it.  Most of them will at least listen politely.

Not only was the vendor area a bit sparse, but the session offering was a trifle weak as well.  The first day’s keynote was all Azure, as were many of the sessions.  Though day two was more focused on general Windows technologies (including some cool IE 9, .NET 4, and Silverlight 4 demos), it seemed wasteful to take up so much of the first day (essentially a third of the conference) on Azure.  Great if you are looking to host such services, but not everyone is!

I went to a few really good sessions.  I’m really interested in WPF, Silverlight, and .NET 4.0.  MEF is cool, SharePoint 2010 is gearing up to be great.  Windows 7 and Server 2008 R2 are full of new features to take advantage of and good sessions will help devs to get started.

I’ve only been to one other PDC (05), but I’ve been to five JavaOne events over the years.  JavaOne events were much bigger and more sensational, though the economy was better during those years.  Hopefully the next PDC will more like PDC 05 was.  Somehow I don’t expect them to do another free laptop though!

Share

SharePoint Development

Friday, November 13th, 2009

I’ve had the chance to do some SharePoint development and it’s been an experience for sure!  Specifically, I’ve been trying to write a custom HTTP handler.  This was much more difficult than I expected.  I’m not familiar with the Visual Studio extensions for SharePoint, so I was writing and deploying the code pretty manually.

What I ended up doing, for simplicity, was create the entire source file in a single ashx file.  I don’t even register the handler, so it’s really just invoked like any other URL, using an HTTP GET request.  I’m not sure that needed to be an ashx file, but there are no ASP.NET pieces here so it seems cleaner.  I use the Assembly tag to reference assemblies that I need, then move straight to the using statements, and then to my class definition.  No code-behind – all in the ashx.  Again, I’m not sure that this was needed, but it was easier to manage.  I couldn’t do any debugging, and I was manually deploying.

I copied the file to the c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\##\TEMPLATE\LAYOUTS, then created a subfolder for my code.  Every time I hit the page, I got a “Runtime Error” message.  I never did find a way to see the underlying error, even with changes to Web.config to turn off custom errors.  The only thing I can think of, is that there is another Web.config file at a different level that overrode those settings since even an iisreset didn’t get things working.  Once I got compilation working though, you’d better believe I had a try/catch surrounding everything so I’d know what was going on.

To reference files in the LAYOUTS folder, I just used http://MYHOST/sites/_layouts/MYFOLDER/MYFILE.ashx.  I discovered that I could link to images, XAP files (for Silverlight) or whatever else for ease of deployment with no document libraries involved.

I wasn’t able to reference custom libraries, but I didn’t have a real need so I didn’t try very hard.  I had considered moving my code in compiled form via a DLL, but I ended up merging it all into the uncompiled ashx file and doing a file copy.

The final step was interacting with the SharePoint instance itself.  The SPContext.Current reference was null.  Even passing in the HttpContext object it failed.  What I ended up doing was just passing in the host name of the machine I was working on.  It’s a pain and would need changing on a new deployment, but it’s a pretty small change, and since it’s the code’s deployed as source, you don’t need to recompile.

In the end, I had what I needed.  I realized, afterwards, some things that would have made things better, but the lack of runtime error support was awful.  I didn’t know if my code failed or if it didn’t even compile – it looked the same either way.  Finally getting the handler in place and doing its job is a wonderful feeling.  Now my next SharePoint experience will have a little more knowledge behind it.

Share

Parallelism with .NET 4

Saturday, November 7th, 2009

I’ve been using Visual Studio 2010 Beta 2 and .NET 4 for a little while now and I must say it’s really nice.  If you are sold on the benefits of multithreaded code (if not, you should be!), then two new features in .NET 4 and two new features in Visual Studio 2010 should really excite you.

.NET 4 has introduced a new feature called Tasks.  Tasks are ways of managing discrete units of work to perform on other threads.  Instead of creating Thread objects, or dispatching work to the ThreadPool, you can now create a Task object, point it at some work to do, and schedule it for work.  They support cancellation, and you get pretty good insight into their current status.

Tying into that, are the new Parallel LINQ extensions.  LINQ is a great technology for querying databases, XML data, and even in-memory collections.  In the end though, much of what happens isn’t much better in terms of performance than a foreach loop – it’s just more expressive and has the advantage of deferred execution.  If I execute a LINQ query across a collection of 10,000 objects and each evaluation takes 1 second, then it will take 10,000 seconds.  The parallel extensions allow me to, almost transparently, spread the work across multiple cores.  Thus, if I have 2 or 4 cores, I’ll get roughly 2x or 4x the performance (note: you’ll never actually get a linear speedup with cores, but you get the idea…).  This works so well since queries almost never rely on shared state and rarely have any side-effects.  In other words, I can perform my evaluations forward, backward, or staggered with no ill effects.  The only question is whether the original caller wants them ordered in some way.  No worry though: LINQ will hold the results until they’re all in for ordering, or release them as they come back depending on the scenario.  It’s really a great system and very easy to use.

Finally, Visual Studio itself has been enhanced with new debugging tools.  You’ve always been able to see the state of threads using the Threads tool window, but there’s a new Parallel Tasks tool window now for only showing work being performed by tasks.  This is a much better view so you only see your app’s parallel work – not a messaging thread or background WPF workers.  You can flag threads of interest, see why deadlocks are occurring, and see stack trace info from the same place.  In addition to Parallel Tasks, there’s the new Parallel Stacks tool window.  This is probably the coolest.  Instead of seeing a list of stack frames, you can actually see how many threads/tasks are executing a given method, and how their stack frames diverge and come together.  This gives you a tree with an at-a-glance view of everything your tasks are doing.

If you haven’t downloaded Visual Studio 2010 Beta 2 yet, you really should.  Even for developing .NET 3.5 apps, it can’t be beat!

Sources:

Share

Sensors and location

Wednesday, November 4th, 2009

One of the great new features in Windows 7 is the addition of sensors and location as common services. Working with a touch, temperature, light, or accelerometer sensor before would require you to obtain specific drivers and learn a new API or understand low-level protocols and use the serial, USB, or other ports. With Windows 7, now you can just use the sensor manager to enumerate sensors by name or type (i.e. all light sensors), find out their status, and subscribe to values. This makes it so simple that anyone can do it – with just one problem. Most systems don’t have any sensors yet. Microsoft anticipates that the next wave of notebooks will have accelerometers and light sensors like most smartphones do. If your laptop has a light sensor that has the right driver, it can take advantage of the built-in Adaptive Brightness service.

clip_image002

This just adjusts your backlight based on ambient light. An accelerometer sensor has less use in a laptop – who wants to wield their entire laptop to play a game! On the other hand, it can be used to determine shock for a hard drive (some drives already do this), check for motion for an alarm, or just be used in unwieldy games! I think that the magic of sensors will be that developers will come up with novel uses that no one has come up with yet. Being able to bridge the virtual with the physical environment is a big deal. This impacts games, social functions, and creative efforts. Adding a web cam can lead to an even better experience due to the positional information.

Location is also very cool in that most systems have no concept of where they are. This information is useful for web searches, news headlines, weather, social sharing, or even theft recovery. Location can be obtained by IP address, cellular tower triangulation, or dedicated GPS units. Each of these has vastly different methods of determining the location involving complex math, hardware interfaces, and software protocols. The location API simplifies this by providing a simple API for grabbing latitude/longitude or even a civil address, if available. This requires that a provider is installed that can do the work of figuring out the location, but then all consumers benefit from one simple way to be updated, with no worries of a device being locked, disappearing, or other issues.

All sensors and location devices require opt-in from the user. This makes it important for a developer to check for the permission first. You can also check for connection and disconnection. Not needing to deal with hardware, protocols, and exact implementations makes a huge difference. Now anyone can add these features to their applications. We just need to cross our fingers that people start integrating the hardware side of things quickly!

Share

Aeshen is invaded by WordPress

Thursday, October 22nd, 2009

This is a sample Blog post

this is more XAML code

Share