25 June, 2010

[Cool Tool] Assembly minifier tool

[Cool Tool] Assembly minifier tool: "
If you are using Silverlight controls from the Telerik suite, you’re going to love this.
Telerik provide a new free tool to help reduce the size of your Silverlight xap. The Telerik Assembly Minifier can be found here:
http://minifier.telerik.com/
From the website: “Telerik Assembly Minifier is a tool that lets you extract only the controls’ classes and resources you need to use in your application development, thus significantly reducing the size of the assemblies. Using the Assembly Minifier you will achieve significantly better loading time when the Silverlight XAP files containing the minified (optimized) assemblies are to be loaded on the client side.”
Note: this apply to Telerik assemblies only (for now).

I decided to give it a try and create a fresh new Silverlight 4 app then insert a Telerik GridView in a page. VS automatically adds reference to these assemblies:
  • Telerik.Windows.Data.dll
  • Telerik.Windows.Controls.Input.dll
  • Telerik.Windows.Controls.GridView.dll
  • Telerik.Windows.Controls.dll

That’s 645KB (compressed) added in your xap file, ouch!

Now let’s add a CoverFlow and a Scheduler controls in my app. This adds 2 more assemblies in the resulting xap:
  • Telerik.Windows.Controls.Scheduler.dll
  • Telerik.Windows.Controls.Navigation.dll

That’s an additional 413KB in the xap.

At that point my xap file is 1.2MB, and my app is quite empty, most of the size is coming from the Telerik assemblies. Great features comes with a price, right ?

Now let’s try the Assembly Minifier tool.
Go to http://minifier.telerik.com/ and upload the Telerik assemblies used in your app.

Then I select the controls to be extracted (GridView, CoverFlow and Scheduler here):

Now I can click on the “Extract” button to download the compressed assemblies and reference them in my app (I removed the originals first).
After recompiling my xap is now 845KB, that’s 32% off.
So finally for my very specific test (empty Silverlight 4 app with 3 Telerik controls: GridView, CoverFlow and Scheduler) I get this result:
xap file size
Before
After
1.2MB
845KB
[32% gain]
Overall this is good, as always Telerik innovate in new tools and it’s nice to see them answering concern like xap files size. But to me the whole process to manually choose your controls and manually upload and manually replace dll is totally inefficient for now. The tool is still beta (and free!) so I do not complain, I just hope to see more features and a better integration in VS later. In a perfect world a VS add-in would do the job automatically when I build in release mode.
Note the tool is working properly, but the way to replace your dll in VS is not (always grab the old replaced dll). You can find some tips to fix it but it is definitely painful for now. Hope VS will provide an easier way to handle this in the future, or maybe Telerik to create a VS addin or something...
Waiting for that you’ll find great help here:
http://www.telerik.com/community/forums/silverlight/assembly-minifier.aspx
"

24 June, 2010

Testing Email Sending

Testing Email Sending: "
Recently I learned a couple of interesting things related to sending emails. One doesnt relate to .NET at all, so if youre a developer and you want to easily be able to test whether or not emails are working correctly in your application without actually sending them and/or installing a real SMTP server on your machine, pay attention. You can grab the smtp4dev application from codeplex, which will listen for SMTP emails and log them for you (and will even pop-up from the system tray to notify you when it receives them) but it will never send them. Heres what the notification looks like:
image
The other interesting tidbit about emails that is specific to .NET is that the MailMessage class is IDisposable. I never realized that before, but I noticed it while reading through the Ben Watsons C# 4 How To book I picked up at TechEd last week (which is done cookbook style and has a ton of useful info in it). Looking at the MailMessages Dispose() method in Reflector reveals that it only really matters if youre working with AlternateViews or Attachments (this.bodyView is also of type AlternateView):
image
All the same, you should get in the habit of wrapping your calls to MailMessage in a using() { } block. Heres some sample code showing how I would typically work with MailMessage:
Bad Example (dont cut and paste and use):
string fromAddress = "nobody@somewhere.com";



string toAddress = "somebody@somewhere.com";



string subject = "Test Message from IDisposable";



string body = "This is the body.";



var myMessage = new MailMessage(fromAddress, toAddress, subject, body);






var myClient = new SmtpClient("localhost");



myClient.Send(myMessage);




And heres how that code would look once its properly set up using IDisposable / using:


Good Example (use this one!):




string fromAddress = "nobody@somewhere.com";



string toAddress = "somebody@somewhere.com";



string subject = "Test Message from IDisposable";



string body = "This is the body.";






using(var myMessage = new MailMessage(fromAddress, toAddress, subject, body))



using(var myClient = new SmtpClient("localhost"))



{



myClient.Send(myMessage);                



}






Note also that SmtpClient is also IDisposable, and that you can stack your using() statements without introducing extra { } when you have instances where you need to work with several Disposable objects (like in this case).


Note that if you run Code Analysis in VS2010 (not sure which version you have to have right click on a project in your solution explorer and look for Analyze Code) you will get warnings for any IDisposable classes youre using outside of using statements, like these:


image




Summary


Sometimes things you dont expect to be Disposable are. Its good to run some code analysis tools from time to time to help find things like this. Visual studio has some nice static analysis built into some versions, or you can use less expensive tools like Fx Cop or Nitriq.

16 June, 2010

How to Answer a Stupid Interview Question the Right Way

How to Answer a Stupid Interview Question the Right Way: " By

Have you ever been asked a stupid question during an interview; one that seemed to have no relation to the job responsibilities at all? Tech people are often caught off-guard by these apparently irrelevant questions, but there is a way you can turn these to your favor. Here is one idea.

While chatting with a couple of folks between sessions at SQLSaturday 43 last weekend, one of them expressed frustration over a seemingly ridiculous and trivial question that she was asked during an interview, and she believes it cost her the job opportunity. The question, as I remember it being described was, “What is the largest byte measurement?”. The candidate made up a guess (“zetabyte”) during the interview, which is actually closer than she may have realized. According to Wikipedia, there is a measurement known as zettabyte which is 10^21, and the largest one listed there is yottabyte at 10^24.

My first reaction to this question was, “That’s just a hiring manager that doesn’t really know what they’re looking for in a candidate. Furthermore, this tells me that this manager really does not understand how to build a team.” In most companies, team interaction is more important than uber-knowledge. I didn’t ask, but this could also be another geek on the team trying to establish their Alpha-Geek stature. I suppose that there are a few, very few, companies that can build their businesses on hiring only the extreme alpha-geeks, but that certainly does not represent the majority of businesses in America.

My friend who was there suggested that the appropriate response to this silly question would be, “And how does this apply to the work I will be doing?” Of course this is an understandable response when you’re frustrated because you know you can handle the technical aspects of the job, and it seems like the interviewer is just being silly. But it is also a direct challenge, which may not be the best approach in interviewing. I do have to admit, though, that there are those folks who just won’t respect you until you do challenge them, but again, I don’t think that is the majority.

So after some thought, here is my suggestion: “Well, I know that there are petabytes and exabytes and things even larger than that, but I haven’t been keeping up on my list of Greek prefixes that have not yet been used, so I would have to look up the exact answer if you need it. However, I have worked with databases as large as 30 Terabytes. How big are the largest databases here at X Corporation?” Perhaps with a follow-up of, “Typically, what I have seen in companies that have databases of your size, is that the three biggest challenges they face are: A, B, and C. What would you say are the top 3 concerns that you would like the person you hire to be able to address?…Here is how I have dealt with those concerns in the past (or ‘Here is how I would tackle those issues for you…’).”

Wait! What just happened?! We took a seemingly irrelevant and frustrating question and turned it around into an opportunity to highlight our relevant skills and guide the conversation back in a direction more to our liking and benefit. In more generic terms, here is what we did:

  1. Admit that you don’t know the specific answer off the top of your head, but can get it if it’s truly important to the company. Maybe for some reason it really is important to them.
  2. Mention something similar or related that you do know, reassuring them that you do have some knowledge in that subject area.
  3. Draw a parallel to your past work experience.
  4. Ask follow-up questions about the company’s specific needs and discuss how you can fulfill those.

This type of thing requires practice and some forethought. I didn’t come up with this answer until a day later, which is too late when you’re interviewing. I still think it is silly for an interviewer to ask something like that, but at least this is one way to spin it to your advantage while you consider whether you really want to work for someone who would ask a thing like that. Remember, interviewing is a two-way process. You’re deciding whether you want to work there just as much as they are deciding whether they want you.

There is always the possibility that this was a calculated maneuver on the part of the hiring manager just to see how quickly you think on your feet and how you handle stupid questions. Maybe he knows something about the work environment and he’s trying to gauge whether you’ll actually fit in okay. And if that’s the case, then the above response still works quite well.