Block Structure Programming

Posted: July 4, 2011 in Graduate School, Programming Languages

This entry is a response to our online assignment in Graduate School regarding Block Structure Programming

What is Block Structure Programming?

Programming languages are developed in order for the user, called as programmer, to tell the computer what to do in addressing a need or a requirement. These instructions are usually in a form of statements that should conform to a set of rules in defining and constructing it. It is called syntax and is unique in every programming language. The construction of these instructions depends on the language you use. There are some who follows a procedural approach where step by step implementation is done. While some are focusing on certain objects in order to come up with a complete solution. Among these, the most common and used technique is what we called block structure programming where declarations and statements are grouped together in a form of a block.

Block structure programming allows the programmer to create blocks that may also include nested block so that statements or codes can be grouped together. The idea of such was introduced when the simplified coding system or also known as “autocodes” were formally presented in Algol 58 and Algol 60 reports. The grouping is done by placing all related declarations and / or statements inside a block and is delimited by a begin and end statement (may be BEGIN or END, an opening or a closing curly braces {}). Blocks allow the programmer to treat a group of statements as a unit, and the default values which had to appear in initialization in this style of programming can, with a block structure, be placed closer to the decision. This technique does not only simplifies the code but also contributes to its readability and maintainability. Here is an example of a block structured code:

Using JavaScript

The for looping statement uses the block structure in this code snippet. It is easier to determine that the dropVal variable will change as it passes to the loop and if the condition is met.

Implementation of Block Structure in Programming Languages

Here is the implementation of the block structure programming in the following well known programming languages:

ALGOL

The idea of the block structure in ALGOL is to create blocks of statements for the scope of variables and the extent of influence of control statements. In this code snippet, it is clear that whenever the for loop is implemented, the array Data[] is populated with the entered value in val variable.

PASCAL

The block structure in this example is implemented in a conditional statement. Notice that is easier to determine the result of the condition by just checking on the inner blocks. Changes can also be integrated with ease in this case without affecting the other blocks. This blocks can also be implemented on looping statements.

C

This C code snippet uses block structure for the looping statement for. Notice that whenever the code passes by the loop a block of conditional statement is implemented to determine if the entered value of the n variable is a prime number. It is easier to maintain and refactor such code with the block structure technique.

BASIC

In this code snippet, the block structure is used in the conditional statement with the IF-ENDIF delimiters. It is easier to determine the codes to be executed whenever the name entered is “Ron”.

Web References

  • http://en.wikipedia.org/wiki/Block_(programming)
  • http://en.wikipedia.org/wiki/Autocode
  • http://www.csse.monash.edu.au/~lloyd/tildeProgLang/PL-Block/
  • http://en.wikibooks.org/wiki/C_Programming/Structure_and_style
  • http://www.cplusplus.com/doc/tutorial/program_structure/
  • http://groups.engin.umd.umich.edu/CIS/course.des/cis400/algol/algol.html
  • http://www.augustana.ab.ca/~jmohr/courses/common/csc370/lecture_notes/algol2.html
  • http://www.cis.temple.edu/~ingargio/cis71/code/factors1.c
  • http://home.cmit.net/rwolbeck/programmingtutorial/index.htm
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s