Monday, April 28, 2008

Interview Questions - Fibonacci

I found a interesting interview questions that is most likely a bit over done, but I still like it, it reminds me of my intro to programming classes from back in the day, which for me was only about 5 years ago. This one concerns the Fibonacci Numbers. The problem is write the Fibonacci Sequence without Recursion. With Recursion the fib sequence is relatively easy:

public static int GetFibValueRecursive(int place)
 {
     if (place <= 0) return 0;
     if (place == 1) return 1;
     return GetFibValueRecursive(place - 1) + GetFibValueRecursive(place - 2);
 }

First step to this problem I would write a test to make sure my code is correctly solving the problem.

[Test]
 public void GetFibValue_GivenPlace_ReturnCorrectValue()
 {
     Assert.AreEqual(0, Fibonacci.GetFibValue(-1));
     Assert.AreEqual(0, Fibonacci.GetFibValue(0));
     Assert.AreEqual(1, Fibonacci.GetFibValue(1));
     Assert.AreEqual(1, Fibonacci.GetFibValue(2));
     Assert.AreEqual(34, Fibonacci.GetFibValue(9));
     Assert.AreEqual(144, Fibonacci.GetFibValue(12));           
 }
Then I would write the code.
public static int GetFibValue(int place)
 {
     if (place <= 0) return 0;
     int previous = -1;
     int result = 1;
     for (int i = 0; i <= place; ++i)
     {
         int sum = result + previous;
         previous = result;
         result = sum;
     }
     return result;
 }

Bam! The Fibonacci Sequence without recursion of course if you wanted more than just a value for given place I would write it a little different perhaps return a list of values instead of a single value.

FibSequence.zip (71.66 KB)
#     Comments [0]  
kick it on DotNetKicks.com
 Thursday, April 10, 2008

General C# Questions

One of my career goals as a developer is to work for Microsoft, now that I have graduated school and have 2 years of development experience I am going to start actively perusing this goal. The word on the street is that the interview process for Microsoft positions is not easy. To prep for interviews I am trolling the web looking for possible interview questions and posting my answers. To start off I found these general questions on C#.

 

  1. What is metadata? What information is stored in Metadata?

Metadata describes every type and member defined in your code in a language-neutral manner. It stores the description of the assembly, description of types, and the attributes

 

  1. What are some of the Tables stored in metadata?

Each metadata table holds information about the elements of your program. For example, one metadata table describes the classes in your code, another table describes the fields, and so on. If you have ten classes in your code, the class table will have tens rows, one for each class. Metadata tables reference other tables and heaps. For example, the metadata table for classes references the table for methods.

 

  1. What are the two basic kinds of types in .net framework?

Two basic kinds of types are value types and reference types.

 

  1. What is boxing and unboxing?

Boxing a value type packages it inside an instance of the Object reference type, unboxing is the reverse.

 

  1. What class does all classes implicitly inherited from?

System.Object

 

  1. What is namespace, assembly?

Namespace declares a scope that lets you organize code and gives you a way to create globally unique types. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality.

 

  1. What is global assembly cache, what is the purpose?

The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.

 

  1. What are Primitive types?

Any data types directly supported by the compiler are called primitive types. Primitive types map directly to types that exist in the base class library.

 

  1. What is reflection?

Reflection allows the inspection of metadata in a PE file and late binding (run time) to types and their members.

           

  1. What is a delegate?

A delegate is a type that references a method with the same signature.

 

  1. Describe the accessibility modifier “protected internal”.

Access is limited to current project or types derived from the containing class.

 

  1. What does the term immutable mean?

It's simply a class that’s state does not change after it was initialized.

 

  1. What’s the difference between System.String and System.Text.StringBuilder classes?

StringBuilder class represents a mutable string of characters. System.String is immutable.

 

  1. What’s the advantage of using System.Text.StringBuilder over System.String?

A StringBuilder object is preferable for a concatenation operation if an arbitrary number of strings are concatenated; for example, if a loop concatenates a random number of strings of user input.

 

  1. Can you store multiple data types in System.Array?

No, array objects with the same array type share the same Type object.

 

  1. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

CopyTo() is a deep copy that copies the values. Clone() is a shallow copy that copies only the elements of the Array.

 

  1. What’s the .NET collection class that allows an element to be accessed using a unique key?

System.Collections.Hashtable or System.Collections.Generic.Dictionary, I prefer the Generic Dictionary it is faster.

  1. Will the finally block get executed if an exception has not occurred?

Yes

 

  1. Can multiple catch blocks be executed for a single try statement?

No, the order of the catch clauses is important because the catch clauses are examined in order. Catch the more specific exceptions before the less specific ones.

#     Comments [0]  
kick it on DotNetKicks.com
 Monday, March 31, 2008

DotNetNuke Upgrade - My Rant

I have been using DotNetNuke for a year or more now mostly for personal fun projects but I have setup a site for a family business using DNN, nothing explosive and shinny but it has served its purpose. I manage 2 different DotNetNuke installations and I have to say upgrading DNN application (not the modules) is scary. I have yet to do it successfully on my first try. Here are my steps to failure:

1. Backup my SQL Server as well as my site files. This is the most important step because the fallowing steps are sure to fail.

2. Download the latest install or upgrade package for your DotNetNuke application. I have tried upgrading using both the upgrade and install packages with equal success err failure... successful failure?

3. Create an app_offline.htm with some generic text stating that you are doing maintenance on the site blah blah blah.

4. Rename your current web.config to web.config.old

5. Copy contents of the install/upgrade package to your DNN application folder.

6. Rename release.config to web.config.

7. Merge your old web.config with the new web.config. The areas to merge are: Connection Strings, MachineKey, and the codeSubDirectories. I also like to set AutoUpgrade key too false so nobody but me will trigger the installation.

8. Now I navigate to [Domain Name]/install/install.aspx

9. After I watch the list of Successful, or sometimes on Friday and the moon is full I will get a failure, I navigate to my home page of my DNN application to view the wonderful yellow screen. The error displayed is usually different every time or a different flavor of the same variety "Object Null Reference" being my favorite for its descriptiveness [insert sarcasm].

The good news and one of the reasons that I like DNN is it has a great community and I have fixed every problem with the help of people on the forums. Also once it is updated and running it is a solid application and very easy to extend and write custom modules for. I just wish for a one click update and BAM you are getting your "real" work completed. Anyway my SQL Server and root files are done restoring, time for try number two.

Note: Currently DotNetNuke was on version 4.8.2 when I wrote this.

Here are a few tutorials on upgrading your installation: 1 2

#     Comments [1]  
kick it on DotNetKicks.com
 Thursday, March 20, 2008

Guild Wars vs Lord of the Rings Online vs World of Warcraft

This post is just some vague rambling on game mechanics and character generation I am only writing it because I graduated finally with my BS degree  and I have declaired this month of the game.

I have been trying to nail down the most important part of a character in LOTRO. So in order to do this I have been comparing it to the other MMOs that I have played.

World of Warcraft: Gear gear gear. Basically everyone in the same class has the same amount of points to spend on the same skills/traits. The only thing left to diversify your character was the gear. This makes for a very addicting game specially when most of the good gear is on "X" mob located at the End of "X" dungeon and it only has a 5% drop rate and you need 15 people to get it. I think I did Upper Black Rock Spire 30+ times trying to get my Valor chest plate. That instance was about an  hour long not to mention it took about 30mins just to get a group, so I probly spent 30+ hours for one piece of equipment which I never got. Sounds like bitching but I still had fun doing it.

Guild Wars: Skill Combos. The best description I have herd for character development in Guild Wars was comparing it to a Collectable Card Game (CCG) like Magic. The Equipment was very easy to Acquire and did not give your character a major advantage. It was all about the skills and there where a million and once at the level cap everyone had the same amount of Attribute points (i.e. str, int). It was basically trial and error trying to get a cool combination of skills for the role you wanted to accomplish. You built your character like you would build a CCG deck you had 5 skills to pick out of a few hundred then adjust your gear and attributes to match the skills gimmick you where going for. It was very fun game pvp was 100x more balanced than wow and was based more on your skills instead of I have been to MC 200 times so I have the current best gear. But it didn’t have the same social feel to it that wow did, I didn’t randomly run into the guy I use to grind with at level 15 or that retarded healer I always got stuck with when grinding UBS.

LOTRO: Lord of the rings characters are driven with traits the gear is important but it comes second. The traits are acquired by grinding mobs, doing x number of quests in an area, exploring regions, or given in quest rewards. Some traits are available to everyone, some only to a given Race, some only for given class. Gear is pretty easy to come by compared to WoW. The best gear is acquired through quests, crafting, or Reputation grinding. In the end when you are at the level cap it all comes down to if you can play, all players are diverse in there equipment and build but more or less equally effective (unless you are retarded or cant read English) there isn’t much of an Elitist factor.

Likes/Dislikes

World of Warcraft Likes: Because of the gear driven nature the economy for WOW was HOT. The Auction House was always on fire, it was a game in its self buying low selling high. Also It was really rewarding once you finally got that set of armor or that kick ass weapon you have been trying to get for the past month or two.

World of Warcraft Dislikes: Competitive/Elitist nature. You can tell from a mile off who is the noob and who is the shit this was a turn off for me because I am not online 24 hours a day but I am competitive it was a hard pill to swallow knowing I couldn’t enjoy all aspects of the game because I was on the more casual side of the players. Casual meaning I played at least 4 hours a day for over a year! There isn’t really an engaging story line.

Guild Wars Likes: It has a story! The level grind is really easy or non existent if you just want to pvp. Finding and capturing skill is fun. You can change your character play style at a whim given the role you want be fulfill.

Guild Wars Dislikes: Being that it isn’t really a Full MMORPG it is missing some of the basics like an Auction House and the ability to link Items in chat. I also like having some non-instanced areas that you can play in. It can be fun to randomly run into some one and group up.

LOTRO Likes: I like the story, the middle earth lore, engaging environments. It’s full of non essential fluff that has no other purpose than just being fun.  It’s a very casual player friendly game. I really love just exploring in this game I have had some of the best experiences I have ever had in an mmo just wondering around in this game.

LOTRO Dislikes: PVP kind of sucks, the auction house is not really active and deed grinding can get old. Other than that it’s my favorite so far.

#     Comments [0]  
kick it on DotNetKicks.com
 Saturday, February 02, 2008

System.Data.EvaluateException

Problem: You are using Select Method to retrieve rows from a typed DataTable and you keep getting the fallowing exception:

 System.Data.EvaluateException: Cannot perform '=' operation on System.String and System.Int32.

This isn't the most helpful error message.

Solution: You are missing hyphens.

Example:

Wrong:

CustomerRow[] rows = Select(string.Format("LastName = {0}", LastName)) as CustomerRow[];

Right:

CustomerRow[] rows = Select(string.Format("LastName = '{0}'", LastName)) as CustomerRow[];

#     Comments [0]  
kick it on DotNetKicks.com
 Monday, January 28, 2008

Post Seattle Code Camp

I spent my weekend attending Seattle code camp sessions. I learned a lot, but one of the biggest things I learned is how much I still don't know. My experience as a developer is limited I have yet to reach 2 years developing professionally and I am still in school currently working on my last quarter for my BS. I like to think that I am a good developer but speaking to people at the code camp is a nice ego check and I still have a long way to go before I can reach the status of elite alpha geek. My goals as a developer this year is to really dive into WCF and to study the code put out by the Patterns & Practices guys at Microsoft, specifically the Enterprise Library and Smart Client. What I really need is a chip I can insert behind my ear and just download the knowledge and experience I need, I cant seem to consume information fast enough otherwise.

One thing I would like to know is the process of how other people obtain deep knowledge of a subject not just an overview.  I am open to opinions please give me your 2 cents by Email Aaron@thesprage.com or leave a comment.

#     Comments [0]  
kick it on DotNetKicks.com
 Tuesday, January 15, 2008

Seattle Code Camp

Seattle Code Camp on Jan. 26th from what I hear it is a little smaller than most but seems to have some good content. The schedule includes speakers such as William (Bill) Vaughn and Phil Haack. Most of the tracks covered will pertain to .Net but there are a few Java sessions as well.

The following sessions look interesting to me:
26th
Rethinking Unit Testing: xUnit.net
Data Enhancements in Visual Studio 2008
Windows Application Enhancements in Visual Studio 2008
Visual Studio Reporting
27th
An Introduction to Windows Communication Foundation
Black Belt DSA, building Duplex Agents
The Web via WCF
LINQ Overview

#     Comments [0]  
kick it on DotNetKicks.com
 Thursday, January 10, 2008

using Statement

The using Statement is simply syntax sugar for a try finally block. If you instantiate an object that implements IDisposable you can make your code look cleaner with the key word using.
Example:
StreamWriter sw = File.CreateText(filePath)
try
{
  sw.Write(someText);
}
finally
{
  sw.Dispose();
}
The above block works the same as:
using(StreamWriter sw = File.CreateText(filePath))
{
  sw.Write(someText);
}
More Info:
MSDN

#     Comments [0]  
kick it on DotNetKicks.com