Prefix cast or as-cast?

added by AndreiR23
8/14/2012 8:53:07 AM


I read today a nice article, from Kathleen Dollard, called To “as” or not to “as”. This is a pain-point for me on which I stumble often, so I decided to write this little rant. I particularly liked a paragraph from the above-cited article : One of the things that makes hard bugs hard is when there is a disconnect in time or space between the cause and the symptom. Time is time, space is lines of code, assembly placement, etc. Code can be written to minimize these disconnects. One of the ways to do that is to fail quickly. When application state becomes incorrect, yell about it immediately and rarely continue with the application in an invalid state. A null-reference exception at an unexpected time just makes code more difficult to debug.


8/14/2012 8:52:37 AM
I also prefer the prefix cast. When reading code it feels more natural to me, "as" sort of sticks out like a sore thumb in C#.