- Source: Block (programming)
- Source: Block programming
In computer programming, a block or code block or block of code is a lexical structure of source code which is grouped together. Blocks consist of one or more declarations and statements. A programming language that permits the creation of blocks, including blocks nested within other blocks, is called a block-structured programming language. Blocks are fundamental to structured programming, where control structures are formed from blocks.
Blocks have two functions: to group statements so that they can be treated as one statement, and to define scopes for names to distinguish them from the same name used elsewhere. In a block-structured programming language, the objects named in outer blocks are visible inside inner blocks, unless they are masked by an object declared with the same name.
History
Ideas of block structure were developed in the 1950s during the development of the first autocodes, and were formalized in the Algol 58 and Algol 60 reports. Algol 58 introduced the notion of the "compound statement", which was related solely to control flow. The subsequent Revised Report which described the syntax and semantics of Algol 60 introduced the notion of a block and block scope, with a block consisting of " A sequence of declarations followed by a sequence of statements and enclosed between begin and end..." in which "[e]very declaration appears in a block in this way and is valid only for that block."
Syntax
Blocks use different syntax in different languages. Two broad families are:
the ALGOL family in which blocks are delimited by the keywords "begin" and "end" or equivalent. In C, blocks are delimited by curly braces - "{" and "}". ALGOL 68 uses parentheses.
Parentheses - "(" and ")", are used in the MS-DOS batch language
indentation, as in Python
s-expressions with a syntactic keyword such as prog or let (as in the Lisp family)
In 1968 (with ALGOL 68), then in Edsger W. Dijkstra's 1974 Guarded Command Language the conditional and iterative code block are alternatively terminated with the block reserved word reversed: e.g. if ~ then ~ elif ~ else ~ fi, case ~ in ~ out ~ esac and for ~ while ~ do ~ od
Limitations
Some languages which support blocks with declarations do not fully support all declarations; for instance many C-derived languages do not permit a function definition within a block (nested functions). And unlike its ancestor Algol, Pascal does not support the use of blocks with their own declarations inside the begin and end of an existing block, only compound statements enabling sequences of statements to be grouped together in if, while, repeat and other control statements.
Basic semantics
The semantic meaning of a block is twofold. Firstly, it provides the programmer with a way for creating arbitrarily large and complex structures that can be treated as units. Secondly, it enables the programmer to limit the scope of variables and sometimes other objects that have been declared.
In early languages such as Fortran IV and BASIC, there were no statement blocks or control structures other than simple forms of loops. Conditionals were implemented using conditional goto statements:
The logical structure of the program is not reflected in the language, and analyzing when a given statement is executed can be difficult.
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:
Use of blocks in the above fragment of Pascal clarifies the programmer's intent, and enables combining the resulting blocks into a nested hierarchy of conditional statements. The structure of the code reflects the programmer's thinking more closely, making it easier to understand and modify.
The above source code can be made even clearer by taking the inner if statement out of the outer one altogether, placing the two blocks one after the other to be executed consecutively. Semantically there is little difference in this case, and the use of block structure, supported by indenting for readability, makes it easy for the programmer to refactor the code.
In primitive languages, variables had broad scope. For instance, an integer variable called IEMPNO might be used in one part of a Fortran subroutine to denote an employee social security number (ssn), but during maintenance work on the same subroutine, a programmer might accidentally use the same variable, IEMPNO, for a different purpose, and this could result in a bug that was difficult to trace. Block structure makes it easier for programmers to control scope to a minute level.
In the above Scheme fragment, empno is used to identify both the manager and their underlings each by their respective ssn, but because the underling ssn is declared within an inner block it does not interact with the variable of the same name that contains the manager's ssn. In practice, considerations of clarity would probably lead the programmer to choose distinct variable names, but they have the choice and it is more difficult to introduce a bug inadvertently.
Hoisting
In some languages, a variable can be declared at function scope even within enclosed blocks. For example, in JavaScript, variables declared with var have function scope.
See also
Basic block
Block scope
Closure (computer programming)
Control flow
References
Block programming (also known as a strand in British broadcasting) is the arrangement of programs on radio or television so that those of a particular genre, theme, or target audience are united.
Overview
Block programming involves scheduling a series of related shows which are likely to attract and hold a given audience for a long period of time. Notable examples of overt block programming were NBC's Thursday evening "Must See TV" lineup, which included two hours of sitcoms and one hour of ER, and Channel 4's "T4" program which often ran sitcoms back-to-back for an hour or more. Reruns on cable television are often assembled into similar blocks to fill several hours of generally little-watched daytime periods. A particularly long program block, especially one that does not air on a regular schedule, is known as a marathon.
Block programming in radio also refers to programming content that appeals to various demographics in time blocks, usually corresponding to the top or bottom of the hour or the quarter-hour periods. For example, various musical genres might be featured, such as a country music hour, a three-hour afternoon block of jazz, or a four-hour Saturday night '70s disco show.
Generally speaking, block programming is anathema to modern competitive commercial radio, which traditionally uses uniform formats, other than a handful of speciality shows in off-peak hours such as weekends (for instance, the infamous beaver hours in Canadian radio). The general rationale for not using block programming is that listeners expect a certain type of music when they tune into a radio station and breaking from that format will turn those listeners away from the station; likewise, a station that airs its programming in hodgepodge blocks will have difficulty building listener loyalty, as listeners' music will only be on for a few hours of the day. This argument for homogenized radio was also a driving force behind the effective death of freeform radio in the late 20th century. The case of talk radio is indicative of the decline of block programming: prior to the 1980s, it was not uncommon to mix various blocks of talk programming together on one station, but this has declined dramatically in the late 1990s and beyond. A listener to a conservative talk radio station will have little interest in a progressive talk radio, sports radio or hot talk block, which reaches a different demographic; stations that have attempted the block strategy have historically been unsuccessful. Block programming of this nature is alive and well on outlets like public radio (such as NPR, the BBC, or CBC) and in multicultural radio serving broad ethnic and cultural audiences, although even in this realm the idea of block programming is declining due to competition for donations.
Some programming blocks have become so popular that they have been transformed to full-fledged 24-hour channels. Current channels which started as program blocks include Disney Junior (which is still a program block on Disney Channel); the Nick Jr. Channel (based on the Nick Jr. block that still airs on Nickelodeon); Boomerang (which was once a program block on Cartoon Network); PBS Kids (which is still a program block on PBS) and MeTV Toons (which was once a programming block on MeTV). In addition, TV Land airs older shows that were once aired on sister channel Nickelodeon's Nick at Nite program block. Adult Swim is also a Cartoon Network Programming Block.
However, since the 2010s, new programming blocks have become rare due to airing programming in a regular format or with little or no brand reference within the programming block.
See also
Audience flow
Lists of programming blocks
Strip programming
Broadcast programming
Dayparting
Marathon (television)
References
Kata Kunci Pencarian:
- /dev/zero
- Steam
- Scratch (bahasa pemrograman)
- ASCII
- Sistem operasi
- Daftar bahasa pemrograman
- TvOne
- Frieren: After The End
- Block (programming)
- Block programming
- Cartoonito (American programming block)
- Bionix (TV programming block)
- Visual programming language
- TGIF (TV programming block)
- Block
- ABC Kids (TV programming block)
- Disney Jr. (programming block)
- Thread block (CUDA programming)