Sunday, January 10, 2010

Does Learning Assembly Language Matter Anymore?

When I started out to teach myself how to program I was always a bit bewildered by assembly language. I often looked at example code from online forums and starred at strange syntax such as this:

mov EAX, [EBP+8]
lea EDS, EAX

I thought '”How can you possibly write software using this stuff?”. Obviously I was being naive since compiling a Visual Basic, or C++ Builder application (my two favorite development tools at the time – others included PowerBASIC) ultimately was generating exactly this “stuff” which the CPU could make use of. As I became more proficient as a programmer, I noticed that I was looking more and more at assembly language code during my debugging sessions. Very often in the C++ Builder IDE I would be watching the values of the EAX and ECX registers, so that I could see the return value of a function or the current loop index value. Little did I know that I was starting to appreciate more the power of this language and what could be achieved.

Back in the early 2000’s I downloaded MASM32 which is a Microsoft assembler and RadASM, a great IDE for writing assembler code. With those tools I was able to write very simple assembler stuff, mainly DLL files that I could use with my Visual Basic 6 applications. It was so cool to see my VB6 code call an assembler routine, passing it a string that was displayed in a message box – a message box created in pure assembly code!! (I guess you had to be there :) What I was learning by doing this was how different calling conventions worked, how to build a DLL file using the assembly source and static library references. By passing a parameter from my VB code, I had to learn how to navigate a stack frame by using the ESP and EBP registers to get to the parameter’s address and grab its content in order for MessageBox to use it. I learned that:

mov EAX, [EBP+8]

actually meant “move the contents of memory address EBP+8 into the register EAX – in other words dereferencing a memory address. Having done a fair amount of C/C++ programming and using pointers, I was getting under the hood experience of how pointers worked at the assembler level. This actually helped me understand pointers better.

OK, so what am I getting at here?

In this day and age of managed runtimes and virtual machines, .NET languages, PHP, Perl, PowerShell, etc, some developers might be asking themselves “what’s the point of learning assembler? It’s not like I’m ever going to use it!”. That might very well be the case, but bear in mind this thought – without good assembly language developers, there would be no operating systems. Let me explain. Taking into account Windows and Linux for example, the vast majority of the codebase for these OS’s are written in C/C++. I would place a very large bet that a small percentage of the code is written in assembler. Assembler code must exist somewhere in the OS since talking directly to  hardware would not be possible. Without those hardcore assembler developers, who’s going to look after this code? If there’s no new talent on the horizon, that would be a deficit to the OS developers who rely on assembler programmers who can churn out this low-level communications code which is vital for the OS’s existence.

Take computer games, there’s bound to be a lot of assembler code in the source for computer games – for example, code to optimize the graphics algorithms so that the frame rate can be really high. A lot of games are written in C/C++ but nothing beats assembler for pure speed. Also you sometimes can’t as easily take advantage of CPU specific instructions from a higher level language, only coding in assembler can give you access to those instructions.

One of the most important areas where assembly language experience counts a lot is crash dump analysis. In my early years I would often see a BSOD and wonder “how can you tell what’s broken just by looking at this crap?!… What’s a bugcheck and how what’s this stack frame rubbish?” Now things are different. I’ve been reading blogs such as Crash Dump Analysis and the NT Debugging blog to help me understand how to analyze and interpret the information in dump files. I’ve also taught myself how to use WinDbg which is a free debugger for Windows. I’ve spent a lot of time recently working with SharePoint 2007, and believe or not, having WinDbg and assembly language experience has come in very handy! How? Well, SharePoint 2007 isn’t the most, how shall we say, “consistent” platform to use. You might get an exception one day that has the following message:

“Something's happened, it’s broken the site, so… there you go”.

(OK, not what you actually get, but in some cases the exception message is totally useless).

When I see an exception message which is useless, I attach WinDbg to the w3wp.exe process running the “broken” SharePoint and I can see the real exception that caused a problem, and sometimes I might have to step into the running code at assembler level to see what’s going on. I don’t have to this often, but the fact that I have this in my arsenal has saved me a couple of times from punching the wall the frustration as to why I’m getting an error.

I strongly believe that learning assembler makes you a better developer, but that’s just me. Check out the following Stack Overflow questions on the matter, see what you think:

Is learning Assembly Language worth the effort?
Why do we teach assembly language programming?
Why do you program in assembly?
Should I learn Assembly programming?
Is there a need to use assembly these days?
What are the practical advantages of learning Assembly?

The Death of Personal Computer World Magazine

Back in the mid 90’s, when I was studying for my BTEC diploma in computer studies, one of the first computer magazines that I began to purchase on a monthly basis was Personal Computer World (or PCW as it was also known). At that time it was a pretty large tome, with each edition spanning out to a good couple of hundred pages. I was impressed with the number of reviews, news, articles and tips and tricks which were presented by technical writers such as Gordon Laing and Barry Fox. In the back pages, I would often read the programming section, which helped me start off Visual Basic coding – where each month a different topic was discussed, such as accessing the file system from VB, reading registry keys, etc.

One thing that stood out most about PCW was the diverse topics which were included in the back pages, such as a monthly column on mathematics. Now, I don’t recall off the top of my head what exactly was discussed in that column, but I can’t think of another magazine at the time (or since) that offered such as section. I thought it was pretty cool, regardless of the fact that I understood very little of it!

Over time I bought the magazine less and less, to a point when I stopped buying it entirely. This wasn’t a decision I made point blank, it just kind of happened organically. A couple of years ago I was browsing through PCW in my local Tesco; I noticed how the magazine had suffered the decline like many other computer magazines – not as much content (I think it barely reached 100 pages). It still had many reviews and such, but it just didn’t feel quite as “heavy” as it did in the 90’s. It felt there was something missing. Even so, it came as a bit of a surprise that in the summer of 2009 I noticed that my local Tesco didn’t seem to be stocking PCW anymore. A recent search on Google lead me to this page. Here Gordon Laing give his postmortem on PCW and why it died off.

This is a real shame. Yes, I wasn't buying the magazine each month, but still, I felt like an old friend had vanished forever (over the top I know, but you know what I mean :) Other mags such as PC Pro don’t feel like they give the same value as PCW did. PCW does still exist on the web, but it’s publishing days are well and truly over :(.

Saturday, January 09, 2010

Nice Application To Handle Requirements Management

One thing that’s been tricky at our company has been requirements management. There’s no problem gathering requirements and creating a document that describes them, the trouble comes when we need to create TFS (Team Foundation Server) work items based on those requirements. There’s always a chance of a requirement being lost (especially true for very large documents) and not getting a TFS work item created for it – a big problem indeed. Certainly there have been cases when a missed requirement was not discovered until near the end of the a project, a rather large ‘ouch’ moment!

In the past, a colleague of mine did tinker with a prototype Word addin that allows a user to highlight sections of a Word 2007 document and mark it as a requirement. He never finished it, mainly due to time, plus the scale of what we needed as a requirements management solution needed something more then just a simple addin. However, I’ve just found this very interesting product – ‘TeamSpec for TFS Requirements Management’. I’m keen to have a look at this since it could be just the ticket for us. Basically this application allows you to integrate Word 2007 documents with TFS, giving you the ability to create work items and link them into the document. The advantage is that you are linking directly between the document and the work items, which means, for example, when viewing the document you get a live update of that work item’s state (if the ‘State’ field has been included in the document).

Not only that, but it also saves time since currently we must write the requirements document, then someone has to go through the document again, picking out each requirement, and creating work items for them. Very tedious; this was crying out for a better solution! There’s a nice explorer window that appears in Word which shows you the work items linked into the document:

 image

On the right is the explorer window which is showing 4 work items. Each work item is described in the document in the bullet points. You can pick and choose which work item fields to display in the document, each field in binded to the work item in TFS which means that any updates to a work item in TFS is synchronized in the document. There’s a lot of cool features in this product, check out the site and see for yourself.

Tuesday, December 29, 2009

Great Resource for Learning About Operating Systems

I happened to come across this page on the Berkeley University site which is a list of SWF and RealPlayer .ram files of lectures for the CS 162 Operating Systems and Systems Programming. I’m a big fan of learning about Windows internals and these lectures are great for helping me get more in depth information about the basics of operating systems and to brush up on stuff that I had forgotten since my computer science diploma days.

If you are using iTunes then there are loads of podcasts available from Berkeley, including CS 162. It looks like, starting from 2007, the CS 162 page does not have an MP3 available of each lecture, only the .swf file.

I highly suggest that you check these lectures out.

Wednesday, November 25, 2009

C# 4.0 – Learning About Dynamic Objects

When I first read about dynamic objects earlier this year, I must admit, I wasn’t sure how much use they would be to me other then, for example, COM programming. Now, considering that I currently do no COM development at all, this left me feeling that dynamic objects was never going to be useful in my arsenal of development tools. Well, that’s what I thought…until now.

Last week at the PDC 09 there was a session given about the new language features of C#/VB.NET in .NET 4.0, and from what I’ve watched so far, I’m excited at the possibilities. After watching the part about dynamic objects, I decided to have a go at a simple prototype app that shows how they can be used. Check out his class:

  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Dynamic;
  4.  
  5. namespace Dynamic_Test
  6. {
  7.     class MyDynamicObject : DynamicObject
  8.     {
  9.         IEnumerable<string> _data;
  10.         IEnumerable<string> _headers;
  11.  
  12.         public MyDynamicObject(IEnumerable<string> headers, IEnumerable<string> data)
  13.         {
  14.             this._headers = headers;
  15.             this._data = data;
  16.         }
  17.  
  18.         public override bool TryGetMember(GetMemberBinder binder, out object result)
  19.         {
  20.             result = _data.ElementAt(_headers.ToList().FindIndex(s => s == binder.Name));
  21.  
  22.             return true;
  23.         }
  24.     }
  25. }

Here I have a class that inherits from DynamicObject and overrides the TryGetMember. Doesn’t look like anything special yet, I’m just getting started. Now, here is my console app that makes use of the above class:

  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Dynamic_Test
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<string> headers = new List<string>();
  11.             List<string> data = new List<string>();
  12.  
  13.             headers.Add("Test");
  14.             headers.Add("Another column");
  15.  
  16.             data.Add("Value of item 1");
  17.             data.Add("Value of item 2");
  18.  
  19.             dynamic line = new MyDynamicObject(headers, data);
  20.  
  21.             Console.WriteLine(line.Test);
  22.         }
  23.     }
  24. }

Before I explain how the code works, have a look at line 21. Notice how I reference the ‘Test’ property on the object instance of MyDynamicObject – bear in mind that MyDynamicObject  doesn't have a ‘Test’ property, but the code still compiles without error. How so? Well, by declaring object ‘line’ to be of type dynamic, the compiler will treat this as something which will be sorted out at runtime – it’s not the compiler’s problem if 'property ‘Test’ doesn’t exist during a build. :)

When running the above code, you’ll see that the magic happens when you hit the line:

Console.WriteLine(line.Test);


The code will enter the TryGetMember method of MyDynamicObject. In that method I have an expression that searches for the string ‘Test’ in the collection _headers (remember, it’s searching for ‘Test’ since that’s the dynamic property reference by ‘line.Test’). If the string is found in _headers, it’s index is returned to pick out the string in the collection _data. So in our example, the string ‘Test’ is found at element 0 of _headers, and element 0 of _data is ‘Value of item 1’, so that is the string which is displayed in the console window. Elementary stuff, but already very powerful.

In the PDC video, the speaker shows an example of code which reads the contents of a CSV file and by using dynamic objects he can reference dynamic properties to read values from the CSV via their columns. It’s worth checking out.

Wednesday, November 18, 2009

Possible Solution To Crackling Audio – Windows 7 Realtek

About a month ago I installed Windows 7 on my laptop, getting rid of the ol’ evil Vista which had been infecting it for almost 2 years. Once the Windows 7 setup was finished, I went through the usual routine of getting up to date drivers installed for devices such as video and audio. Now, as I’ve become aware, there have been countless people experiencing crappy audio from their laptops/desktops via Windows 7 due to Realtek’s drivers. I was one of those people and for the life of me I couldn’t get a Realtek driver that would fix the poor audio.

Finally I managed to get a driver that has fixed the problem – if you go to here you can download a zip which contains some drivers that were mention in this forum. At last, no more pops and crackles. :)

Sunday, November 15, 2009

‘Undocumented Windows 2000 Secrets’ Book Available Online

For those of you who enjoy reading about Windows internals, you can download a PDF version of the very popular ‘Undocumented Windows 2000 Secrets – A Programmer’s Cookbook’. This book has been out of print for a long time and, due to its popularity, used copies can cost and arm and a leg if you don’t shop around. So, save your pennies and navigate to here. There is a zip file with the contents of the companion CD that came with the book.

Happy reading!

Friday, October 23, 2009

Windows 7 Is Winning (Some Surprising) People Over

linuswin7_084F3D27

Yup, it’s Linus alright.

(OK, he did it for a joke – he didn’t buy a copy surprisingly :) )

Tuesday, October 20, 2009

.NET DLL’s Duplicated In Memory

For reading RSS feeds I use RSS Bandit which is just fine for my needs. However, I’ve often felt that RSS Bandit isn’t the most resource friendly application; on my Windows XP system with 1GB of RAM, it can feel a bit sluggish. Well this evening I thought I’d use VMMap from Sysinternals to see how much memory RSS Bandit is using – and in doing so I found something very odd.

image

The above view is a portion of the images section of RSS Bandit’s virtual memory space. Notice the duplicate DLL files loaded in memory, there are many other DLL duplications appearing, wasting a lot of memory. I counted about 28MB of memory was being wasted by duplicate DLL files. The most notable thing about this, is that all the DLL files are .NET DLL’s.

Now this actually rang a bell with me, since in the back of mind I thought I had read something about this on a forum. After some hunting around I found the original Sysinternals forum post where I had read about this duplication issue. It turns out that Microsoft have been notified about the problem and are looking into it.

Problem is that a fix won’t be coming anytime soon. If you read the last post for the Connect bug report, by Aarthi Ramamurthy, you’ll see that MS have anaylsed the problem and decided that it’s too large a change to do anything about it right now.

Sunday, October 18, 2009

TypeMock Isolator 5.4.2 Released.

Hot on the heels of version 5.3.5, Isolator 5.4.2 has just been released. The new feature of this release is Intellitest which is a tool to help developers create the arrange section for tests. (AAA – Arrange, Act, Assert). So how does this Intellitest work? Well there is some sample footage of it in action here and here. I was just trying it out now with a simple class library.

So I have an interface like so:

namespace ClassLibrary1
{
    public interface IPerson
    {

string GetFirstName();

string GetLastName();

    }
}

which is used by this class:

namespace ClassLibrary1
{
    public class Class1
    {
        public string DoSomething(IPerson p)
        {
            return string.Format("{0} {1}", p.GetFirstName(), p.GetLastName());
        }
    }
}
I go ahead and create a unit test project and start writing my test:

[TestMethod]
public void GetSomethingTest()
{
    Class1 target = new Class1();
    target.DoSomething();
}

The cool stuff happens once I put the caret in the method call for DoSomething() I get this window appear:

image

I can now choose to create a fake IPerson to pass to my DoSomething(), which Isolator takes care for me by automatically inserting the code needed to perform the faking:

image

This has great potential, by adding functionality that can speed up the creation of the arrange code for developers, I think TypeMock are adding another great asset to the Isolator feature list.

At the moment, Intellitest only works with interfaces, but classes will be supported soon. I can’t wait to see what’s in store when this feature matures. Though my only concern is that, with a recent increase in price for Isolator, that Intellitest doesn’t

  • Increase the cost of Isolator even more.
  • Becomes a separate product that you have to pay for.

Chances are one of the above options will become a reality. Personally I hope they choose the second option, since I’d rather pay for Isolator with the current feature set, and have the option to purchase Intellitest if I really wanted it.

Wednesday, September 23, 2009

Windows 7 Developer Boot Camp

If you want to get ahead with developing solutions for the latest version of Windows, then this sounds like a fantastic event in the making. I’m a big fan of Mark Russinovich and I also enjoyed watching the Channel 9 videos of Landy Wang (memory manager guru) and Arun Kishan (architect in the Windows kernel team) – and to have these guys make an appearance at the developer boot camp makes me wish I had the chance to go. Ah well, you win some, you loose some.

To any of you who are going, I hope you have a great time (I hope the sound of my gritted teeth didn’t come through there!).

Thursday, September 17, 2009

.NET Reflector 6 EAP Available!

For those of you who love using .NET Reflector, there is now an EAP of version 6 available here. Red Gate have done a ton of work in this version to allow you to step into .NET code using a .NET Reflector addin in Visual Studio. There is an example walkthrough of this listed in the above I link I gave. As I´m currently in Tenerife, I can´t test the addin,but I have downloaded version 6 to have a quick look. On the whole it still looks the same as version 5, so for this EAP the big news is the VS integration. I´m sure that Red Gate will had features to the stand alone Reflector program as well. Looking forward to the next release :)

Thursday, September 10, 2009

Telerik Release TFS Work Item Manager & TFS Project Dashboard

Just a quick mention of some new, and free, tools from Telerik for those of you who use Team Foundation Server as part of your development process. The new tools are applications that you can use to view things such as work items, iteration and sprint details (for those of you using the agile templates), progress information (number of items completed, those currently being worked on, etc). Doesn’t sound like anything special, but when you see the great UI which is presented to you (built with WPF), you’ll soon forget about using the boring team explorer tab in Visual Studio.

A video on the site shows you an introduction to the tools, which I’m going to install tomorrow if I can squeeze some time in.

Friday, July 31, 2009

Wow, Must Be One Hell Of A Long Path!

image

Monday, July 20, 2009

I've Added Ad Sense To My Blog

I’ll have to wait about 48hrs for adverts relating to software development to appear. In the meantime, for those of you viewing my blog, you lucky people can click on these beauties which were generously randomized for me:

image

Passed exam 70-536.

About a month ago I passed the TS: Microsoft .NET Framework - Application Development Foundation exam. I had been a bit lazy about taking this one, having bought the training kit about 2 years ago! (Yup, I bought the the first edition, which has about 3 Microsoft Knowledge Base articles devoted to it’s mistakes). Mistakes aside, I managed to pass the exam with the aid of that book, plus Programming Microsoft® Visual Basic® 2005: The Language which is an excellent tome. I highly recommend it, even though its targeted towards Visual Studio 2005, since the author goes into great depth on many subjects such as reflection, object oriented programming, threads, security.

Saturday, May 23, 2009

Trying Out VS 2010

I downloaded the VS Professional 2010 bits last night, as I’ve been looking forward to testing out the next version for a while. The new WPF code editor has got me very excited (yeah I know – sad :)) due to the new possibilities for writing some cool UI extensions, like those which can be found at the Visual Studio Gallery.

One of the first things I wanted to try out where the new Sub() based Lambda’s in VB, which was not available in the language for VS 2008, though Func() was. As I sat down to start a new console application, I was a bit disappointed. Here is the code I was working with at the time:

Public Sub Main() 
    Dim k As String() = { "F", "B", "C" }
    k.ForEach(
End Sub

When I type the ‘(‘ character, VS started to churn a bit, think about it for a bit longer and then crash :( Humph. OK it’s a beta, so things like this are going to happen. Unfortunately it happens a lot for me. Even when creating a new class and instantiating it, the second I type a dot ‘.’ next to the variable name, I get a crash. Grrr.

Oh well. Hopefully by beta 2, things like this will have been ironed out. All in all, I’m really looking forward to VS 2010 since there is promised SharePoint support in the IDE (inside the server explorer, where you’ll be able to navigate SharePoint sites directly) and more SharePoint project templates. Cool. Having worked on many SharePoint projects, I can say that the development experience can prove frustrating at times.

Personally, it would be nice if they got rid of the need for SharePoint Designer and integrated everything into VS, giving users the option to use either for their SharePoint work. My reason for this request? SharePoint Designer is a heap of junk and I detest having to use it. But hey, that’s for another blog post…..

Monday, November 24, 2008

Unit Testing Private Methods

I’ve been reading a lot recently about people’s opinions regarding the correctness of unit testing private methods. Personally, I don’t see anything wrong with testing them – after all, private or not, I want to know if the code is going to work!!!

Who cares if it’s private?

Granted, performing the tests on a private method can prove tricky. I use VSTS for my coding, thus I take advantage of the private accessor code that is generated for me when I create a test on a private method. I find it quite bizarre that someone would suggest not testing private code, rather you should unit test any public methods that make use of that private code. Tsk, rubbish. If I had a coder on my team with that attitude, I’d seriously question his sanity.

Sunday, May 25, 2008

Passed Exam 70-630 TS: Microsoft Office SharePoint Server 2007, Configuring

Well I'm really chuffed that I passed this exam last Monday, with a score of 805. Admittedly I wasn't 100% confident that I had prepared enough, but with the help of Measure Up I was able to fill in any blanks that I had in my preparation.

In response to this success, I'm looking to taking exam 70-542 TS: Microsoft Office SharePoint Server 2007 – Application Development. I have no timeframe yet though I'm looking to get that one out of the way in the next couple of months. In the meantime I might have a go at exam TS: Microsoft .NET Framework 2.0—Application Development Foundation. Passing this will open the way for me to complete an MCPD certification, most likely in the web development area.
I'll keep you posted on any progress.....

Thursday, April 03, 2008

TypeMock - It's well ace.

Recently I purchased a fantastic mock framework called TypeMock and I will recommend any developer who wishes to improve their testing procedures to consider it. There are a number of bloggers out there with plenty of code examples, but here is my contribution. Today I needed to figure out a way that I can mock a SharePoint SPSite obejct, specifically a site object returned via SPContext.Current.Site. I wanted to do this in order for me to be able to run unit tests against my web parts. Before using TypeMock, the only way I could know what my code was up to was by using trace files. Now, I'm able to physically run the web part's code in real time and see whats going on! :) Ok, so here's the test:
    Public Sub SPContext_MockInstance_Test()
        Dim mockSPSite As Mock = MockManager.MockObject(Of SPSite)(New String() {"http://mycomputer:24000"})
        Using recorder As New RecordExpectations
            Dim dumm As SPSite = SPContext.Current.Site
            recorder.Return(mockSPSite.MockedInstance)
        End Using
        Dim target As BitsAndBobs = New BitsAndBobs
        target.Testy()
        If mockSPSite.MockedInstance IsNot Nothing Then
            DirectCast(mockSPSite.MockedInstance, SPSite).Dispose()
        End If
    End Sub
OK, so the test code works by mocking the call to SPContext.Current.Site, and when that happens, rather then returning that site object (which never exists anyway) the TypeMock framework returns my testing instance of an SPSite object. This is a very cool feature for me, since I've found testing web parts to be a bit of pain. Looking up articles that show you how to attach the debugger to the w3wp.exe process is handy, but it's so fiddly and often doesn't work (well, for me anyway!), so this is a big improvement on that, and hopefully will speed up my testing and allow me to use various scenarios to test the code.