Talk:Off-side rule

Latest comment: 2 months ago by Stevebroshar in topic How is it a better mouse trap?

Specific or general edit

The page doesn't specify whether "the off-side rule" refers to this particular definition of using indent to signify blocks, or any such ruleset. — Preceding unsigned comment added by 81.191.75.7 (talk) 21:58, 29 July 2015 (UTC)Reply

Either this has already been addressed or I don't understand your concern. It does seem to have a rather specific meaning yet may vary a little between languages where it's deployed. So, the answer to your concern is: yes? Stevebroshar (talk) 13:30, 13 February 2024 (UTC)Reply

Origin and meaning edit

I tried looking at the various sporting uses of "off-side", but couldn't see any obvious conceptual link to the indentation rule use. Where, and how, did it originate? --Piet Delport 09:55, 26 December 2005 (UTC)Reply

I'm not sure I understand your question, and perhaps you saw this already, but the cited article by Landin includes the following:
(c) Indentation, used to indicate program structure. A physical ISWIM can be defined in terms of an unspecified parameter: a subset of phrase categories, instances of which are restricted in layout by the following rule called "the offside rule." The southeast quadrant that just contains the phrase's first symbol must contain the entire phrase, except possibly for bracketed subsegments. This rule has three important features. It is based on vertical alignment, not character width, and hence is equally appropriate in handwritten, typeset or typed texts. Its use is not obligatory, and use of it can be mixed freely with more conventional alternatives like punctuation. Also, it is incorporated in ISWIM in a systematic way that admits of alternatives without changing other features of ISWIM and that can be applied to other languages.
Conclusions of the article end in the following paragraph:
It is assumed that future calls on language development cannot be forstalled without generalizing the alternatives to explicit sequencing. The innovations of "program-points" and the "off-side rule" are directed at two of the problems (respectively in the areas of semantics and syntax) that must consequently be faced.
--TuukkaH 16:56, 26 December 2005 (UTC)Reply
OK, that shows the term being coined, but still without any explanation of why is it called the "off-side" rule. I assume the name is intended to carry the connotations of some existing concept, but what is it? --Piet Delport 12:43, 31 December 2005 (UTC)Reply
Right. We can come up with some possible explanations :-) There's off-shore and off-road meaning away from a thing, so off-side could be "away from the side, indented". Perhaps there were other indentation rules already, and Landin wanted a distinct name? How could we know what Landin really thought? We can hope we find him explaining this :-) --TuukkaH 15:23, 31 December 2005 (UTC)Reply

Some comments edit

With regard to the discussion above, about the connection with the sporting meaning of "off-side", I'll point out that in the sport known as "soccer" in the USA, and "football" everywhere else in the known universe, the offside rule is generally acknowledged as the hardest to understand and to explain to outsiders. It is, nevertheless, a crucial rule whose abolition changes the game entirely.

But that's not what brought me here. The page has the following:

"(note also the obligatory colons — they are merely syntactical markers to make it easier to read)"

Are you sure you mean "obligatory"? Perhaps you mean "traditional". It's not possible for something to be both obligatory and optional at the same time.

Also, the article is still marked as a stub, although I can't think of anything much that needs adding to it. I suggest that the "stub" template be removed.--Nyelvmark 00:24, 8 September 2007 (UTC)Reply

Colons aren't optional. What the quote is means is that they aren't nescessary to make the language interpretable, but are in the language simply to make it more readable. Ragzouken 13:35, 16 October 2007 (UTC)Reply
I think the confusion here is between the particular syntax of Python and the syntax that off-side implies. In Python, the colons are required syntax -- necessary to make interpretable. It's possible that the Python designers used that syntax to enhance code readability, but that is way off topic for this article. The point IMO is that that colon syntax is required by Python syntax, but is not required to implement a off-side rule in a general sense. FWIW I think this article would be much better if there was an additional example in a language that doesn't use the colon syntax. Stevebroshar (talk) 13:40, 13 February 2024 (UTC)Reply

It's amazing how the omission of such a small word - "not" - can make such a big difference. Fortunately, someone has now quietly added it, converting a piece of execrable time-wasting garbage into a piece which may be useful to somebody, someday (if, indeed, it's now accurate).

Python edit

Although it may apply to the Python language, the term is very seldom used within the community. --Paddy (talk) 04:02, 20 February 2008 (UTC)Reply

What term is used? Stevebroshar (talk) 13:45, 13 February 2024 (UTC)Reply

Alas, this is all original research, but I wanted to get my thoughts out to see if they point towards some published work. The term "off-side rule" is not used in the Python community because while technically the parser uses it, Python statements are almost always indented by a set number (usually 4) of spaces for each level of nesting. (The off-side rule is thus more general than the fixed indentation that devs actually use.) Being imperative, Python has two broad categories of syntactic elements, statement and expression. (See compound_statement and contrast with expr.) Statements always have a header, which is always on its own line, while expressions are arbitrarily nested within brackets. Because statements are always on their own line, it's more natural to indent their "suite" (subordinate statements) by a fixed amount. Contrast with Haskell devs, who fully use the off-side rule: it only has expressions and often more nesting. Thus in Haskell indenting by varying amounts is quite common and in this article you can see various examples of indentation that you'll rarely (if ever) see in Python. 2600:1003:B004:D076:DD9:5E02:D54C:2B1E (talk) 14:36, 27 August 2019 (UTC)Reply

That could be said for many languages; while technically C is free-form, C statements are almost always indented by a set number of space for each level of nesting. What "technically" the parser does seems more interesting than how it's used in practice.--Prosfilaes (talk) 13:20, 30 August 2019 (UTC)Reply
I don't get the point of 2600:1003:B004:D076:DD9:5E02:D54C:2B1E either. "Python statements are almost always indented by a set number of spaces for each level of nesting" ... because they have to be! yes, not only for style like for a free-from language. That's the point of this article. The parser uses indentation as syntax. Stevebroshar (talk) 13:48, 13 February 2024 (UTC)Reply

Left versus right edit

At http://en.wikipedia.org/wiki/Off-side_rule#Definition I don't doubt the historical accuracy of the Landin quote, but hasn't he confused left for right? That is to say, isn't this

....'....1...'...2...'...3...'...
          first-token-on-the-previous-line
     token-to-the-LEFT-of-the-first-token-on-the-previous-line
an example of what he describes using the word left?


I think he means, by "start of a _new_ declaration", that one is no longer inside the old one (which would be the inner scope). Although it's really not understandable. --81.191.75.7 (talk) 22:09, 29 July 2015 (UTC)Reply




Hasn't Landin in fact (by using "left" instead of "right") inadvertently described OUTdenting? Xojo (talk) 19:15, 30 July 2009 (UTC)Reply



No, advertently. See the previous comment. The rule defines when a declaration starts by defining when the previous one finishes. (Actually, in Python he would mean a statement rather than a declaration, but that's a separate issue...)

Main advantage of curly braces edit

A section needs to be rewritten.

Regarding the C-style curly braces instead of indenting, the article says "The main advantage of this is that it makes it possible for tools to correct the indentation automatically."

That isn't an *advantage* of the alternative, it's a crutch that people use to make their code more readable. An advantage of this alternative might be that it is up to the developer to indent however they need to -- including not indenting shorter blocks if they want, while still indenting longer blocks. Another advantage might be that it makes parsing of the language a little easier. — Preceding unsigned comment added by 71.13.147.17 (talk) 18:15, 25 July 2012 (UTC)Reply

exactly, that’s stupid: if the program doesn’t compile when indented incorrectly, there’s no reason for relying on a tool that corrects indentation, correct indentation is simply enforced. I’ll delete that part and replace it with the arguments you mention. — Flying sheep (talk) 19:48, 2 January 2013 (UTC)Reply

aka "syntactically significant whitespace" edit

I think "syntactically significant whitespace" is standard term for this, including in Python community. 76.119.30.87 (talk) 16:52, 25 March 2014 (UTC)Reply

Merge with "Free-form language" edit

This page should be merged with Free-form language under a neutral name like "whitespace significance" or "block syntax". Jruderman (talk) 11:00, 28 December 2014 (UTC)Reply

Not exactly correct: Python syntax is "Off-side rule" but it isn't Free-form language.
"Off-side rule" is not widely used among programmers and poorly sourced. Ushkin N (talk) 05:41, 22 May 2016 (UTC)Reply
Definitely not. Off-side is basically the opposite of free-form. Stevebroshar (talk) 13:25, 13 February 2024 (UTC)Reply

This concept stands in stark contrast to free-form language elements (of which even Python includes a few). It might make sense to create a single "compare and contrast" page covering different approaches to block structuring in a text medium such as are used in programming languages, mark-up languages, etc. — Preceding unsigned comment added by 141.197.12.183 (talk) 18:09, 5 April 2017 (UTC)Reply

Off-side or offside? edit

I can see that Landin did indeed spell it off-side in his Next 700 Porgramming Languages paper in 1965. But it looks to me like sources today (including a couple I just added) tend to spell it as a single word. In Google searches for Landin "offside rule" versus Landin "off-side rule", the unhypenated spelling is 1.48x as frequent on the web (4,680 hits versus 3,170 hits) and 4.55x as frequent in books(182 hits versus 40 hits), This isn't a huge difference but per WP:COMMONNAME, I believe it might be enough to justify renaming the article Offside rule (programming). Opinions, please? Msnicki (talk) 17:10, 3 September 2015 (UTC)Reply

Unhyphenated is the case in [association] football and rugby, but as long as it's not offsides I can live with it. 2A02:2788:1008:6D6:E2CB:4EFF:FE88:1A2D (talk) 14:35, 18 April 2022 (UTC)Reply
Spelling does change and in particular gets simplified over time. I recommend using the common spelling first and throughout along with the old spelling as a.k.a. or formerly or some such. ... but the hard part is this: how does one make such a change without falling prey to the no-original-research rule? Not that I wouldn't make the change :) but I do struggle internally with the pesky original research rule. Stevebroshar (talk) 13:23, 13 February 2024 (UTC)Reply

To merge or not to merge? edit

It has been proposed to merge this into Control Flow. Arguably, offside rule is about block structure, not control flow per se. There are plenty of concepts well expressed in modern languages through block structure. Sticking to the Python example, while technically class and function definitions are executable in their own right, that's usually considered an implementation detail. (Cases where it matters are few and found principally in metaprogramming.) Branching into the slightly-more-abstract, one can easily imagine an offside rule delimiting literal structured data of the sort not meant for interpretation also as code. More concretely, YAML is very deliberately a data-only language using the off-side rule for block structure.

On balance, this page ought to be fleshed out with examples like YAML and not merged with control flow. — Preceding unsigned comment added by 141.197.12.183 (talk) 18:03, 5 April 2017 (UTC)Reply

Strong no on merging with control flow. I see WAY too much merging of terms on wikipedia. Just because terms are related, even a specialization, does not mean they should be covered on the same page. Pages are cheap. Every term should have its own ... for various reasons including linking.
If YAML has an off-side rule, then add an example. The page only has Python example rn and would be improved with an example for another language. Stevebroshar (talk) 13:20, 13 February 2024 (UTC)Reply


In some languages (but not Pascal), this means that newlines are important edit

The only example that comes to my mind is the C preprocessor. I'm not sure whether that can be considered a programming language — Preceding unsigned comment added by 198.176.82.33 (talk) 10:08, 6 October 2017 (UTC)Reply

Seconded. If you can logically replace begin...end with {...} or whatever I don't see the difference. If some languages or implementations thereof have chosen to make it so, that's accidental not essential. 2A02:2788:1008:6D6:E2CB:4EFF:FE88:1A2D (talk) 14:38, 18 April 2022 (UTC)Reply
BASIC and in particular Visual Basic use newline for special meaning. But... this point and most of the 'alternatives' section is way off topic. Stevebroshar (talk) 13:59, 13 February 2024 (UTC)Reply

There is no mention of this term that doesn't reference Wikipedia edit

I haven't found a single mention of the term "off-side rule" regarding syntactically significant indentation that doesn't reference this Wikipedia article or "The next 700 programming languages". I am a software engineer, and I have never heard this term before. This site should be called "Syntactically significant indentation" (or "...whitespace", as another user has mentioned before), because that's what it is. There is no reason to call it "off-side rule", only because someone (even Peter Landin) called it that once. — Preceding unsigned comment added by 2A02:810D:4740:8F7C:D4DE:89C3:E67E:C72 (talk) 23:36, 18 May 2018 (UTC)Reply

FORTRAN and ALGOL edit

I wonder whether it would be worth noting that FORTRAN had an explicit significant-whitespace rule, in that originally labels had to start in column 1 of an input record (usually a punched card) and normal statements in column 7?

In addition I believe that at least some ALGOL-60 implementations treated anything after an END as a comment, stopping at end-of-line.

Both of the above are distinct from certain columns being reserved for sequence numbers. MarkMLl (talk) 08:53, 29 May 2019 (UTC)Reply

Hmm. IDK. I see the similarity. I'm pretty sure that whatever offside rule means was not intended to cover that aspect of FORTRAN (and punch cards). Further seems a stretch to use offside to mean that. But, could be an interesting side-note about a related factoid. In general, it's hard to organize information into neat boxes like terms and pages. So much overlap. Makes my head hurt thinking about. Stevebroshar (talk) 14:07, 13 February 2024 (UTC)Reply

Does this article need a new name? edit

I think it does. And perhaps a new scope. The term "off-side rule" would be mentioned in the article, but should not be the focus. I'll look to see if there is already an article that discusses the concept of a programming language or markup language that uses indentation to define blocks. - Bevo (talk) 13:06, 5 June 2019 (UTC)Reply

Bevo: any luck with that search :) Stevebroshar (talk) 14:09, 13 February 2024 (UTC)Reply

On the reference to the "Goto Fail" bug edit

Section "Alternatives" mentions that "sloppily indented code might lead the reader astray, such as the goto fail bug.". While the claim is true, the goto fail bug was not caused by sloppy indentation, but rather the exact opposite: that the developers relied on indentation as opposed to brackets, in a language that uses brackets. I think that this reference should be removed. Matt-bacon-bcm (talk) 02:40, 21 June 2021 (UTC)Reply

Alternatives section is way off topic edit

I think most of the existing Alternatives section should be deleted. It's 5 lengthy paragraphs rn about what offside is not. It's well-intentioned, but as often happens on wikipedia pages, folks incrementally add information that diverges from the central focus of the page topic. The result tortures the reader with unrelated information. A couple sentences and a few links to related topics should be enough to cover alternatives. Don't need to describe the alternatives in gory detail; just reference them. Stevebroshar (talk) 14:17, 13 February 2024 (UTC)Reply

What is this thing? edit

Some folks have commented that 'offside rule' (off-side rule) is not a common term and the term used here should instead be something that's more commonly used. ... but what might that term be?

The page includes significant indentation and I see a comment using syntactically significant whitespace.

Here's my struggle: How can a term be chosen without doing original research? Determining which terms is the most common seems to require research, right? And most likely there is no primary or secondary source that says which term is most common. Someone can use online tools (like google) to determine which is most used in available info worldwide; but that's research, right?

FYI This must be a common struggle for wikipedia and defining terms in general. Every term has it's own connotation and the not 100% interchangeable with another term. I have struggled personally with the page function (computer programming). Stevebroshar (talk) 14:27, 13 February 2024 (UTC)Reply

How is it a better mouse trap? edit

This articles covers what the offside rule is; which is good. But a major aspect of technology is that it is invented to solve a problem; to improve something that has limitations. Why was this rule invented? What limitations does it solve?

The alternatives section covers blocking syntax of other languages -- which IMO is off topic. But, a discussion of how offset is better or worse than other syntaxes would be valuable. Stevebroshar (talk) 14:38, 13 February 2024 (UTC)Reply