Posts tagged: Coding

Difference Between System.* and Microsoft.*

Scott Hanselman has been on a roll lately with his posts and twits. Today he writes “Question to .NET Programmers: what is the difference between the System.* and Microsoft.* namespaces?”

This is an important question and one that I can’t say I truly know the answer too. I had always assumed it was based on either the idea that System.* was part of the core framework where as Microsoft.* was for Microsoft specific functionality. For instance, it would be expected that much or all of the System.* functionality would be replicated on many other platforms where as Microsoft.* would not.

Certainly this is true for the very basic feature set such as the common types but it is not true for System.Windows.Forms. Which begs the question that I always wondered: why is Windows.Forms where it is? I always expected it to be in Microsoft.Windows.Forms as it is a Windows specific implementation based on many of the Win32 controls.

Weighing In On EIPL

EIPL, or English as the International Programmer Language, seems to have been brought up again around the blogosphere. It seems to have started on Scott Hanselman’s blog with a comment stating “If you don’t know English, you’re not a programmer!” Of course it does not end there: Bjoern writes about it in a blog post saying “In regard to translated documentation: I wouldn’t use it. Maybe it is because I learned programming during the dark ages when everything development related was English – it is even possible to claim I learned English through such documentation – or maybe the early days of localizations spoiled my conception of its quality.” And finally it appears here with generally the same attitude: that English is quickly becoming or should become the official language of programmers.

I believe that English should not be the official language. It is nice to know that variable names will generally be in a language I can understand, however I believe that this can be fixed in the future with language independent coding taking the place of what we do not. Visual Studio is already an incredibly powerful tool and it wouldn’t surprise me if within a decade or two it would begin to support the dynamic localization of variable names. It would be ignorant of me to demand or expect all source code to be in English.

However, the one caveat here is that non-English speaking programmers or wannabes should most likely learn English simply because features like the one mentioned above will take many years to come about and perfect. Furthermore, it can be said that English is somewhat of an international language. In Western cultures it is very easy to find someone who speaks English and it is quickly spreading throughout the tiny corners of the world. For evidence of this, look no further than the Olympics which was conducted in (I believe) three languages. If memory serves me correctly it was English, French and Chinese. This was due to the host country (China) and the IOC (Official Languages: English, French).

While on the subject of languages there is another potential problem. While languages based on Latin or in similar style (left to right) can be well understood by an immense amount of people in the community, vertical and right to left languages that feature non-alphanumeric characters can cause more problems than just being able to understand the meaning. I can’t imagine what source code written in Chinese or Japanese would look like.

The Difference Between New and Override

This is a fundamental topic in C# and if you plan to do any development at all with the language you need to know this. Override is used for changing the behavior of the original type’s method or property. The new keyword, in this case, is used for scratching the existing behavior but only in the current type. To better explain this, consider the following code.

1
2
3
4
5
6
7
8
9
10
11
public class Foo{
     public virtual void Print(){
          Console.WriteLine("I am a Foo!");
     }
}
 
public class Bar{
     public override void Print(){
          Console.WriteLine("I am a Bar!");
     }
}

If we declare a Bar and cast it to a Foo in the above code, we will still get “I am a Bar!” when we invoke the Print method. However, if we change the code to the following things will get messed up a bit.

1
2
3
4
5
6
7
8
9
10
11
public class Foo{
     public void Print(){
          Console.WriteLine("I am a Foo!");
     }
}
 
public class Bar{
     public new void Print(){
          Console.WriteLine("I am a Bar!");
     }
}

If we instantiate a Bar, we will get the new functionality. However, if we cast that Bar object into a Foo, we will get the implementation provided by the Foo. So be sure of what you are using and why!

Hosting A Page Inside A SharePoint Page

One of the tasks I had recently was to get not only a web page into a SharePoint page but also pass in parameters from the Query String. Let’s say I am going to create the page at http://localhost/sharepoint/mypage.aspx in a normal way. In order to host a page inside that SharePoint page, we can use a Page Viewer Web Part, but this limits what can be done. Instead, we can create a custom web part to do the work…

Please excuse me if the code isn’t exactly correct. I do not have the code in front of me right now and will update it when I do.


1
2
3
4
5
6
7
8
9
10
11
12
13
public class CustomWebPart : WebPart {
    public override void Render(HtmlTextWriter writer){
        string rawUrl = Context.Request.Url.OriginalString;
        int index = rawUrl.IndexOf("?");
 
        string query = String.Empty;
        if(index != -1) query = rawUrl.Substring(index);
 
        writer.Write(
            "<iframe src='http://localhost/sharepoint/myOtherPage.aspx" + query + "' width='100%' height='765px'/>"
        );
    }
}

WordPress Themes