3

I wonder how many .NET developers have a working knowledge of CIL and where it has been useful to them.

In case you are missing my meaning, here is a simple CIL example to add two locations together:

ldloc.0
ldloc.1
add
stloc.0    // a = a + b or a += b;
5
  • 5
    confused: question title has absolutely nothing to do with CIL. What are you asking about? In-depth knowledge of the Runtime or the Intermediate Language? Apr 11, 2011 at 18:51
  • 1
    It's about both; you cannot have CIL without CLR.
    – Phil C
    Apr 11, 2011 at 18:57
  • 3
    When I start micro-optimizing, I remind myself the guys that wrote the compiler are a lot smarter than I'll ever be. Apr 11, 2011 at 19:02
  • The above code is magic to me. Apr 11, 2011 at 19:20
  • @Nick: "With CIL the previous lines of code matter in that these are used as parameters for the add instruction" [ Source: carnotaurus.tumblr.com/post/2455409003/… ]
    – Phil C
    Apr 11, 2011 at 19:27

4 Answers 4

9

The times I've had to use reflector or dip into IL have always been due to code smell. Two times in particular I recall:

  1. I was using a poor debugging method which resulted in a variable being optimized out by the compiler

  2. The original code was lost. Reflector did little to recover the code. The time it would have taken me to piece the code back to read-able form was much greater than the time it took me to rewrite it (non-obfuscated).

My point is, if you are a "normal" developer (E.G. not working at MS on the CLR source), there's very little need to scan IL. Regular developers should look at more common solutions to problems or they may be wasting a lot of time on the wrong solution or micro-optimizations.

5

I use it to the extent that I need to in order to follow things like Jeff Richter's book, and sometimes blog posting by the like of Eric Lippert. To that extent it is important to me so I have a good understanding of the platform as a whole.

I have (almost) never used IL directly in my "day job". However, if tools like Reflector did not exist I might have to, but thankfully the tools exist so I don't need to.

Edit - the comment below reminded me that on occassion it may be neccessary to debug in IL if you do not have source code available. I can only recal doing this once but it's certainly a scenario where some knowledge of IL is useful.

3
  • The sad thing is that there appears to be no debugging feature with Reflector - I'll upvote you for actually answering the question
    – Phil C
    Apr 11, 2011 at 18:03
  • That's a good point, and come to think if it I have once had to debug IL without source code.
    – Steve
    Apr 11, 2011 at 19:39
  • Yes, that's happened to me but rather you than me I suppose :)
    – Phil C
    Apr 11, 2011 at 19:44
1
  • understanding of principles is important
  • details like in you example - rather no. There are a lot of more useful knowledge to feed a brain
1

The headline asks about the CLR, the Common Language Runtime. The question text itself is about the CIL, The Common Intermediate Language. They are different things!

  • CLR. Yes, any .net developer needs a good understanding of the CLR.

  • CIL. No, a typical developer does not need to know CIL in any depth. If you need to write a compiler or perform some low level analysis you need it, otherwise not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.