Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

Some Philosophical Reservations

Blocks are very versatile and they are clearly an important part of Apple's plans for the future of Objective-C and Mac OS X. However, blocks come with a few issues that are worth a moment or two of thought:

  • The term "block" was already in use. It is used as interchangeable with "compound statement" in almost every book on the C language. This might cause confusion in some circumstances.
  • Blocks are function oriented and not very object oriented. This may be an issue if you are strongly attached to an ideal of object-oriented purity.
  • Blocks completely break encapsulation. A block's access to variables that are not accessed through an argument list or an accessor method presents many of the same issues as using global variables.

    Using __block variables and copying blocks can result in entangled objects: You can create separate objects (potentially belonging to different classes) communicating via a variable on the heap that is not visible to anything else.

  • As with operator overloading in C++, blocks can be used in ways that lead to Design Your Own Language Syndrome, code that is very terse but very difficult for others (or yourself, several months later) to read and understand. This may not be an issue for independent developers, but it can be a problem if you are part of a programming team.
  • + Share This
  • 🔖 Save To Your Account