Just sharing some of my inconsequential lunch conversations with you... RSS  

Wednesday, February 24, 2010

Real-World Relativity: GPS

Einstein’s theory of relativity is not as abstract as we may think. An example we often use is GPS, a system that as we know uses a method called trilateration, a method that depends on the precision of the satellite internal clocks to calculate absolute positions.

The problem is that time is relative, and though we all recognize it, probably most of us imagine that we needed extreme conditions to make it happen (I was one of them). But all we need is a satellite at about 20.000 km from the ground, orbiting at about 14.000 km/h and a process requiring 20 to 30 nanoseconds precision, and there you have it, you’ll have to take the theories of relativity into account:

Because an observer on the ground sees the satellites in motion relative to them, Special Relativity predicts that we should see their clocks ticking more slowly (see the Special Relativity lecture). Special Relativity predicts that the on-board atomic clocks on the satellites should fall behind clocks on the ground by about 7 microseconds per day because of the slower ticking rate due to the time dilation effect of their relative motion.

Further, the satellites are in orbits high above the Earth, where the curvature of spacetime due to the Earth's mass is less than it is at the Earth's surface. A prediction of General Relativity is that clocks closer to a massive object will seem to tick more slowly than those located further away (see the Black Holes lecture). As such, when viewed from the surface of the Earth, the clocks on the satellites appear to be ticking faster than identical clocks on the ground. A calculation using General Relativity predicts that the clocks in each GPS satellite should get ahead of ground-based clocks by 45 microseconds per day.

The combination of these two relativitic effects means that the clocks on-board each satellite should tick faster than identical clocks on the ground by about 38 microseconds per day (45-7=38)! This sounds small, but the high-precision required of the GPS system requires nanosecond accuracy, and 38 microseconds is 38,000 nanoseconds. If these effects were not properly taken into account, a navigational fix based on the GPS constellation would be false after only 2 minutes, and errors in global positions would continue to accumulate at a rate of about 10 kilometers each day!

Cool article! But you know what’s cooler? That these theories were almost like pure creation: it’s not like Einstein developed a GPS system, failed to make it work, to finally theorize: what if time would be relative? Naturally he did start from an empty canvas and no purpose at all, but in face of the problem the scientific community had identified, his leap was so extraordinary that after 100 years we still find it hard to explain. Thank you, Albert.

Thursday, February 18, 2010

Outlook Social Connector

The all-new Outlook Social Connector connects you to the social and business networks you use, including Microsoft SharePoint, Windows Live, and other popular third-party sites, so you can get more information and stay in touch with the people in your network without leaving Outlook.

For now we only support LinkedIn, but Facebook, Windows Live and mySpace is comming soon. On problem, though, is the lack of 64 bit support.

 

Here’s a sample:

Facebook for Outlook

 

And here’s my sample on a 64 bit box (disconnected from LinkedIn):

image

Tuesday, February 16, 2010

Windows Phone 7 Series

Let’s start with the obvious: once more, Microsoft had to get a new name for it’s mobile OS, so their brand name is basically: worthless.

I haven’t tried it yet, but from what I’ve been reading:

  • Cool: rewritten from scratch. Or branched from Zune. About time!
  • Cool: Leveraging product application from Zune to XBox.
  • Not so cool: IE escaped this rewriting. Something we’ll regret on a near future.
  • Unknown: SDK and backward compatibility?

Hope to get one - probably only on 2011. Until then, I’ll continue to suffer with WM6.5.

Wednesday, February 10, 2010

AutoMapper

Object to object mapping is a tedious operation. And lately we all have a bunch to map. Here are the usual suspects:

  • MVC (Domain model to view model)
  • SOA (Domain model to data contracts)

Generally: whenever the same model payload must traverse boundaries that need to keep decoupled from each other. And here is AutoMapper to the rescue:

What is AutoMapper?

AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. What makes AutoMapper interesting is that it provides some interesting conventions to take the dirty work out of figuring out how to map type A to type B. As long as type B follows AutoMapper's established convention, almost zero configuration is needed to map two types.

Why use AutoMapper?

Mapping code is boring. Testing mapping code is even more boring. AutoMapper provides simple configuration of types, as well as simple testing of mappings. The real question may be "why use object-object mapping?" Mapping can occur in many places in an application, but mostly in the boundaries between layers, such as between the UI/Domain layers, or Service/Domain layers. Concerns of one layer often conflict with concerns in another, so object-object mapping leads to segregated models, where concerns for each layer can affect only types in that layer.

How do I use AutoMapper?

First, you need both a source and destination type to work with. The destination type's design can be influenced by the layer in which it lives, but AutoMapper works best as long as the names of the members match up to the source type's members. If you have a source member called "FirstName", this will automatically be mapped to a destination member with the name "FirstName". AutoMapper also supports Flattening, which can get rid of all those pesky null reference exceptions you might encounter along the way.
Once you have your types, and a reference to AutoMapper, you can create a map for the two types.
Mapper.CreateMap<Order, OrderDto>();
The type on the left is the source type, and the type on the right is the destination type. To perform a mapping, use the Map method.
OrderDto dto = Mapper.Map<Order, OrderDto>(order);
AutoMapper also has non-generic versions of these methods, for those cases where you might not know the type at compile time.

Where do I configure AutoMapper?

If you're using the static Mapper method, configuration only needs to happen once per AppDomain. That means the best place to put the configuration code is in application startup, such as the Global.asax file for ASP.NET applications. Typically, the configuration bootstrapper class is in its own class, and this bootstrapper class is called from the startup method.

How do I test my mappings?

To test your mappings, you need to create a test that does two things:
  • Call your bootstrapper class to create all the mappings
  • Call Mapper.AssertConfigurationIsValid
Here's an example:
AutoMapperConfiguration.Configure();

Mapper.AssertConfigurationIsValid();


Can I see a demo?



Check out the dnrTV episode on AutoMapper: http://www.dnrtv.com/default.aspx?showNum=155




So AutoMapper is a convention-based object-object mapper in .NET. It follows the Convention over configuration principle, which seeks to infer as many rules it can from convention, avoiding unnecessary configuration. Some obvious examples of such usage are clear on frameworks like Ruby on Rails and Spring. It can also be read under the DRY principle – don’t repeat yourself!

Monday, February 08, 2010

And today’s .NET least asked features goes to…

… complex numbers! I was browsing over (now old) new features, and I came across this beauty: complex numbers!

I must confess, except for some geeky fractal computations ages ago when it was geek to calculate Mandelbrot sets, long before .NET, I’ve never really needed to handle complex numbers… But ok, there you have it. Cool.

Long since I’ve been introduced to numbers with this properties, I had to seek help from Wikipedia in order to get a reason for using them. Here they are:

Ok, it checks: not in my daily work task list :)

Thursday, February 04, 2010

Trying out a new SoftPhone

image

I’m trying out a new softphone – I’m trying to ditch X-Lite. Here a cool option: 3CX. And yes, it looks like an iPhone, cool!

Wednesday, February 03, 2010

Refactor :my => 'code'

Here’s a cool site dedicated to code refactoring: http://refactormycode.com/. It’s like a forum for code refactoring on a concrete basis (code posted, refactoring suggestions are posted back).

Thanks for the link, Cab_Ux.

Development Catharsis :: Copyright 2006 Mário Romano