Use of Syntactic Sugar / Built in Functionality

Posted by Kyle Rozendo on Stack Overflow See other posts from Stack Overflow or by Kyle Rozendo
Published on 2010-05-14T05:28:01Z Indexed on 2010/05/14 5:34 UTC
Read the original article Hit count: 305

Filed under:
|
|

I was busy looking deeper into things like multi-threading and deadlocking etc. The book is aimed at both pseudo-code and C code and I was busy looking at implementations for things such as Mutex locks and Monitors.

This brought to mind the following; in C# and in fact .NET we have a lot of syntactic sugar for doing things. For instance (.NET 3.5):

lock(obj)
{
   body
}

Is identical to:

var temp = obj;

Monitor.Enter(temp);

try 
{ 
   body 
}
finally 
{ 
   Monitor.Exit(temp); 
}

There are other examples of course, such as the using() {} construct etc. My question is when is it more applicable to "go it alone" and literally code things oneself than to use the "syntactic sugar" in the language? Should one ever use their own ways rather than those of people who are more experienced in the language you're coding in?

I recall having to not use a Process object in a using block to help with some multi-threaded issues and infinite looping before. I still feel dirty for not having the using construct in there.

Thanks,

Kyle

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#