Bug Vanquisher

12 October 2008

Tidbit 2

Filed under: Dev inside!, Tips — Tanveer Badar @ 7:29 PM

This one pertains to CLR.

Please, please, please make sure your static constructors do not throw exceptions. Having static state in a class is already asking for trouble in the case of multiple threads, if that reason wasn’t enough proceed below.

For example,

class A
{
      static DataType1 member1 = new DataType1( );
      static DataType2 member2 = DataType2.GetDefaultInstance( );
}

If there is even the remotest chance that either DataType1’s constructor or DataType2.GetDefaultInstance will throw an exception you are better off with this version:

class A
{

    static DataType1 member1;
    static DataType2 member2

    static A( )
    {
        try
        {
            member1 = new DataType1( );
        }
        catch( Exception ex )
        {
            // do some logging
        }
        try
        {
            member2 = DataType2.GetDefaultInstance( );
        }
        catch( Exception ex )
        {
            // do some logging
        }
    }
}

The only reason for all this hassle is the avoid throwing uncaught exceptions from .cctor of a type.

Because, for a type whose static constructor throws an exception, EE ensures that no instance of that type will ever be instantiated in that appdomain.

[Update 11/03/09: Many moons after the original post, I come across this. The exact same problem happens in native world.]

Tidbit 1

Filed under: Dev inside! — Tanveer Badar @ 7:13 PM

Whenever you write an optimizer for a compiler/assembler/HW synthesizer, anything in general which will try to optimize expressions please ensure you special case a(b+c).

There is no need to do ab + ac, unless you want to split hairs.

[Disclaimer: I am allergic to memory models for the next 30 minutes.]

3 September 2008

The Best Programming Language

Filed under: Dev inside!, Rant vs Vent — Tanveer Badar @ 5:30 AM

The myth doesn’t exist.

There is no single best programming languages. If you are too thick to take one as the best, you may as well open a grocery shop and ditch programming forever.

I really hate this line of chat with totally unknown, or unenlightened fresh graduates (or w/e):

<someone>: hello
<me>: hi
<someone>: what do you do for a living?
<me>: making peoples’ lives a living hell
<someone>: you are joking
<me>: of course
<someone>: your real job
<me>: programming

[Then, the stupid question comes.]

<someone>:im too interested in programming
<someone>:which language you use most
<me>:there is no single language, depends on what you are working on
<someone>: i mean present trend
<me>: there are many, there is no single answer to that question of which is the best

[Then, the same question phrased differently this time and my same reply.]

[Then, the same question phrased differently yet again for the third time and my same reply.]

Finally, I got tired of the recursive non-decision but didn’t have the nerve or brain left to tell them to buzz off.

22 August 2008

Project Planning

Filed under: Dev inside! — Tanveer Badar @ 11:59 PM

Or my lack thereof.

I somehow failed to see the plain fact of dividing a long project plan into as many independent, parallel sequences of tasks as possible.

Such a division gives two pieces of information.

  1. You get the see the maximum parallelism in the project.

  2. Even if you apply infinite people on it, you still cannot finish it sooner than the longest sequence.

Therefore, [it] requires 8 people and won’t be finished sooner than 1.5 month in the ideal case.

28 July 2008

Dear God, Why Brits?

Filed under: Dev inside!, Funnier, Rant vs Vent — Tanveer Badar @ 8:50 PM

Why do they have to talk about something when they don’t know anything? Just the hype. Just the news they get from CNet/ZD Magazine/w-e. Just the little, tiny bits of information their minds retain.

Case in question:

Moore’s Law in relation to manycore

Today, July 28, 2008, 8 hours ago | noreply@blogger.com (The Moth)Go to full article

When most people’s brains first light up on why parallelism is the next BigThing, some jump to the conclusion that Moore’s law is over. Let’s clear that up below.
All of you know Roger Moore’s law which boils down to the prediction of

"the number of transistors on a chip will double about every two years"

clock speed increases and that is what has tricked most of us to associate Moore’s law with CPU speed.
So, now that chip manufacturers cannot make single CPUs any faster (well, they can, but they can’t cool them down enough to make them useful), they are resorting to having chips with multiple cores, which we are terming the manycore shift. The manycore shift has a profound impact on developers (especially those programming for the desktop client) in that their software now has to learn how to take advantage of parallelism.
So if you followed the logical flow so far, you’ll conclude that Moore’s law is still alive: we are still getting more silicon, but it does not translate to increased linear speed, but rather to parallel "engines" that your software must learn to utilise.
I am glad we cleared that up :)

Please read the funny stream of comments. And a bit unleashing of my own wrath.

I am glad you don’t actually do anything in hardware industry.

First off, it is Gordon Moore not Roger Moore. Get your facts right before you post.

Second, holy parallelism has its own nemesis, the Amdhal’s Law. You cannot go faster than 1/[portion of serial work] even with infinite processors.

Third, the problem isn’t even cooling. They can’t make the a transistor’s channel short enough.

[Update: 30/07/08 As expected, my comment wasn’t approved.]

[Update: 15/07/08 I just found out, he is also a PM at Microsoft. Yikes!]

5 July 2008

What Spring Had!

Filed under: Dev inside!, WCF — Tanveer Badar @ 8:44 PM

And I thought ASP.Net didn’t have it. And yes, I am talking about this Spring. And the feature in question in Spring’s DWR or direct web remoting.

A feature similar in functionality exists in WCF 3.5 incarnation, namely, “AJAX Integration and JSON Support“. This also allows an ASP.Net AJAX (or w/e it is called these days) client side to call a WCF service endpoint.

18 June 2008

Promote Firefox

Filed under: Dev inside! — Tanveer Badar @ 12:05 AM

Get is from here people!

http://ftp.twaren.net/Unix/Mozilla//firefox/releases/3.0/win32/en-US/Firefox%20Setup%203.0.exe

24 May 2008

Moving the Ground from Underneath Your Feet

Filed under: Bugz, Dev inside! — Tanveer Badar @ 7:08 PM

Run check disk while doing something important. :) The drive should disappear from everyone’s view as check disk opens it under exclusive RW access.

This brings us to some things, some tests I would like to run on many applications. Typical happens as I write this.

1- Visual Studio setup just hangs. *

2- Firefox crashes upon close when running from that drive. *

3- Tortoise SVN background process will crash. **

4- Opening any MS Office program will invoke windows installer instead (expected). If office was installed on that drive.

5- OneNote’s background keystroke monitor will crash. **

There are lots of things programs access file system for.

1- Custom logging: Not essential enough to actually crash the application. I would love to see some example program doing exactly that.

2- User data: Nothing should ever crash for this. Instead prompt for an alternate location.

3- On demand functionality: User invoked something. You need to load code/resources/configuration from a disk not available. What will you do? Crashing is very gross.

4- Configuration data: This can happen anytime. Don’t tell me you don’t keep a default copy of your required, must-have, 24/7 available, configuration ready at hand in resource form. Embedded right into your executable images.

19 April 2008

The Myth Called Overloading

Filed under: Dev inside! — Tanveer Badar @ 11:23 PM

There are some serious word press screw ups in this post. No smileys, ever! Yet word press insists. Also, line breaks are disappearing like mad.

There is no such thing as function overloading in this world! Period.

Whatever you see in HLLs is the compiler lulling you into the false sense that function overloading exists.

Cases in point:

1- C++: Most major compilers (at least from Microsoft) use name mangling. Here is dump of four constructors on std::bad_cast from msvcrt.dll

Mangled mode

Pretty mode

??0bad_cast@@AAE@PBQBD@Z bad_cast::bad_cast(char const * const *)
??0bad_cast@@QAE@ABQBD@Z bad_cast::bad_cast(char const * const &)
??0bad_cast@@QAE@ABV0@@Z bad_cast::bad_cast(class bad_cast const &)
??0bad_cast@@QAE@PBD@Z bad_cast::bad_cast(char const *)

2- CLR:Everything compiles down to IL, whether you like it or not. And here’s IL for typical function calls:

call class System.ServiceModel.Channels.Message System.ServiceModel.Channels.Message::CreateMessage(
class [System.Runtime.Serialization]System.Xml.XmlDictionaryReader,
int32, class System.ServiceModel.Channels.MessageVersion)

from System.ServiceModel.Channels.Message.

That’s it, you get the whole nine yards. Return type + fully qualified function name + fully qualified parameter types. It does not matter whether you use call, callvirt or calli. If its a call, its going to use everything fully qualified.

3- You may want to argue about operator overloading. But that’s just syntactic sugar.  Here is >> from std::basic_istream.

Mangled mode

Pretty mode

class std::basic_istream
<wchar_t,struct std::char_traits<wchar_t> > &
std::operator>>
<float,wchar_t,struct std::char_traits<wchar_t> >
(class std::basic_istream
<wchar_t,struct std::char_traits<wchar_t> > &
,class std::complex<float> &)
??$?5M_WU?$char_traits@_W@
std@@@std@@YAAEAV?$basic_istream
@_WU?$char_traits@_W@std@@@0@
AEAV10@AEAV?$complex@M@0@@Z

4- In CLR, the case is even simpler. You get op_Add straight away, then, its off to fully qualified function calls in IL. End of story.

It does not exist. Anywhere. Ever.

6 April 2008

‘The’ Source Code

Filed under: Dev inside! — Tanveer Badar @ 2:51 AM

If you haven’t heard that .Net framework source code is available while debugging under Visual Studio 2008 Professional (may be standard too?) or higher, I suggest you crawl out of the rock you are living under so far.

Specific details about how to set up your environment to enable source level debugging in FX assemblies is here. And it works too. :)

However, what amazes me is that the build tree is even more cryptic than ROTOR. Take a look at the monstrous path to AppDomain.cs.

F:\NetFX Symbols\src\source\FX1434\1.0\DEVDIV\depot\DevDiv\releases\whidbey\REDBITS\ndp\clr\src\BCL\System\AppDomain.cs\7

Yes, the actual .cs file is under <blah blah blah>\AppDomain.cs\7 directory.

[Update: about one hour later]

1- Go to definition does not use this particular source server for whatever reason. Bug filed here.

2- Downloaded source code is not persisted for whatever reason. Suggestion filed here.

« Newer PostsOlder Posts »

Create a free website or blog at WordPress.com.