Monday, July 19, 2010

A compact PC-Lint error output file parser

This code has been hanging around in my drafts folder for quite some time now. I needed to get it out. I wrote this simple parser for extracting information from the .out file PC-Lint provides as output after its analysis. This information will further be fed to a VS add-in that would integrate this content with the editor. It's going to be a cool one! I'm going to setup the alpha version of the add-in next month on Google Code.

Here's the code.

public class PCLintOutputReader
{
    public PCLintOutputReader(string filePath)
    {
        _content = File.ReadAllText(filePath);
    }

    public List<ErrorMessageInfo> ParseTextErrorMessages()
    {
        const string errorPatternAsString = @"T:\s*(?<Type>\w*)\r\n"
                                          + @"N:\s*(?<ErrorNumber>[0-9]*)\r\n"
                                          + @"F:\s*(?<FileName>.*)\r\n"
                                          + @"L:\s*(?<LineNumber>[0-9]*)\r\n"
                                          + @"M:\s*(?<Message>.*)\r\n";

        Regex errorPattern = new Regex(errorPatternAsString, RegexOptions.Compiled | RegexOptions.IgnoreCase);

        var errorMessages = new List<ErrorMessageInfo>();
        var matches = errorPattern.Matches(_content);
        foreach (Match match in matches)
        {
            GroupCollection groups = match.Groups;
            errorMessages.Add(
                ErrorMessageInfo.Parse(groups["Type"].Value, groups["ErrorNumber"].Value, groups["FileName"].Value,
                    groups["LineNumber"].Value, groups["Message"].Value)
            );
        }

        return errorMessages;
    }

    private string _content;
}


public class ErrorMessageInfo
{
    public ErrorMessageInfo() { }
    public MessageType Type { get; set; }
    public int ErrorNumber { get; set; }
    public string FileName { get; set; }
    public int LineNumber { get; set; }
    public string Message { get; set; }

    public static ErrorMessageInfo Parse(string aType, string aErrorNumber, string aFileName, string aLineNumber, string aMessage)
    {
        ErrorMessageInfo errorMessage = new ErrorMessageInfo();
        switch (aType)
        {
            case "Info":
                errorMessage.Type = MessageType.Info;
                break;
            case "Warning":
                errorMessage.Type = MessageType.Warning;
                break;
            case "Error":
                errorMessage.Type = MessageType.Error;
                break;
            default:
                throw new ArgumentException("Could not identify the type of PC-Lint error.", aType);
        }

        int temp = 0;
        int.TryParse(aErrorNumber, out temp);
        errorMessage.ErrorNumber = temp;

        int.TryParse(aLineNumber, out temp);
        errorMessage.LineNumber = temp;

        errorMessage.FileName = aFileName;
        errorMessage.Message = aMessage;
        return errorMessage;
    }
}


public enum MessageType
{
    Info,
    Warning,
    Error
}

Disclaimer: This is a very amateur implementation of the solution. Kindly use the code at your own risk and don't blame me if your laptop bursts into flames. Please forgive any obvious coding convention errors. And let me know if you find any bugs.
Have fun!

Sunday, July 4, 2010

The Engineering Sprint

I was listening to Episode 164: Agile Testing with Lisa Crispin on SE-Radio a few days ago. It was a nice podcast and Lisa's views are very much similar to the views of hundreds of Agile experts out there. While describing the work she's currently into, she mentioned the term "Engineering Sprint".
An Engineering sprint is a 2 week long iteration every 6 months where the team tries out new tools, upgrades existing tools and tries out some new approach to do things better than the way its always done.
I really liked the idea. I do that on a regular basis. I'm always on the lookout to find new and better tools to do my work more efficiently. Nowadays, we do a lot of work - which with a little bit of thinking - can be automated and we can save ourselves a whole bunch of time. But, the team usually doesn't have time to look at the existing situation and evaluate options to make it better. It's the scrum master's responsibility to allocate enough time to each individual to make such evaluation and it is the team's responsibility to make sure they make the best of it.

I'm not asking for a 20% personal time like Google does. But, even letting the team know that such suggestions are welcome can go a long way in making things better. There are always people in the team who are bored of doing the same shitty work everyday. Let them do something different, something interesting and something which will make them more productive in future.

Friday, July 2, 2010

Give it a name!

We all make mistakes, both big and small. But there are always opportunities in life where the smart ones learn to hide their mistakes by redirecting attention to something good (or at least something that looks good). For example, I feel most of the famous and most delicious recipes have been the result of a screw-up. Like when the chef added a little too much pepper in the chicken, they called it 'Hot Pepper Chicken', more ginger and they called it 'Ginger Chicken'. Well, for one, these are fairly easy instances to get out of and second, you cannot always be a smart-ass. The lucky ones get away with murder.


But, making excuses is great till the time someone somewhere catches your bluff. It's really embarrassing then. Not trying to be some kind of a wise man or something. I just came across this topic tonight while preparing dinner when I added too much ginger garlic paste in the chicken. I'll call it 'Pro Ginger Garlic Chicken'.

Since you wasted your precious time reading this crap, the least I can do is leave you with a thought -
'When life gives you lemons - you don't make lemonade; you sell the lemons at double the price, buy lemonade with the first half and keep the second.'


Update: This variation of 'When life gives you lemons' was my own creation and it provoked me to look for more such related interesting quotes. I could find these -
"When life gives you lemons, buy a lemonade stand and use the profits to buy a machine gun. Lets see if life makes the same mistake twice."
"When God gives you lemons, find a new God."
"When life gives you lemons, make grape juice. Then sit back and watch the world try to figure out how you did it."
"When life gives you lemons, throw them at mean people."
"When life gives you lemons, trade it for an apple or something."
"When life gives you lemons, squeeze the juice into a squirt gun and squirt it into someone's eye. It'll make you feel better."
"When life gives you lemons, throw them away! WHO THE FUCK gives lemons out? Mercury Sympathizers thats who!"
"When life gives you lemons, make lemonade. Then give it to your enemies cause it'll be real shitty unless life gave you sugar too."
"When life gives you lemons, you should be use to it because you are a loser and you already have a shitload of them."
"When life gives you lemons, find someone who's life gives them fish & chips and enjoy."
"When life gives you lemons, gentically modify them and use your Super Lemons to destroy the world!"
"When life gives you lemons, rip said lemons in half and jam the wet ends into life's eyes. That'll teach the fucker."
"When life gives you lemons, sell them on e-bay."
"When life gives you lemons, ask for the receipt."
"When life hands you lemons, make lemonade and find someone else who life handed vodka to, and have a party."

P.S. I promise my future posts will definitely be more sensible.

Wednesday, June 23, 2010

Not the world's most faithful employee

Yes, I'm not the world's most faithful employee. But then, who is? I haven't been fair to my employer by lurking around for better opportunities or as they say "looking for greener grass". But, who doesn't do that? I'm not The Buddha or Mr. HarishChandra to always be true about whatever I do.

And one fine day I get a cool offer letter from XYZ corp. Yay! Sounds great, doesn't it? Oh wait, you haven't heard the half of it yet. Lets go back a couple of moments from when the mail popped into my inbox. This is what happened - My reporting manager and I are having a nice code review for a feature I've been implementing for some time. We're completely immersed into the review and I'm explaining her on how the code works. "Bing" goes my desktop and an Outlook alert pops up saying, "Offer letter from XYZ" and we totally froze for about a couple of seconds. Now comes the difficult part; behaving as if nothing happened. So we do our expression-less poker face which would look somewhat like this.


But, she's freaked out inside somewhat like this.


And, the best thing was that we didn't talk about it even after the review was over; extremely professional ya know! Uh, not so professional when I realized she had called up my project manager and informed that they were losing a developer (I really couldn't find a picture to portray his grief). As far as XYZ is concerned, they won't have the pleasure of working with me. Will call up and reject the offer tomorrow. I'm staying.

Edit: 
My good friend @Gamer_Rags guessed what my project manager's face would be like. I've actually seen that face today. Thanks buddy!


I really need a disclaimer. Have a nice evening!

Sunday, June 20, 2010

The Beginning

So here I am wondering what to write on this blog and I really can't find a topic on which I could endlessly blabber about. But, I'm human. I come across new stuff everyday. Good stuff, bad stuff, beautiful stuff, ugly stuff and stuff I shouldn't blog about. Well, now that stuff has a home, it's here. Today I'm going to talk about stuff that has been on my mind and stuff I want to share about my new blog - sort of a curtain raiser. Here we go.

Why a new blog?
I'm not a blog hopper. I knew I wanted a new blog. My old blog on GeeksWithBlogs.net was a totally technical blog and writing personal stuff over there was not really a great idea. The good thing is that that frickin' blog still gets at least 40 hits a day only with 20 posts! Google Search really helps the blog stay alive. The GeeksWithBlogs.net community is totally awesome and I really liked posting out there. But, that's past now. I want my blog to be both technical as well as personal. I want my blog to be a place where I share my views on things that happen to me in my life. And, I want my blog to be a portrayal of myself and not as some XYZ blogger on GWB. Soon, I'll move to a custom domain. That would help me getting my blog a unique identity.

The Technical Side
Well, if you ask me what I do, I'd say "I'm a professional C++/C# developer". But, I'm glad it doesn't end there. I'll try to share every tool I work with, every great coding experience I come across and every interesting software development tidbit. I currently work with Windows XP (Yes, I still work on WinXP), and Visual Studio 2008. I keep using tools like CppUnit, NUnit, NAnt and Compuware DevPartner. My current job includes compiler design and development, but I'll try to avoid any talk about it as it can get really really boring. I remember studying "Compiler Design" during the 6th semester of engineering - it was hell. I'm a software developer at heart. I take pride in what I do and sharing my experiences about it helps me know that I'm learning something new everyday.

The Personal Side
I love/hate a lot of people (the latter being larger in number) for the things they do everyday. There are some super-annoying people and some incredibly awesome people who I interact with everyday. I could ramble about them for hours. And then there's me - the super-annoying incredibly awesome person. All the crazy things I do will be a part of this blog.

The Name of the Blog
Well, I've been looking for good blog names for quite some time now. I could come up with a few including
Websteroy
Royware
Royology
... and I realized how much I suck on producing good names. The search for a good blog name kept me from actually starting the blog. It's no wonder I'm a champion procrastinator. I keep finding ways to not do what I'm supposed to do. So Ellogical is not really a fixed and final name for this blog. I just had to give it a go. Drop in a comment about what you think about the blog's name or if you can suggest some other good name for this blog.

Killing the smileys
Although this blog is a personal-cum-work related blog, this is fairly serious writing and there will be no smileys (I'll try to control myself as much as possible). I use them regularly on Twitter as sometimes 140 characters are not enough to express joy, sorrow, etc. But, here, it's a no-no.

Swearing
I'm an angry person and I'm totally allowed to use expletives out here. IT'S MY F**KING BLOG. You don't tell me what I can/should write.

What next?
Not a bad start, but I really don't know what my next post will be about. I'm sure I can find something to talk about. Till then, have fun. Peace.