Archive

Posts Tagged ‘Blocks’

Code Issues of the dead code type for members and blocks

October 18th, 2012 Comments off

Here are several of the code issues, which highlight redundant and unnecessary code blocks that may be safely removed for improving code readability.

Read more…

Refactorings for Loops and Blocks overview

August 28th, 2012 Comments off

This is just a quick overview list to organize a bunch of refactorings that deal with loops and blocks. Click the refactoring name to learn more about it.

Add Block Delimiters

This refactoring embeds a single statement into curly braces.

Consolidate Using Statements

This refactoring combines several neighboring or nested using statements that cover variables of the same type into a single using statement.

Read more…

The Lock to Try/Finally refactoring

August 27th, 2012 Comments off

Locking is essential in programs with multi-threading. It restricts code from being executed by more than one thread at the same time. The lock statement gets the exclusive monitor for an object and ensures that no other thread can access the object until the lock is released.

The lock statement automatically generates exception safe code, and in fact it is a syntactic shortcut for a call to the methods Monitor.Enter(obj) and Monitor.Exit(obj) with a try/finally block. However, if the thread is aborted after the lock is acquired but before entering the try block, the lock will not be released. Also, bear in mind that the Monitor.Enter() waits to acquire the lock forever which may introduce a possible deadlock condition.

Read more…

Adding and removing block delimiters in C#/C++ and JavaScript

March 12th, 2012 3 comments

In C#, C++ and JavaScript languages, curly braces are used as block delimiters. A block allows multiple statements to be written inside. If a block contains a single statement, block delimiters, in most cases, are optional. For example, a single statement inside a loop does not require block delimiters:

CodeRush Optional block delimiters sample

Read more…