Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Off-side rule
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Alternatives== The primary alternative to delimiting blocks by indenting, popularized by broad use and influence of the language [[C (programming language)|C]], is to ignore [[whitespace character]]s and mark blocks explicitly with [[curly bracket]]s (i.e., <code>{</code> and <code>}</code>) or some other delimiter. While this allows for more formatting freedom β a developer might choose not to indent small pieces of code like the [[Control flow#Continuation with next iteration|break and continue statements]] β sloppily indented code might lead the reader astray, such as the [[goto fail]] bug. [[Lisp (programming language)|Lisp]] and other [[S-expression]]-based languages do not differentiate statements from expressions, and parentheses are enough to control the scoping of all statements within the language. As in curly bracket languages, whitespace is mostly ignored by the reader (i.e., the read function). Whitespace is used to separate tokens.<ref>{{Cite web|url=http://clhs.lisp.se/Body/02_adg.htm|title = CLHS: Section 2.1.4.7}}</ref> The explicit structure of Lisp code allows automatic indenting, to form a visual cue for human readers. Another alternative is for each block to begin and end with explicit keywords. For example, in [[ALGOL 60]] and its descendant [[Pascal (programming language)|Pascal]], blocks start with [[Reserved word|keyword]] <code>begin</code> and end with keyword <code>end</code>. In some languages (but not Pascal), this means that newlines ''are'' important{{citation needed|date=June 2012}} (unlike in curly brace languages), but the indentation is not. In [[BASIC]] and [[Fortran]], blocks begin with the block name (such as <code>IF</code>) and end with the block name prepended with <code>END</code> (e.g., <code>END IF</code>). In [[Fortran]], each and every block can also have its own unique block name, which adds another level of explicitness to lengthy code. [[ALGOL 68]] and the [[Bourne shell]] (sh, and [[Bash (Unix shell)|bash]]) are similar, but the end of the block is usually given by the name of the block written backward (e.g., <code>case</code> starts a [[switch statement]] and it spans until the matching <code>esac</code>; similarly [[conditional (computer programming)|conditionals]] <code>if</code>...<code>then</code>...[<code>elif</code>...[<code>else</code>...]]<code>fi</code> or [[for loop|''for'' loops]] <code>for</code>...<code>do</code>...<code>od</code> in ALGOL68 or <code>for</code>...<code>do</code>...<code>done</code> in bash). An interesting variant of this occurs in [[Modula-2]], a Pascal-like language which does away with the difference between one and multiline blocks. This allows the block opener (<code>{</code> or <code>BEGIN</code>) to be skipped for all but the function level block, requiring only a block terminating token (<code>}</code> or <code>END</code>). It also fixes [[dangling else]]. Custom is for the <code>end</code> token to be placed on the same indent level as the rest of the block, giving a blockstructure that is very readable. One advantage to the [[Fortran]] approach is that it improves readability of long, nested, or otherwise complex code. A group of outdents or closing brackets alone provides no contextual cues as to which blocks are being closed, necessitating backtracking, and closer scrutiny while [[debugging]]. Further, languages that allow a suffix for END-like keywords further improve such cues, such as <code>continue</code> versus <code>continue for x</code>, and [[For loop#1964: BASIC | end-loop marker specifying the index variable]] <code>NEXT I</code> versus <code>NEXT</code>, and [[For loop#Early exit and continuation | uniquely named loops]] <code>CYCLE X1</code> versus <code>CYCLE</code>. However, modern [[source code editor]]s often provide visual indicators, such as [[syntax highlighting]], and features such as [[code folding]] to assist with these drawbacks.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)