Dan Rigsby - Coding Up Style

.Net, C#, & Wcf Development

Heroes {Community} Launch - Ft. Wayne

Posted by Dan Rigsby on May 14th, 2008

I finished another Heroes {Community} Launch event last night in Ft. Wayne, IN for the .Net Users of Ft. Wayne (nufw).  I volunteered to speak up here because my in-laws live in Ft. Wayne, and I figured it would be nice to give my wife and daughter the chance to visit with them while I was speaking. I have had this event planned for a couple of months, but I knew it would be hard to do an entire launch event in just one night.  Fortunately, they were really only interested in Visual Studio, but it was still difficult to squeeze everything into one event. The major areas of discussion were:

Visual Studio 2008

  1. What are the features in Visual Studio itself targeted to different types of developers: All, Windows Client, Web Client, Office, Mobile, and Server.  I went into highlights in each one of these that people may or may not know about.
  2. New project properties
  3. UAC support in application manifests
  4. New Css Support in web projects
  5. New Web Designer
  6. Javascript Intellisense
  7. Javascript Debugging

Languages

.Net Framework

  • Additions to .Net 3.0 features (WCF, WF, WPF, Cardspace)
  • Additions to Windows Forms
  • Additions to ASP.Net
  • System.Addin
  • Additions to CLR (HashSet, ReaderWriterLockSlim, DataTimeOffset, TimeZoneInfo, etc)
  • Expression Trees

Overall, I think my presentation went pretty well.  We started a bit late since we had to wait an extra half hour for the pizza to arrive.  It would be hard to hold a 2 hour meeting with a bunch of hungry developers.  The meeting was held in a small conference room at local company. We had 30 people attend which was one of the highest attended events that NUFW has ever put on, but meant that the room was very crowded.  We had to bring in seats to fit everyone, and I was forced to have some attendees sit behind me which was a bit uncomfortable.

I really enjoyed presenting there, and I hope they invite me back again in the future.   Unfortunately though, they didn’t provide questionnaires to the attendees.  So if anyone who attended this event is reading this, please provide any feedback (both good and bad) either as a comment to this post or directly to me.  I would like to know what I am doing well and what I could do better, but I hope everyone enjoyed the presentation.

Here is the entire presentation including slides, before and after projects, code snippets, notes, etc.: http://www.danrigsby.com/files/Presentations/HeroesCommunityLaunch-FtWayne.zip

Posted in Community | No Comments »

ArcReady: Architecting for Scalable and Usable Web Applications

Posted by Dan Rigsby on May 13th, 2008

ArcReady is a quarterly Microsoft architecture meeting that travels through the Midwest.  This quarter Larry Clarkin himself is presenting on “Architecting for Scalable and Usable Web Applications”.  Larry is the Architect Evangelist for the MidWest region and well known in Indianapolis. This session is about how to prevent scalability problems in web applications and how to handle them before they happen.  This is not a quick fix session about how to fix applications that already have an issue.

The room here in Indianapolis was packed.  There was a mix up in the rooms, and the ArcReady event got the smaller room.  There ended up being over 50 attendees with quite a few standing in the pack.  I was pleased that I left early and got a seat.

Performance vs Scalability

Performance is how your application behaves when there is just one user. Scalability is how your application behaves when there are many users.

Scaling Later: Don’t worry about how to handle your 1 millionth customer when you don’t have your first yet.  It’s good to start thinking about scalability early, but don’t spend a lot of time on it until the system is being used.  Getting revenue means that you have money to work on scalability in the future.

Patterns for Scalability

  1. Block and Tackle: Diagram your network layout and all of its resources so you can identify potential bottlenecks early.  Caching can really help elevate the load.  For instance, cache the list of States in the country since this list isn’t going to change between page requests.
  2. Scale Up: Taking existing architecture and improving pieces of it.  Many times this means work on the database server.  Web servers are easy to scale out, but databases can’t be farmed like web servers.
  3. Scale Out: Adding more servers and potentially changing your architecture.  This often means adding more web servers in the web farm and moving the session to the database.
  4. Specialize: For each server you add, give it a dedicated role such as a web application server, web service server, and a resource server.
  5. Split the application: Put different parts of an application on a different server.  For example, at Amazon.com each tab for its’ store is on a different machine.  Microsoft has parts of its’ site on separate machines such as microsoft.com, msdn.microsoft.com, and technet.microsoft.com.  Microsoft ties its’ sites together with Live Passport and search indexing.
  6. Split the database 1: Split the database based on data.  Perhaps have a Reference (read) and Transaction (write) databases.
  7. Split the database 2: Reads happen a lot more than writes.  So have a lazy replication from writable database to a read database.  This could be done with replication.
  8. Split the database 3: Sharding - Split data on some key such as area code or A-L & M-Z, etc.
  9. Geo Distribution: You need to keep multiple copies of the data in multiple locations to avoid things such as power outages and natural disasters.  You could even use these sites to help route the traffic to its closest server center.  This does take a lot of replication work, but can really help with failover and scalability.
  10. Offload the Work: Content distribution networks can help help funnel the work.  You could even push your entire web server farm to a company that specializes in this.

Anti-Patterns for Scalability

  1. Spending all your time looking at code: Chances are the problem may be a setting or a hardware related issue
  2. Caching everything: Scalability can be destroyed because of everything stored in memory.
  3. Services calling services (especially across the network): This is a mess and causes performance issues.

Scalability Tips

  • Make sure you set debug=false in your web.config file before deploying.  Partially because the timeout becomes timeout and the resources held by that request are kept with that infinite timeout.  You can put a string in the machine.config to prevent debug=true settings on any website on a machine.  It’s best to turn this on for every production webserver.
  • Load balancing SSL is specific to the session and the service.  So if you just do true load balancing, performance and scalability will drop with SSL because of how the SSL negotiation works.  For each server a request gets routed to the SSL tokens need to be renegotiated.  To help prevent this, you can use server affinity so that every request for a client stays on the same server.  You could also have a single SSL negotiator that is in front of the web farm.
  • Many times images and resources take up the majority of the data in a web request. So you can move these files to a separate server to help distribute the load.  This can include images, javascript files, css files, etc.

Usability

Application Archetypes

  1. Information/Reference: Wikipedia, blogs, etc
  2. E-Commerce: Amazon, e-bay, etc
  3. Utility: Windows Update, etc
  4. Data Viewer/Editor: Reporting sites, etc
  5. Document Viewer/Editor: Office, etc
  6. Entertainment: Gaming, Movies, etc

Web UX Continuum

  1. Ubiquity: Web
  2. Richness: Supplemented Web such as Silverlight
  3. Next Generation: Platform Optimized such XBAP

Overall there are 35 different UI platforms that Microsoft gives developers.  You can run UXIQ (download) to give you the best option for your needs.

Usability Best Practices

  1. Form follows Function: Think about functionality first
  2. Create a set of design tenets: 5-6 pillars of design principles that the application must have such as “I don’t want the user to have to click more than 3 times to get anywhere”.
  3. Use the appropriate level of fidelity: How rich is the application?  Or have a different level of fidelity depending on the user.
    •  ProtoXAML is a template that allows you to take WPF mockups and skin them with “napkin” or “whiteboard” like look to the took.  People like the whiteboard metaphor and respond well to UIs that look this way when giving feedback.  This is an example of using very low fidelity to get a point acrossscreenshotNapkin
  4. Build with the customer and user’s input: Get customer input early and often.  However think about all potential users of the application.
  5. Build for ease of use, but don’t forget the power users: (70-20-10 rule)  Make your application easy to use, but make sure you have options for the power users.  Tripit.com is a good example of this in use.
  6. Plan for concurrency: You will always have more than one user in an application.  Think about locks and other data sharing
  7. Balance computing load: This can make things faster and more scalable (see scalability topics)
  8. Balance security with usability: Make sure you security mechanisms are also easy to use. Some password reminders can be confusing because the answer could be expressed in many ways.   For instance, you may be able to shorten the answer in some way or what about casing of the words.
  9. Build for supportability & maintenance: Marketing always wants to update a website.  Make sure your site is easy to maintain and make changes to in the future.
  10. Compliance: (Section 508 and Accessibility) One such issue is screen readers.  These are programs that read a website out loud for the visually impaired.  The readers have to be able to read your site in such a way that user’s can make sense of the data.

Anti-Patterns for Usability

  1. Golden Hammer: The same solution doesn’t work for all applications
  2. Breaking UI Conventions
    • An example of this could be using a hyperlink to represent a submit button.  Hyperlinks usually open pages or change navigation.  Submission is usually handled via a button.
  3. Overuse of Animations or other types of bling
  4. Not considering multiple “heads” for complimentary online vs. offline scenarios

Overall, it was a very good event (although seating was cramped).  It was Probably one of the best ArcReady events I have attended in quite a while.  Lately, I have thought the sessions have been a bit boring and not very useful.  I am glad to see the event is picking back up again. Larry is an excellent speaker (and mentor of mine).  He did a great job of engaging the audience and getting them involved.  This can often be a very difficult thing to do.  He wasn’t afraid of silence and to solicit the audience to get a response.

During the break, Larry showed a video of the WorldWide Telescope.  You may have seen this video.  Its of a little kid talking about where he lives and how see sees the sky at night. Larry stated that he couldn’t give us a copy yet because it wasn’t out.  I corrected Larry that it was released today (see last post) and can be downloaded.

The event ended with Larry asking the audience about some of the best practices for UI development.  The audience suggested things such as compressed scripts, no vertical scrolling, keep buttons together, keep consistency in site navigation, etc.

If you missed this event you can try to catch it at one of these locations:

You can also download the presentation directly from the ArcReady website.

Posted in Community, Software Architecture | No Comments »

Microsoft’s WorldWide Telescope is Available

Posted by Dan Rigsby on May 13th, 2008

Microsoft has released its Worldwide Telescope software, and it is available for download. This software can be used by astronomers and non-astronomers alike to explore the heavens with a desktop client much like Google Earth.  I have a vested interest in this after having working on some Observatory Simulation Software and my life long love of astronomy. I am excited about spending my evenings exploring the cosmos. Long Zheng has a good review of this product here: http://www.istartedsomething.com/20080513/capturing-screenshots-from-worldwide-telescope/.  I am very exciting about this product.   It’s one of the coolest applications I have seen in a long time.  Supposedly, a video of this product even made Robert Scoble cry.

wwt5

I doubt you will find evidence of alien life, but I urge you to download the software and try it out yourself here: http://www.worldwidetelescope.org/experienceIt/ExperienceIt.aspx?exp=true.   You won’t be disappointed.

Posted in Applications | No Comments »

West Michigan Day of Dot Net

Posted by Dan Rigsby on May 10th, 2008

 

Live blogging this event, expect updates throughout the day.  Pictures will be available in a day or two after the event.

WM Day of .Net May 10, 2008 - I'll be there!

I made it out to Grand Rapids, MI around 8am today to attend the West Michigan Day of .Net (WMDoDN). It was a 5 hour drive from Indianapolis.  However, I spent the night with my In-Laws in Ft. Wayne which cut the trip this morning down to only 3 hours.  Much like with the Central Ohio Day of Dot Net there hasn’t been much representation of Indianapolis in Michigan thus far either.  It seems if you are in a different Microsoft district, you either don’t know much about what is going in other districts, or are afraid the break the barrier.  I have met with a number of people know from Ohio and Michigan, and we are hoping to change that over time. I have another session over Wcf up here, and again no one seems to know any other speakers from Indiana.  I ran into a few familiar faces from other events and meet a few new people(Wally McClure, Bruce Abernathy, Dan Hibbitts, Chris Woodruff, Amanda LaucherSteven Harman, Tim Wingfield, James Bender, Jay Wren, Josh Holmes, Jeff McWherter, Dave Redding, Joe Wirtley, Dan Hounshell, Joel Ross, Jennifer Marsman, Patrick Foley, etc).

I liked the layout of the event.  The 4 rooms, but the were a little bit spread out.  I saw a number of people get lost between rooms.  However the amount of space was very refreshing.  There were a few “break out” areas and there was a dedicated speaking room.  The vendors and sponsors were spread out throughout the hallways which was good.  Many times attendees try to avoid the “sponsor” corner, which is unfortunate for everyone.  The sponsors make these events possible and really do have good things to say.

Soft Skills - They’re not just for humans anymore

I am trying to attend as many sessions as I can and learn as much as I can while I am here.  I started the day attending Josh Holmes session on Soft Skills.  I had seen Brian Prince’s presentation before and wanted to watch Josh’s perspective on it.  Josh got thrown this session at the last minute and piggy-backed on Brian’s slide deck.  However, he brought his own unique perspective to each of the topics:

  • Mentoring: Always have a mentor.  In fact get 3+. Josh attended the toastmaster’s club to find speaking mentors
  • Manage your Career: You are your business.  Your employer just happens to be the person paying you to do your job right now.
  • Creativity: Like myself Josh doesn’t have a CS degree and it does give us a creative edge because we think outside of the box.  This is true for everyone.  Stay creative and think in other ways.  Keep a log or use something like OneNote or a notepad.
  • Brain Storming: Josh asked the question, “If you have an infinite supply of bricks, how would you raise money for your user group, school, or church”.  The audience threw out some of the standard responses, but
  • 3 Illegal Topics to Talk About: Sex, Politics, and Religion - don’t talk about these at work, just don’t do it, unless the setting is totally appropriate.
  • Don’t Assume all People Above you are Idiots: Sometimes they aren’t the smartest people, but there is a reason they have their position.  They are bringing something to the table and at the very least have power and control.
  • Communication Skills: Communicate like a human, not like an alien.  Know your audience: geek talk is ok only if all people are geeks.
  • Know when to say “I don’t know”: It’s ok not to know everything, and if you give wrong answers, you lose all respect.  Don’t be an encyclopedia, be the index.
  • Ask Open Ended Questions: If people just answer Yes/No you never really learn much
  • Don’t Take Reactions Personally: People don’t always mean what you think.  Especially in things like emails.  Some people come off more rigid than others as well.
  • Be an Active Listener: Don’t have distractions, ask smart questions, don’t multi-task in your head.  Take what a person says and rephrase it back to them, and if they can confirm that, then you can answer the question.  Also avoid filler words, enjoy the silence.
  • Take Notes: Notes don’t have to be a distraction, but write down things as much as you can.
  • Tape Yourself: learn to find the filler words in your presentations and how you can improve yourself.
  • Avoid Bad Language:  There is no need for it.
  • Integrity & Honesty:  always tell the truth and remember that its hard to get respect back.
  • Everything you know today will be obsolete in 2 years: which is true from a technology standpoint, but soft skills will always be with you.  So eat like a bird and poop like an elephant.

Josh ran out of time during the presentation, but that’s ok.  Its unfortunate that some of the most important topics are at the end of the slide deck, but it’s better to get a few points across well rather than just throwing out a mess of information sometimes.  A presentation like this is more training rather than a survey of some technology.

Overall, I would say Josh did just as well with the presentation as Brian did.  Brian overall probably had the better pitch of the ideas, but that is understandable since he put together the slide deck.

I did enjoy watching Josh after reading a couple of his latest posts: Words as Filler when Public Speaking and Public speaking and movement onstage.  You could actually see the 2 points on the floor that Josh positioned himself as “home” and “away”.  I didn’t go as far as to try to count his “filler words”, but I either didn’t notice many or at the very least they weren’t a distraction.

You can download the Soft Skills presentation here: http://cinnug.org/files/folders/cododn2008/entry1045.aspx

How to Architect Rich Internet Applications (RIA)

I went ahead and stayed for Josh Holmes’s second session. Josh is a good speaker and potential “mentor” for me, so I wanted to learn all I can.  I always feel awkward talking to Josh in person sometimes though.  The session was packed.  I think I only saw 3 empty seats which brought the audience total up to 60+.

What is a Rich Internet Application?  Its all about context.  The challenge in an RIA is to not make things more difficult by adding some flash.  RIA is web application that has the attempt to bring features and functionality of a traditional desktop application to the web.  There is some overlap between desktop and web, but the differences are killer such as: lack of state on web, non-text layout on desktop, business logic in UI on desktop, limited runtime on web, the nasty back button on the web, etc.

“The Inmates are Running the Asylum” and “About Face” by Alan Cooper bring out the idea of treating the user of your application as “God”.  If “God” says close the application, are you going to ask “Are you sure”?  The reality is that we treat our users as morons.  You need to know when to trust your users, put the user first, and know when to help them.  A big anti-pattern that we often get into is making our SOA layer look like our pure CRUD operations.  Instead we want to think about it more from an end user perceptive.

“Hype” is often very misleading.  Sometimes a manager will say something like, “We need a better web UI.  Let make it more Web 2.0 or Ajaxy”.  The problem is that you want what is best for the user and that shouldn’t mean attaching words and labels to it.

The C# Variety Show

The yield statement as compared to beer: If you ask your wife to get you beer, and she brings you a 6-pack, that would suck to have the entire 6-pack dropped in you lap.  Instead you would want them one at a time.  Yield allows you to get a item one at a time and consume them as needed.

Operator overloading: Barely class, Hops class, Water class, overload the plus operator to add them together to create beer.

Unfortunately, I only attended these 3 sessions.  I had some last minute testing to do of my presentation and spent some time talking in the speaker room.  My session went pretty well.  I had a packed room which was probably around 40-50 people. I felt I was a bit dry, but I did have a lot good questions and comments.  I only had two people doze off, which actually isn’t that bad for a session that late in the day.  I didn’t have any presentation glitches, but I really need to add more images and “real world” examples to my slides.

Posted in Community | 4 Comments »

Heroes {Community} Launch - Indianapolis, IN (Part 2)

Posted by Dan Rigsby on May 9th, 2008

Last night I presented at the Indianapolis .Net User’s Group (IndyNDA) monthly meeting.  This is actually the third time I have spoken at IndyNDA in the last 4 months.  I am sure the attendees are getting tired of seeing me up there.  The president of IndyNDA, Brad Jones, jokingly told the audience that they would give me a four month break from speaking at the monthly meetings.  This month was part 2 of the Heroes {Community} Launch event series we have been running for Windows Server 2008, SQL Server 2008, and Visual Studio 2008.  Part 2 focused on new features in C# 3.0, VB 9.0, and .Net Framework 3.5.  The major areas of discussion were:

Languages :

.Net Framework

  • Additions to .Net 3.0 features (WCF, WF, WPF, Cardspace)
  • Additions to Windows Forms
  • Additions to ASP.Net
  • System.Addin
  • Additions to CLR (HashSet, ReaderWriterLockSlim, DataTimeOffset, TimeZoneInfo, etc)
  • Expression Trees

We had around 85 people attend.  Which is on the low end of average, but they were a very active audience.  I had some great questions and answers to the questions that I proposed to the audience.  There were times when I felt like I was losing the audience, but there was a lot of material to cover all at once.  The goal of this meeting was more to show what is possible with the Languages and Framework, not to do in depth training.

Immediately after the IndyNDA meeting, I spoke at the Team Foundation System Special Interest Group (TFS Sig) and covered Scrum in a duet with Jamie Kurtz where I did a short version of my Scrum talk and Jamie covered Scrum in TFS.  As with most special interest group meetings, we had a small attendance.  However I was pleasantly surprised to see that 3 people drove over 3 hours from Decatur, IL specifically to see the Scrum talk.

For those who attended either event, I am always looking for presentation feedback (positive or negative).  Feel free to post a comment here or email me (see address on About Me page).

Here are the presentations including slides, before and after projects, code snippets, notes, etc.:

Posted in Community | No Comments »

When to make an action Invisible or Disabled

Posted by Dan Rigsby on May 2nd, 2008

When I want to prevent a user from performing an action on a page, do I disable that control, or do I just make it invisible?

It seems no one has really published any rules about when to use either of these options (at least none I can find).  Some applications use one method, when they should probably be using an other.   Many of you may think this to be trivial knowledge, but I see applications all the time that don’t follow general standards or even show consistency in the application itself. I would like to officially propose the following "soft" rules:

Rules:

  1. If it is an action the user does not have permission to use, make it invisible. If the user is never going to have permission to perform the action, then there is no harm in not showing.  This may be preferable too so that casual users don’t know about actions that more advanced users may be able to perform.
  2. If it is an action that the user normally has permission to perform, but is not available at that time, make it disabled.  Making actions invisible and visible again can confuse users because they expect to see certain actions in certain places.  Disabling it keeps the action in place, but the user can no longer select it.

For instance, lets say you are working on an ordering application.  There may be a "save" button that is disabled until the user enters in all relevant data.  Once the order is placed, no one can edit the order except an administrator. So, on a summary page you may have a "save changes" button that is only visible to those users with administrative permissions. However, what if you use the same form for adding and editing the order?  The regular user normally has the permission to "save" a new order, but not the permission to "save" and edit to an existing order.  Since this is technically a different action now, making this button be invisible is acceptable in accordance to the defined rules.

As with most rules, there may be exceptions.  These exceptions should only be used in "special case" scenarios.  Your application and company as a whole should have standards that are routinely followed.  Here are some proposed exceptions:

Exceptions to the rule:

  1. When you need to disable an action and are working with a control which doesn’t have an enable property:  In this scenario you might look at a ReadOnly property or find some other way to "gray out" the action.  You should avoid making the action invisible if you can help it.
  2. When you want some descriptive information displayed to the user even if they don’t permission: You might want to go ahead and show an action as disabled even if the user doesn’t have permission just so the user knows it is there.  You should avoid this doing this all together, but you may come up with a scenario where this makes sense.  If you do this, you may want to append something like "(admin)" to action name to inform the users that this isn’t a task they can perform.

kick it on DotNetKicks.com

Posted in UI | 2 Comments »

Have you tried Community-Credit.com?

Posted by Dan Rigsby on April 30th, 2008

logosmall5 I am probably the last person to discover this site (I always seem to be the last to know a lot of stuff), but www.Community-Credit.com is a site where you can record your contributions to the development community. "Stupid prizes" are given to the people who record the most community points for a given month.  Some of these prizes are actually quite nice and all of them are very geeky. If you do any kind work with the community or even just attend user group meetings, I encourage you to check it out.

What is Community Credit?
Community Credit is a way of showing your contribution to the technology community.  Community Credit helps show off the enthusiasm and passion you have for the success of our industry.

How do I actually get points?
You can submit points on our Point Submission page. Simply type your name, email address, date you earned the points and point category and they will instantly be added to your total. The points that you earn can be seen on our Community Leaders.

The site was created by David Silverlight back in 2005.  David has been a great community contributor and Microsoft Mvp for many years.  Microsoft honored him last year when they named Silverlight after him.  After reading so much about him, I hope I have the chance to meet him some day.  Not only is has he done a lot to promote the community, but he also does a lot of work for non-for-profits through his sites.

So why record your community credit?  Well for one, it helps you keep track of everything you have been doing in the community.  It can be easy to forget something you have done many months ago.  You may use the site to show off to potential employers or friends.  Mostly its just fun to compete with your community friends to see who can help out others the most.

When you submit your contributions, you must provide a Url which can be checked to validate your submission.  Each Url can only be submitted once.  So if a single Url could relate to multiple point credit areas, then you will want to pick the one with the highest total.  There is room for this system to be abused, but there is a certain amount of honesty that must be assumed with a site like this.  I’m sure if someone is caught abusing the system, then they would be banned or at least deducted a certain amount of points.

communitycredit1

The point ranges don’t always make sense.  Like a response on a discussion board that is marked as an answer is only worth 150 points, while a blog entry can be worth around 3000.  Sometimes an answer on the forums can be longer than a blog post.  Writing a book is only 30000 points.  I think most books are bigger than 10 blog posts.  You can even get points for posting articles to DotNetKicks. But then again, you are probably getting some kind of commission from a blog post too.  However, I think the point ranges have been fairly well thought out and are at least level among all of the contributors.  They have also added in "curves" so that people who have won prizes in previous months, don’t get as much credit in future months.  For example, the top winner in April, may get a 95% curve placed on them such that if they enter something that is normally worth 1000, they will only be awarded 50 points.  These curves normally expire after a few months, however certain "Hall of Famers" of the have been slapped with a 50% curve making it harder for them to come out on top in a given month.

The site is so great at recording points, that the INETA Community Champions Program even uses the community-credit.com website to log contributions for their own award system.  This program offers its own set of awards that are given to contributions to the development community.  However, the points from community-credit don’t automatically cross over to the INTEA program.  INETA has their own set of Activities and Activity Types.  So if you wish to contribute to INETA and community-credit, then you will have to do a fair bit of dual entry.

Check out my community-credit profile here: http://www.community-credit.com/Portfolios/ShowPortfolio.aspx?UserID=119bae28-46ed-491d-8243-94c452dc1991.

I also created a blog badge (80×15) image that links to my community-credit account.  Feel free to download this badge and use it on your own blog, if you want:  http://www.danrigsby.com/Files/Images/communitycredit.png.

communitycredit

kick it on DotNetKicks.com

Posted in Community | 12 Comments »

Sexagesimal Conversions in .Net

Posted by Dan Rigsby on April 30th, 2008

No, that is not a dirty word, and yes, it is fun to say. [sek-suh-jes-uh-muhl]

7520012074151Sexagesimal is a base-60 number system much like our own base-10 decimal system.  Throughout history different cultures have chosen different base numbering systems based on things they considered common or sacred.  Many people today recognize numbers as always being base-10, and it can be quite difficult to explain a different numbering system to a child.  Those of us in computer science are quite use to a base-2 (binary) system.  Some of the more common historic number systems are:

  1. Base-5 (quinary): This system has been popular because five can easily be represented by the five fingers on one hand
  2. Base-8 (octal): Some cultures used only their fingers to count and used the thumbs as place holders.  While other cultures, such as the Yuki Native American tribe of Northern California , counted the spaces between the fingers.  The Yuki actually started counting with 0 as well (much like C based languages).  So the numbers 0-7 were counted on their fingers.
  3. Base-10 (decimal): We are all familiar with the base-10 system which is almost universally used around the world.  Historical this is based on the fact that humans have ten fingers on which to count.
  4. Base-12 (duodecimal):  This system is based on the knuckles of the four fingers.  Each finger has 3 knuckles and the thumb is used as the place holder.  Twelve is also an important unit in British measurement such as 12 inches in a foot, 12 pennies to a shilling, 12 numbers used in our time units, etc.
  5. Base-20 (vigesimal): The base-20 system originates from the combination of ten fingers and ten toes on which to count.  This is most widely known to be used by the Mayan civilization.
  6. Base-60 (sexigesimal): The base-60 system dates back to the Sumerians and the early cultures of Mesopotamia.  It’s hard to say where this system originated from, but common belief is that it is a combination of the base-10 and base-12 systems.

So why is the base-60 system still important to us today?  Well for one, there are 60 seconds in a minute and 60 minutes in an hour.  This measurement one of the Sumerian’s lasting impressions today.  Their calendar and type systems have been adopted and modified throughout the Asia and Europe.  We can blame the Sumerian’s for not having enough time in the day.

180px-Geographic_coordinates_sphere.svg Another popular use for the base-60 system is in angular measure in our spherical coordinate system of the Earth.  A degree is divided into 60 minutes and a minute is divided into 60 seconds.  Our system of Latitudes and Longitudes is expressed in these terms.  With the popularity of geo-spatial and mapping tools such as Google Maps and Microsoft Live Maps, it has become important to be able to convert from degrees/minutes/seconds into a decimal notation and vice versa.

Example:

(49°30′02"N, 123°30′30")

 

49 degrees, 30 minutes, and 2 seconds by 123 degrees, 30 minutes, and 30 seconds

Below is a utilities class that I originally wrote for an astronomical observatory simulation application called StellarResults (which is available on codeplex).  This program would simulate observatories around the world and what astronomical objects they could see at a give time of day.  I soon realized that I needed to push this library down to a more basic level so that I could use it for other geo-spatial calculations such as working with geo-coded locations, or entering locations into a database.  Libraries like this will also be useful when working with the new spatial database features in Microsoft SQL Server 2008.

public static class GISUtilities
{
    #region Sexagesimal
    /// <summary>
    /// Converts from degrees, minues, seconds to a double.
    /// </summary>
    /// <param name="degrees">The degrees.</param>
    /// <param name="minutes">The minutes.</param>
    /// <param name="seconds">The seconds.</param>
    /// <returns></returns>
    public static double ConvertSexagesimalToDouble(
        int degrees,
        int minutes,
        int seconds)
    {
        return ((double)degrees % 360) + ((double)minutes / 60) + ((double)seconds / 3600);
    }

    /// <summary>
    /// Converts from degrees, minues, seconds to a string.
    /// </summary>
    /// <param name="degrees">The degrees.</param>
    /// <param name="minutes">The minutes.</param>
    /// <param name="seconds">The seconds.</param>
    /// <returns></returns>
    public static string ConvertSexagesimalToString(
        int degrees,
        int minutes,
        int seconds)
    {
        return String.Format(
            "{0}° {1}’ {2}”",
            degrees.ToString(),
            minutes.ToString(),
            seconds.ToString());
    }

    /// <summary>
    /// Converts from a double to degrees, minues, seconds.
    /// </summary>
    /// <param name="value">The value to convert.</param>
    /// <param name="degrees">The degrees.</param>
    /// <param name="minutes">The minutes.</param>
    /// <param name="seconds">The seconds.</param>
    public static void ConvertDoubleToSexagesimal(
        double value,
        out int degrees,
        out int minutes,
        out int seconds)
    {
        degrees = (int)value;
        minutes = (int)((value - degrees) * 60);
        seconds = (int)((value - degrees - (minutes / 60)) * 3600);
    }
    #endregion Sexagesimal

    #region HMS
    /// <summary>
    /// Converts from hours, minues, seconds to a double.
    /// </summary>
    /// <param name="hours">The hours.</param>
    /// <param name="minutes">The minutes.</param>
    /// <param name="seconds">The seconds.</param>
    /// <returns></returns>
    public static double ConvertHMSToDouble(
        int hours,
        int minutes,
        int seconds)
    {
        return ((double)hours % 360) * 15 + ((double)minutes / 60) * 15 + ((double)seconds / 3600) * 15;
    }

    /// <summary>
    /// Converts from hours, minues, seconds to a string.
    /// </summary>
    /// <param name="hours">The hours.</param>
    /// <param name="minutes">The minutes.</param>
    /// <param name="seconds">The seconds.</param>
    /// <returns></returns>
    public static string ConvertHMSToString(
        int hours,
        int minutes,
        int seconds)
    {
        return String.Format(
            "{0}h {1}m {2}s",
            hours.ToString(),
            minutes.ToString(),
            seconds.ToString());
    }

    /// <summary>
    /// Converts from a double to hours, minues, seconds.
    /// </summary>
    /// <param name="value">The value to convert.</param>
    /// <param name="hours">The hours.</param>
    /// <param name="minutes">The minutes.</param>
    /// <param name="seconds">The seconds.</param>
    public static void ConvertDoubleToHMS(
        double value,
        out int hours,
        out int minutes,
        out int seconds)
    {
        double totalseconds = value / 15 * 3600;

        hours = (int)Math.Truncate(totalseconds / 3600);
        minutes = (int)Math.Truncate((totalseconds - hours * 3600) / 60);
        seconds = (int)Math.Truncate(totalseconds - (hours * 3600) - (minutes * 60));
    }
    #endregion HMS
}
 

So a conversion from Latitude or Longitude to a double would look something like this:

double latitude = GISUtilities.ConvertSexagesimalToDouble(100, 34, 20);
 
There are also methods in this library to convert between hours/minutes/seconds as well as the degree/minutes/seconds primarily used in geo-spatial calculations.
 

kick it on DotNetKicks.com

 

Posted in .Net | 3 Comments »

IndyCodeCamp

Posted by Dan Rigsby on April 27th, 2008

Saturday April 26, 2008 ushered in the first IndyCodeCamp.  This event was designed to be a code camp for all languages, but morphed more into a .Net thing this year.  This may change in future events.  I would love to see the event stay mostly .Net focused, but offer at least one track for other languages such as Ruby, Python, etc.  This year we had over 400 people registered for an event that could only accommodate 250 people.  We had a great line up of speakers as well.  I was very anxious in the days leading up to the event.

On Saturday morning, I arrived at IndyCodeCamp around 7am.  The event started at 8am, but I wanted to be sure to get there early to meet with the staff, speakers, and friends.  Part of my job as Logistics Director of IndyNDA is “speaker support”.  So at events like this, it’s my job to make sure the speakers know what is going on and that they are taken care of.  Personally, I just love being able to hang out with all of these great guys and gals.  Anyway, when I got there, I found the building still locked and a number of people standing around outside.  It had been warm all week, but Mother Nature hit us with a cold front, and it was quite chilly standing outside of the building.  Building staff claimed it was a miscommunication, but were were able to get in the building around 7:30am.  Needless to say, it was a mad house trying to get everything set up.  We had expected to have time to setup sign in booths and tables, but the attendees were right behind us.  Things went a little chaotically up until the first session.

Overall the event went off well.  We had a couple of speakers cancel at the last minute, but we were able to fill in their spots.  Out of the 400 people we had registered, only about 170 showed up.  That is quite a drop off rate, but I think the lack of reminder emails and no iCal files, lead to a lot of people forgetting about the event or not thinking they were registered.  Our local Microsoft representatives Dave Bost and Larry Clarkin had family commitments (we understand guys), but Bill Steele was kind enough to make it down, speak at a couple of sessions, show off his new hud, and buy us pizza for lunch.

There were four rooms setup for sessions and one great room where the sponsers were setup and were the speakers could sit.  It was great meeting up with many of my speaker friends from Indiana, Ohio, Michigan, Kentucky, Tennessee, and Illinois.  It’s nice to see that we had people speaking from all of the surrounding states.  We did have a number of Audio/Video issues in the first couple of sessions, but things got worked out throughout the day and the attendees were patient.

I was fortunate enough to have 3 sessions at IndyCodeCamp.  I was a little worried when I saw that all 3 of them were back to back and that it meant about 4 hours of conversation, but my voice didn’t waver too much and I made it through.  Here are my comment about each session:

  • Agile Project Management with Scrum:  This was my first time performing this session and since this was a code camp, I didn’t think it would be accepted.  However, I had 30 people attend which was a lot more than I expected.  Everyone was very attentive and came with a lot of great questions!  I think the slide deck was good and filled up the time nicely.  I got great comments and some nice laughter at some of the “funnier” slides I put in.  I really hope I get a chance to do this session again in the future.  A couple of people afterwards even asked me about presenting this to people at their places of employment.
  • Introduction to Windows Communication Foundation: I have done this session a few times now, and it always seems to be a hit.  I was fortunate to have over 50 people attend which ended up being the most popular session of at IndyCodeCamp.  The session went off without a hitch and the modifications I made, helped keep the session more introductory for those who may be new to any kind of connected system development.  I do think I am going to add a couple of new slides to this deck over why we need services.
  • Intermediate Windows Communication Foundation: I wanted to discuss the Web Programming Mode, Duplexing, and Asynchronous Operations all in one session.  I hated the name that I gave the session, but I couldn’t think of anything better.  However, I really under estimated how much I can talk about a topic. In the future I will break this up into three self contained sessions.  The talk today went well though. and I had about 28 people attend. But I really had to rush a couple of the topics, and I felt that I lost the audience when I talked about Duplexing.  In my next Duplexing talk, I will have a lot more “lead up” slides to help introduce the topic to the audience.

Because my sessions ate up the 2nd half of the day, I didn’t get to attend any of the afternoon sessions. And during the first half of the day, the best I could do was to take a sampling of each of the sessions.  Overall, I think everyone did a good job.  A few sessions had some issues, but I hope that doesn’t scare the speakers away from speaking again in the future.  The comments I heard from the attendees though were all positive.

After the event of a few of the speakers made it down to Champp’s for a little after-party.  Everyone was invited, but only some of the speakers showed up.  I hope in the future, more attendees will make to out.  It’s important to interact with your peers when possible.

I want to thank all of the speakers and staff for making this event a success.  I hope to see many of you again next year!  And to those who read this blog regularly, I apologize for the lack of posts this past week.  I have 4 great Wcf posts in draft state at the moment, but I spent most of time this week preparing my sessions for this event.

The materials from my sessions can be found here:

Posted in Community | 7 Comments »

New Webcast: CSS Support in Visual Studio 2008

Posted by Dan Rigsby on April 22nd, 2008

I have a new 7 min 50 sec training webcast out over the CSS Support in Visual Studio 2008.  The video is available through JupiterMedia and can be viewed at http://www.internet.com/video/. Just look for the "Developer Video" titled "CSS in Visual Studio 2008".  Direct links are:

http://www.internet.com/video/?bcpid=1431564240&bclid=1433966034&bctid=1499645387
http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1499645387

Posted in Visual Studio, Webcast | 1 Comment »