Bug Vanquisher

2 October 2008

— — .-. … . -.-. — -.. . .- -. -.. …. — .– .. .- — -. — – .- -… .. –. ..-. .- -.

Filed under: Computer Theory, Funnier — Tanveer Badar @ 3:59 PM

– …. .   -.- . -.–   .. …   .. -.   – …. .   – — .–. .. -.-. .-.-.-   — .-.   …. . .-. . .-.-.-  -… ..- -   -.– — ..-   .– .. .-.. .-..   -. . . -..   – —   -.. . -.-. .. .–. …. . .-.   – …. .   -.- . -.–   – —   -.. . -.-. .. .–. …. . .-.   – …. .   -.-. .. .–. …. . .-.   – . -..- – .-.-.-   —… -.–.-

– …. .   -.-. — -.. .  -.. . … .. –. -.  … …. — .– …   .. -   — .-. .. –. .. -. .- – . -..   -… . ..-. — .-. .   .. -. ..-. — .-. — .- – .. — -.   – …. . — .-. -.–   .– .- …   . …- . -.   ..-. — .-. — ..- .-.. .- – . -.. .-.-.-   .— ..- … -   – —   … …. — .–   – …. .   …. — .-. .-. — .-. …   — ..-.   .– …. .- -   .- -.   .- .– ..-. ..- .-..   -.. . … .. –. -.   .. -   .. … –..–   -.-. — -. … .. -.. . .-.   .– …. -.–   .. -   -. . . -.. …   .-.. . – – . .-. -..-. .– — .-. -..   … . .–. .- .-. .- – — .-. … .-.-.-   -… -.–   – …. .   .– .- -.– –..–   — -.–   .-. .- -. -   .. -.   -. —   .– .- -.–   ..- -. -.. . .-. — .. -. . …   – …. .   … .. –. -. .. ..-. .. -.-. .- -. -.-. .   — — .-. … .   -.-. — -.. .   … . .-. …- . -..   -.. ..- .-. .. -. –.   .– .– ..   .- -. -..   .– .– .. .. .-.-.-   .. -   .– .- …   … – .. .-.. .-..   – …. .   -… . … -   – …. .. -. –.   ..- -. -.. . .-.   – …. — … .   … .. – ..- .- – .. — -. … –..–   -.-. . .-. – .- .. -. .-.. -.–   – …. .   -.. . … .. –. -.   — ..-.   . -..- – .-. . — .   .– .. – .-.-.-

-. — .– –..–   -… .- -.-. -.-   – —   – …. .   – — .–. .. -.-.   .- -   …. .- -. -.. .-.-.-   .. ..-.   -.– — ..-   –. —   – —   – …. .   .– .. -.- .. .–. . -.. .. .-   .–. .- –. .   ..   .-.. .. -. -.- . -..   – —   . .- .-. .-.. .. . .-. –..–   -.– — ..-   .– .. .-.. .-..   … . .   …. — .–   … — .- .-.. .-.. . .-.   -.-. — -.. . …   .- .-. .   …- .- .-.. .. -..   .–. .-. . ..-. .. -..- . …   — ..-.   .-.. .- .-. –. . .-.   -.-. — -.. . … .-.-.-   .-.. . – – . .-.   .   .. …   . -. -.-. — -.. . -..   .- …   .-.-.-   .- -. -..   — .- -. -.–   — – …. . .-.   .-.. . – – . .-.   -.-. — -.. . …   -… . –. .. -.   .– .. – ….   .-.-.- .-.-.-   – …. .. …   -. . -.-. . … … .. – .- – . …   – …. .- -   … — — .   — – …. . .-.   .-.. . – – . .-.   -… — ..- -. -.. .- .-. -.–   — .- .-. -.- . .-.   — ..- … -   -… .   ..- … . -..   -… . -.-. .- ..- … .   -. —   .-.. .-.. -.–.- -.- -.–.-   .–. .- .-. … . .-.   -.-. .- -. –..–   ..- -. .- — -… .. –. ..- — ..- … .-.. -.– –..–   .- .-.. .– .- -.– …   -.. . -.-. — -.. .   .. .-.-.-  

— -.   – …. .   — – …. . .-.   …. .- -. -.. –..–   …. ..- ..-. ..-. — .- -.   .- -. -..   .- .-. .. – …. — . – .. -.-.   . -. -.-. — -.. .. -. –.   …. .- …- .   – …. .   -. . -.-. . … … .- .-. -.–   .–. .-. — .–. . .-. – -.–   … …. — .-. – . .-.   -.-. — -.. . …   .- .-. .   -. — -   …- .- .-.. .. -..   .–. .-. . ..-. .. -..- . … .-.-.-   .- -. -..   .-.. . – …   -. — -   ..-. — .-. –. . -   – …. .   — .- –. -. .. ..-. .. -.-. .- – .. — -.   — ..-.   … -.– — -… — .-.. …   .-. . –.- ..- .. .-. . -..   – —   .-. . .–. .-. . … . -. -   – . -..- – .-.-.-   .-.. . – – . .-. …   .   .- -. -..   -   …. .- …- .   – …. .   … …. — .-. – . … -   -.-. — -.. . …   .- -. -..   – …. . -.–   .- .-. .   .- -   .-.. . .- … -   .—-   … -.– — -… — .-..   .-.. — -. –. .-.-.-   .-. . … -   — ..-.   – …. .   .-.. . – – . .-. …   –. . -   ..- .–.   – —   ..-. — ..- .-.   … -.– — -… — .-..   .-.. — -. –.   -.-. — -.. . … –..–   … —   .– .   .- .-. .   – .- .-.. -.- .. -. –.   .- -… — ..- -   — .- –. -. .. ..-. .. -.-. .- – .. — -.   — ..-.   .- -   .-.. . .- … -   ..— -….- ..— .-.-.- ….. -..- .-.-.-

23 December 2007

Catching the Exceptional

Filed under: Computer Theory, Dev inside! — Tanveer Badar @ 4:42 PM

[Warning: None of the code, even the simplest one, may compile. I was just demonstrating a point, code is meta-information to support that.]

Let’s do some coding. You have a simple program to calculate inverse of an integer.

using System;

namespace Program
{
    public class Exceptional
   {
       public static void Main( )
       {
           Func( );
       }

       void ShowInverse( int num )
       {
           Console.WriteLine( 1.0 / ( double )num );
       }

       void Func( )
       {
           Console.WriteLine( "Please enter a number: " );
           try
           {
               int num = int.Parse( Console.ReadLine( ) );
               ShowInverse( num );
           }
           catch( Exception ex )
           {
               Console.WriteLine( ex.Message );
           }
        }
    }
}

I do not claim this program to be the best ever. You will see what I am trying to do. That int.Parse line can fail for any number of reasons. That’s why it is surrounded by a try-catch clause. So, we got rid of formatting errors for the moment. But this leaves one problem wide open. What happens if input is ‘0’? We may need to add another try-catch in ShowInverse. So the revised code for ShowInverse becomes

       void ShowInverse( int num )
       {
           try
           {
               Console.WriteLine( 1.0 / ( double )num );
           }
           catch( Exception ex )
           {
               Console.WriteLine( ex.Message );
           }
       }

This is essentially equivalent to having a nested try-catch block inside the one in Func. You get the idea how we nest try-catch blocks to deal with different syntactic/semantic errors.

Now, let’s get a bit abstract, our Exceptional class has some functions which encapsulate some business logic and call each other inside try-catch clauses. Each of them has DB logging for success, in case of exceptions and in their finally blocks.

using System;

namespace Program
{
   public class Exceptional
   {
       // logging logic all goes inside Logger.Log function, which will take only a string.
       Logger log = new Logger( );

       void Func1( ... )
       {
           try
           {
               log.Log( "Executing Func1" );
               ...
               Func2( ... );
               log.Log( "Ending Func1's try block." );
           }
           catch( Exception ex )
           {
               log.Log( "Error occurred inside Func1 " + ex.Message );
           }
           finally
           {
               log.Log( "Exiting Func1." );
           }
        }

       void Func2( ... )
       {
           try
           {
               log.Log( "Executing Func2" );
               ...
               log.Log( "Ending Func2's try block." );
           }
           catch( Exception ex )
           {
               log.Log( "Error occurred inside Func2 " + ex.Message );
           }
           finally
           {
               log.Log( "Exiting Func2." );
           }
        }
    }
}

We log everything, even the exceptions to a database. Here’s a pop quiz, what happens in the case when original exception was thrown because underlying database is not available? Even in this case, we attempt logging and fail in our catch blocks and throw another exception.

Suppose this happened while Func2 was executing, we catch the first exception and try to log it, another exception is thrown and Func1 attempts to log it and throws yet another exception. There is no one to catch the third exception was will cause what service Exceptional was providing to fail.

Is the answer to the problem is to add yet another try-catch clause inside all existing catch/finally blocks? Definitely no. What if someone else comes along later and sees no logging in catch/finally block! I’ll add that. And we are back to the same problem we were attempting to solve.

Suppose, this code was part of a console application. Eventually, the exception would surface to operating system loader which will notice no one has handled it. For Windows, you can find the details in MSDN about what happens when program throws an unhandled exception, but operating systems follow similar patterns. If everything fails, program is terminated. If this happened in kernel mode, you lose everything.

If you pause to think for a moment, you will see our exceptional handling code forms a hierarchy. We have various levels of handlers from swallowing everything type to log and rethrow to transforming ones. At lower levels, you have all sorts of choices from retrying the operation to keeping things silent to invoking some alternative or compensating functionality.

The one which causes the program to terminate is the most beautiful. It is the root which must withstand the worst of all. It is unique in the way that nothing passes this handler, nothing can ever pass this one. It handles everything where others fail.

11 November 2007

More Horrors

Filed under: Computer Theory — Tanveer Badar @ 3:46 PM

Right off Brad Abrams blog!

Isn’t it odd that…

From the files of things that make you go “hmmmm”.

System.Exception (the base class for all exceptions) is indeed an exception: throw new Exception ()

But…

System.Enum (the base class for all enums) is not an enum: typeof (Enum).IsEnum == false

System.ValueType (the base class for all ValueTypes) is not a ValueType: typeof (ValueType).IsValueType == false

System.Attribute (the base class for all custom attributes) is not a custom attribute [Attribute] -> compile error

# Brad Abrams said on May 10, 2004 9:21 PM:

Oh, and I just noticed that System.Array is not an Array:
typeof (Array).IsArray = false…

This again proves my point that root in a hierarchy is always special. The rules used to build that hierarchy do not apply to the root, breaking the constraint system.

3 November 2007

Building The Tools

Filed under: Computer Theory, Dev inside! — Tanveer Badar @ 1:12 PM

Connected with the extremely twisted last post, consider the methods of programming the machines we have seen since 1943. Let us build a hierarchy of tools we use for programming and how they must have come to be what they are right now.

ENIAC was programmed using rewiring and four years later than that for ROM function tables. Only six women programmed it. Compilers existed long before that. Assemblers came out a little late. We see the first portable programming language in 1972. High level languages soon follow, my first love enters the picture, the world is swarming with all sorts of OO and high level languages by mid 1980s. Declarative languages add to the mix at this time too. Right now, we are partying on very expressive programming environments.

Grab Visual C++ compiler, the language I use most. Or better yet csc.exe. Consider how that compiler itself must have been built. If you have seen rotor, you will know that csc itself is written in C++. Therefore, it will require a C++ compiler, definitely cl.exe because of this. Put cl.exe into the interrogation box and ask the same question, who is your mother? It will say cl.exe with a build number or version number smaller than mine.

But this isn’t a chicken and egg problem because it must have begun at the first build of cl.exe. Let’s say it was compiled with a C compiler. Then, who was the mother of that compiler? Some earlier C compiler. Who gave birth to that first one? An assembler is the most likely answer, say masm.exe. The question repeats itself, only this time in the context of assemblers. First assembler would have built the second and itself must have been built by some machine which required programming by re-wiring (only a guess, I have no proof :)).

This machine may have built a few assemblers. Those assemblers must have boot-strapped themselves and eventually one of them may have become powerful enough to build a C compiler. (Actually, from what I just read, it goes way back than that assumption. C was a transformation of B which had a compiler who origin was in BCPL’s compiler. But let us again skip the details and say BCPL compiler may have been built with an assembler.)

This early compiler must have boot-strapped itself too and built more powerful versions of it and other compilers. Definite proof for this is the C-front, first compiler for C++ which produced C code as a result which was compiled and executed. The process has been bootstrapping itself ever since and giving rise to more and more language compilers of all sort and hence, we trace the path from root to csc.exe!

If you look carefully, you will find my favorite data structure here too. Conceptually, ENIAC or something similar lies at the root. At every level, a transformation program (assemblers/compilers) is either boot-strapping itself or increase the set of available transformation programs at the next level. From ENIAC, we move to a decent number of assemblers, which boot-strap themselves to assemble BCPL (again, my hypothesis) compiler. BCPL compiler compiles B compiler which boot-straps itself and generates a C compiler. This C compiler again bootstraps and really makes the bomb go off by giving rise to other C compilers and C-front. And again, the rest is history.

Abacus->ENIAC->Assemblers->Compilers->Declaratives

Filed under: Computer Theory — Tanveer Badar @ 1:08 PM

It must have begin with the first ever Abacus. One of the earliest machines to help us compute. Although primitive but really effective. Even if you do not include a concept of ‘0’ in your numerals.

Over millennia, we moved forward to faster, automated computing machines. ENIAC was born. But limited in programmability and never reproduced. Remember it is still 1943 and the design has been locked. First ever compiler makes to the front for Mark 1 in the same year. No stored program concept till 30/06/1945, machine programmability is very limited. Universal Turing Machines are still 4 years away. Even with the concept of UTM in 1948, it takes one more year for human eyes to see the first ever symbolic assembler.

Therefore, let me change the title to

Abacus->ENIAC/Compilers->Assemblers->Declaratives

Let’s fast forward the boring details and link leaden paragraphs to 1972. This year is significant because it marks the turning point in programming languages and will change the flow of events forever. We see ‘C‘ being born and the rest is history.

I am laying the ground for another post with this extremely brief history, many twisted details (some by me, for brevity’s sake), and left out milestones (again my apologies).

19 October 2007

Out of the Fire, into the Frying Pan 2

Filed under: Computer Theory, Personal — Tanveer Badar @ 12:53 PM

A few days ago, I posted about how I got 3.89 out of 5. That piece of information was not there, leading people to ask what the overall rating was.

While I have no objections to that 3.89, I do have a little to say about the procedure. At my company, a TL reviews each and every member of his/her team. After that review, the formalized review forms stream up the food chain (higher management).

Then, someone normalizes the results. By normalizing it means that rankings are pulled back a little if the TL is known to be lenient or added up a little if he/she is very strict. Then, things happen, all sorts of tantrums, shoutings, yelling hoarsely or walking out (just kidding, nothing of that sort ever happened).

If you are following the theme about one specific data structure I praise above all, you may have already spotted the trouble spot. It is the normalization process. What a TL does to his/her team is done again with his team by an even larger/bigger predator (no offense if anyone from my company reads it :) ). If a TL has a very dim view with the predators, his team is going to pay the price, if a very bright view kudos to all.

18 October 2007

It also goes by ‘Wait’

Filed under: Computer Theory, Things in life — Tanveer Badar @ 4:34 PM

clip_image001imageimageimage

They all spell the same. They all mean the same. They mean try as you may, it will not let you for a whole host of reasons.

Get introduced to the second name of the wonderful machine, the marvelous invention ‘computer’.

For the last hour, I have been building the latest release of boost. Yet my computer won’t let me do anything else.

image

I wonder has our waiting for anything to be done has increased or not? Even with the ever faster computers and more and more computing power available at our finger tips, with the advent of multi-core processors, nearly every body can be seen waiting for something to finish, some download to complete, some compiler to stop whining about the dredged code or have his heart’s desire to spit all those informative message about how it thinks a variable may be truncated during assignment.

We wait for our word processors to save the documents, watch those LEDs blink as the computer boots,  wonder what’s taking it so long to shutdown, curse while those GBs of RAM get written to disk if hibernating or read back during resume operations. And don’t be astounded when visual studio takes forever to refactor code even when the changes are confined to a single function, go to any lengths to optimize (not improve) OLTP performance.

Even with broadband availability, our needs have expanded even more disproportionately.

Work expands to exhaust (and demand more) resources allocated to it.

Now, we seek even bigger downloads, Ajax based websites take forever to load on those dial-up connections. Ever tried facebook, with the plethora of pictures on every page, mounds of javascript at your service you better have had a broad band connection.

And a big factor in consumer oriented markets like desktop operating systems and application is to only improve the perceived speed of some operation yet never inspect code like this

Message message = …;//get from somewhere

// A paramter has only one value, missing break after substitute call
foreach( Parameter parameter in parameters )
{
    IList values = GetAllValues( );
    foreach( Value value in values )
        if( value.Id == parameter.ValueId )
        {
            message.Substitute( parameter , value );
        }
}

They will go overboard to recommend things like

· Consider adding un-managed splash screen to show before the WPF app start. This will present the user with some UI and improve perceived responsiveness. Check blog later for a sample that demonstrates how this can be done.

[Improving WPF applications startup time]

With the release of Visual Studio 2008, Microsoft build tools will finally have multiprocessor build support, with MSBuild having /maxcpucount:n and cl having /MP:n as the relevant options. Just as the added generics after MSDN filling pages about how dangerous templates are for everyone’s health during .net framework 1/1.1 timeframe. So, I may expect boost to build a little faster next time I try that labor intensive (ahem! actually, only waiting for the damn thing to finish) operation.

It has been ages since multi-core processors came out. Hyper threading is a fact of history we take for granted these days. Multiple processors in one form or another are a norm rather than exception, yet it is hard to find properly written programs which can take advantage of even the most basic form of concurrency available. Having two processors in the bare minimum you can have but programs in the wild (and by wild I mean currently in heavy usage, not just written by your average Joe) blissfully ignore and have only one thread.

Herb Sutter rightfully said about these issue we will face increasingly in the future, with our processor clocks going no where.

We are shifting more and more towards ease. Ease of development, ease of use, ease of deployment, ease of availability, any ease you can fit in. Gone are the days when a redirector had only 128 byte foot print in low memory. Gone is the time when Windows ran happily in 4 MB of RAM.

So, I’ll see you around when you will be waiting for my next post because I will be waiting for something else to finish.

28 August 2007

Of Paging and Buses

Filed under: Computer Theory, Fun — Tanveer Badar @ 6:20 PM

This bus has nothing to do with this bus or this. I was referring to this bus instead. So, you got up in the morning and walked to bus stop and hitched a ride to office/school/college in that public bus.

Given the messy time it is in morning, everyone very busy with themselves on the roads, people bustling here and there, buses full to bursting point, it is hard to find a seat in the bus. What means do you employ to gain hold of a seat? Pushing, feigning a sick health ( :-) ), asking someone to sit up and give you their seat, bullying as the last resort? Whatever means you use, you will surely benefit if you had read a little about how operating systems do paging.

Different algorithms used to paging have a variety of characteristics and performance guarantees associated with them. They can also help you make your decision about where to sit, what to do to grab a seat and certainly, what to avoid.

  • Perhaps the best is the one which replaces the page which won’t be needed for the longest. Analogous to this, you should seek the passenger who will leave their seat the earliest,  use whatever means to gain hold. This strategy suffers the same problem as that algorithm mentioned, you cannot know beforehand who is going to leave when, unless you employ heuristics. For example, you may consider standing near school/college students when their institute is nearing, they will leave in a hurry.

  • Then, the worst choice is FIFO. You cannot expect people to play fair and offer you a seat if they can do otherwise.

  • Try going for the least recent arrival, corresponding page replacement algorithm is LRU. The person who is sitting the longest is likely to get off in near future as compared to others.

  • Given your specific route, most people will tend to get on and off quite quickly or they may stick with you for a long time. Choose wisely. The person who get into the vehicle recently is likely to leave after a short time.

  • Pick a random seat and stand near them. Here again, you can use some heuristics. People usually start to look on the road pretty closely when they are about to get off the bus. You may want to choose such a passenger.

  • Consider assigning a certain likelihood to the nearby passengers. If they are busy reading, their stop is far from your comfort. If someone is talking non-stop, their stop is no where near their recognition of surroundings!

  • Don’t go anywhere near old people and those visibly sick. They will have higher precedence than you when a seat needs to be filled. You will waste your time and chance which would be better utilized some place else.

  • [Update: 18/09/2007] Large groups of people tend to get off the bus near community places like shopping malls, something religious, hospitals [ :) ], schools, colleges etc. Spot such a group if some community place is on your path.

  • [Update: 07/11/2007] People do not actively seek vacant seats but instead tend to stay at one place. This call for spatial locality.

  • [Update: 07/11/2007] If you regularly take a route, you can remember people’s faces and easily predict who gets off when. Hence, the temporal locality.

15 August 2007

Don’t ‘Not Leak Information’

Filed under: Computer Theory, Fun — Tanveer Badar @ 2:02 PM

A couple of days ago, I was watching Discovery Channel. They showed some program about UK military and Apache pilots, remember the exact details.

One point that particularly stood out was how those pilots were debriefed. All personal information and pointers linking them to be an Apache pilot were stripped away. I suppose this was to prevent the [potential, totally misunderstood] enemies from finding out the details of that helicopter, in case the mission was compromised.

Now, let us puddle together into the lakes of wild guesses. I may be as right as Israeli forces attacking Lebanon last year or as wrong as freedom fighters in Kashmir and Palestine. Consider the situation where only Apache pilots have no information. Easy targets to identify, capture a foreign solider (pilot) and if he/she has no personally identifiable item, you captured an Apache pilot.

Therefore, next time your commanding officer tells you to lose everything personal before going on a mission, point him/her to this page and this entry too. Never (ever!) lose everything you have, makes you an easy target to pick out from masses. A much better strategy is to go along the path of misinformation. Lose personals and gain it from your commanding officer.

Side note to intelligence agencies. You guys should keep a keen eye out for pilots not having any identification. Chances are high they are Britons and were flying Apache helicopters in your territory. He is your priceless source of information, don’t let him escape.

25 June 2007

Happy Turing Day

Filed under: Computer Theory — Tanveer Badar @ 11:52 AM

It’s a bit late (actual date is 23rd June), but better late than never.

Older Posts »

Create a free website or blog at WordPress.com.