Tabs
-
Taking off from the tabs vs spaces post few threads below, I was wondering why they were talking about tab = 8 spaces. Does it not make the code unreadable as it is too spaced out? When tab is set to 8 spaces: if (true) { // Indent of 1 tab = 8 spaces if (true) { // some thing here } } When tab is set to 4 spaces: if (true) { // Indent of 1 tab = 4 spaces if (true) { // some thing here } }
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]
lw@zi wrote:
I was wondering why they were talking about tab = 8 spaces.
What do you mean "we" ? For a coding application I set tab at four, or even two. It's a bit font-dependent. As for your code sample, all eyes are different, but for your 4-space tab I'd make it:
if (true) {
// Indent of 1 tab = 4 spaces
if (false) {
// some thing here
} // if(false)
} // if(true)I particularly draw your attention to two three conventions:
- Opening brace on same line as conditional
- Closing brace under begfinning of its conditional
- Comment containing matching conditional clearly identifies the end
The labling of the closing brace is invaluable when you look at the stuff some day further along in history and need to see what's what very quickly (or at least more quickly).
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
The 8 space idea was around from the early days of Unix, and the only the terminals were basic teletypes (electric typewriters). I Have never understood why anyone thought that was a good idea on a device that generally could only print 80 characters across the page.
I'd think that it is older than Unix. In Fortran, cols 1-5 were reserved for labels. Col 6 was for a line continuation marker. You could start your code in col 7, but then the continuation marker would be adjacent to the code, possibly disturbing the reading of the line (if, say, you use digits 1, 2, 3... to mark the order of continuation lines, and the code line starts with a numeric. So you set the tab stop at 8. In the Fortran days, indenting loops was not very common; code was written from pos 8 - the left margin labels were good enough marking of loops. The problem of rightward migration of the source code was not relevant. In those days, it was common to have arbitrary tab stops (like on most old mechanical typewriters). Often, a programming language recommended certain tab stops: If my memory is correct, Fortran (if you used tabs at all!) recommended stops at 8, 14, 20 and then for every 10. On a punched card, there was no way to tell if you had moved out to col 14 using the tab stop or the space bar - either left no hole! When evenly spaced tab stops were getting common, there were some fighting about what comes after 8 - is it 15 (the first tab brought you 7 positions out from the margin, 8 + 7 = 15)? Or is it 16, (counting starts at 0, so n tabs brings you to position 8*n)? Or 17, the first one 8 cols out from the margin, i.e. at pos 9? If Fortran had still been strong, I guess the third alternative (9, 17, 25...) would have been rejected, but it is the most consistent and easiest to handle, so it won. If there had never been any disagreemet about the positions/intervals, causing chaos in line/table layout when moving text files around, maybe tabs would have been popular today. More and more people are rejecting it, both because of the non-standardization and (among software developers) because they came to hate it through makefiles. In modern days the tab key has become common as a navigation key in GUIs, for moving to the next edit field, which further discourages its use as a text input key. Python is actively discouraging tabs. I am happy about it. As an input method, it is fine, as long as it has the semantics of "Space fill up to the next tab position" (rather than inserting a tab character code into the file). I hate it when some tab-loving co-worker edits "my" files, and garbles up some nicely lined up declarations, comments etc. Some garble not only the lines they edit, inserting tab characters, but their editors (don't ask me which one they are using) replace any r
-
I'd think that it is older than Unix. In Fortran, cols 1-5 were reserved for labels. Col 6 was for a line continuation marker. You could start your code in col 7, but then the continuation marker would be adjacent to the code, possibly disturbing the reading of the line (if, say, you use digits 1, 2, 3... to mark the order of continuation lines, and the code line starts with a numeric. So you set the tab stop at 8. In the Fortran days, indenting loops was not very common; code was written from pos 8 - the left margin labels were good enough marking of loops. The problem of rightward migration of the source code was not relevant. In those days, it was common to have arbitrary tab stops (like on most old mechanical typewriters). Often, a programming language recommended certain tab stops: If my memory is correct, Fortran (if you used tabs at all!) recommended stops at 8, 14, 20 and then for every 10. On a punched card, there was no way to tell if you had moved out to col 14 using the tab stop or the space bar - either left no hole! When evenly spaced tab stops were getting common, there were some fighting about what comes after 8 - is it 15 (the first tab brought you 7 positions out from the margin, 8 + 7 = 15)? Or is it 16, (counting starts at 0, so n tabs brings you to position 8*n)? Or 17, the first one 8 cols out from the margin, i.e. at pos 9? If Fortran had still been strong, I guess the third alternative (9, 17, 25...) would have been rejected, but it is the most consistent and easiest to handle, so it won. If there had never been any disagreemet about the positions/intervals, causing chaos in line/table layout when moving text files around, maybe tabs would have been popular today. More and more people are rejecting it, both because of the non-standardization and (among software developers) because they came to hate it through makefiles. In modern days the tab key has become common as a navigation key in GUIs, for moving to the next edit field, which further discourages its use as a text input key. Python is actively discouraging tabs. I am happy about it. As an input method, it is fine, as long as it has the semantics of "Space fill up to the next tab position" (rather than inserting a tab character code into the file). I hate it when some tab-loving co-worker edits "my" files, and garbles up some nicely lined up declarations, comments etc. Some garble not only the lines they edit, inserting tab characters, but their editors (don't ask me which one they are using) replace any r
Quite possibly, although when I was writing Fortran & Cobol, all input was hand written to coding forms and sent to the Data Preparation department, where it would be punched onto Hollerith cards by a team of pretty young girls. And since neither language was free form the issue of tabs never arose as far as I know. Assembler was similarly fixed although by convention the operator field was set at column 11, operands at 21, and comments at 39.
-
lw@zi wrote:
I was wondering why they were talking about tab = 8 spaces.
What do you mean "we" ? For a coding application I set tab at four, or even two. It's a bit font-dependent. As for your code sample, all eyes are different, but for your 4-space tab I'd make it:
if (true) {
// Indent of 1 tab = 4 spaces
if (false) {
// some thing here
} // if(false)
} // if(true)I particularly draw your attention to two three conventions:
- Opening brace on same line as conditional
- Closing brace under begfinning of its conditional
- Comment containing matching conditional clearly identifies the end
The labling of the closing brace is invaluable when you look at the stuff some day further along in history and need to see what's what very quickly (or at least more quickly).
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
I do not see why the inner "if" is indented 2*4 spaces. I think it should line up with the first comment. Small sidetrack: Your style of commenting the end brace to indicate what it terminates can be very helpful in complex code. But what I long back to is the CHILL style: Any block can be labeled (the label applies to the block, not to a point in the code). If you repeat the label after the closing brace, the compiler will check it, giving a compilation error if it doesn't match. You could also break out to any outer block level, referring to the block label. Like
Outerloop: if (true) {
Innerloop: while (moreToDo) {
// some thing here
if (reasonToTerminate) exit Outerloop;
} Innerloop;
} Outerloop;This is far more readable and far safer. Unfortunately, it isn't straightforward to introduce it into the syntax of C class of languages. But as an emergency solution, your comments is a great alternative. Not necessarily for 2-line innermost loops/ifs, but certainly when the loop/if spans a dozen lines or more.
-
lw@zi wrote:
I was wondering why they were talking about tab = 8 spaces.
What do you mean "we" ? For a coding application I set tab at four, or even two. It's a bit font-dependent. As for your code sample, all eyes are different, but for your 4-space tab I'd make it:
if (true) {
// Indent of 1 tab = 4 spaces
if (false) {
// some thing here
} // if(false)
} // if(true)I particularly draw your attention to two three conventions:
- Opening brace on same line as conditional
- Closing brace under begfinning of its conditional
- Comment containing matching conditional clearly identifies the end
The labling of the closing brace is invaluable when you look at the stuff some day further along in history and need to see what's what very quickly (or at least more quickly).
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
W∴ Balboos, GHB wrote:
Opening brace on same line as conditional
Only in Java. C,C++ and C# it goes on the next line under the "i" character. ;P And if you would like to see something truly horrible with braces, take a look at some of @OriginalGriff's code.
-
W∴ Balboos, GHB wrote:
Opening brace on same line as conditional
Only in Java. C,C++ and C# it goes on the next line under the "i" character. ;P And if you would like to see something truly horrible with braces, take a look at some of @OriginalGriff's code.
-
Quite possibly, although when I was writing Fortran & Cobol, all input was hand written to coding forms and sent to the Data Preparation department, where it would be punched onto Hollerith cards by a team of pretty young girls. And since neither language was free form the issue of tabs never arose as far as I know. Assembler was similarly fixed although by convention the operator field was set at column 11, operands at 21, and comments at 39.
I suffered the same problems for my first year at the U. The first run was always to identify they typos that the ladies had made. We had a couple of punches available for making corrections, but there was a sign telling that after punching 8 cards, you had to yield to the next one in line. During my 2nd year, we went from that huge Univac 1110 filling a big hall to three single-rack 16 bit minis, each handling 20 interactive terminals (and they did it well!). The great, expensive Univac had interactive terminals too, reserved for special (mostly post-graduate) projects, running at 300 bps. Although the mini could easily handle 9600 bps lines, we were ordered to reduce the speed to 1200 bps so that the proud Univac would not totally loose its face :-) We (that is, the TAs) had certain authorizations, so as soon as the professors went home for supper, and eager students would work through the night on the minis, we raised the line speed. As you point out, assembler is another language (class) where unevenly spaced tab stops were/are common.
-
I'd think that it is older than Unix. In Fortran, cols 1-5 were reserved for labels. Col 6 was for a line continuation marker. You could start your code in col 7, but then the continuation marker would be adjacent to the code, possibly disturbing the reading of the line (if, say, you use digits 1, 2, 3... to mark the order of continuation lines, and the code line starts with a numeric. So you set the tab stop at 8. In the Fortran days, indenting loops was not very common; code was written from pos 8 - the left margin labels were good enough marking of loops. The problem of rightward migration of the source code was not relevant. In those days, it was common to have arbitrary tab stops (like on most old mechanical typewriters). Often, a programming language recommended certain tab stops: If my memory is correct, Fortran (if you used tabs at all!) recommended stops at 8, 14, 20 and then for every 10. On a punched card, there was no way to tell if you had moved out to col 14 using the tab stop or the space bar - either left no hole! When evenly spaced tab stops were getting common, there were some fighting about what comes after 8 - is it 15 (the first tab brought you 7 positions out from the margin, 8 + 7 = 15)? Or is it 16, (counting starts at 0, so n tabs brings you to position 8*n)? Or 17, the first one 8 cols out from the margin, i.e. at pos 9? If Fortran had still been strong, I guess the third alternative (9, 17, 25...) would have been rejected, but it is the most consistent and easiest to handle, so it won. If there had never been any disagreemet about the positions/intervals, causing chaos in line/table layout when moving text files around, maybe tabs would have been popular today. More and more people are rejecting it, both because of the non-standardization and (among software developers) because they came to hate it through makefiles. In modern days the tab key has become common as a navigation key in GUIs, for moving to the next edit field, which further discourages its use as a text input key. Python is actively discouraging tabs. I am happy about it. As an input method, it is fine, as long as it has the semantics of "Space fill up to the next tab position" (rather than inserting a tab character code into the file). I hate it when some tab-loving co-worker edits "my" files, and garbles up some nicely lined up declarations, comments etc. Some garble not only the lines they edit, inserting tab characters, but their editors (don't ask me which one they are using) replace any r
Member 7989122 wrote:
We did have a pre-commit plugin rejecting commit of files with tab stops, but then there were projects still using classical makefiles, so we had to slack up on that.
Find a plugin that can be configured to have exceptions for makefiles and anything else that's tool generated?
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
W∴ Balboos, GHB wrote:
Opening brace on same line as conditional
Only in Java. C,C++ and C# it goes on the next line under the "i" character. ;P And if you would like to see something truly horrible with braces, take a look at some of @OriginalGriff's code.
Richard MacCutchan wrote:
Only in Java.
Also javascript. Who the :elephant: thought magic semicolon insertion by the runtime was a good idea. X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| X| &
-
I suffered the same problems for my first year at the U. The first run was always to identify they typos that the ladies had made. We had a couple of punches available for making corrections, but there was a sign telling that after punching 8 cards, you had to yield to the next one in line. During my 2nd year, we went from that huge Univac 1110 filling a big hall to three single-rack 16 bit minis, each handling 20 interactive terminals (and they did it well!). The great, expensive Univac had interactive terminals too, reserved for special (mostly post-graduate) projects, running at 300 bps. Although the mini could easily handle 9600 bps lines, we were ordered to reduce the speed to 1200 bps so that the proud Univac would not totally loose its face :-) We (that is, the TAs) had certain authorizations, so as soon as the professors went home for supper, and eager students would work through the night on the minis, we raised the line speed. As you point out, assembler is another language (class) where unevenly spaced tab stops were/are common.
Member 7989122 wrote:
huge Univac 1110
I worked on a number of Univac systems from the 1108 to 2200/800 systems. Most of my time was spent poring over 500 page (printed) memory dumps trying to find bugs in the operating system. But at least it gave me job security. :-D
-
Richard MacCutchan wrote:
C,C++ and C# it goes on the next line under the "i" character.
At least for C++--the others are irrelevant dreck--you are correct, and people should harken to someone so venerable. :)
-
Greg Utas wrote:
dreck
That was a common term when I lived in Manchester, but I have not heard it for years. Is it common in your city/province?
-
Quite possibly, although when I was writing Fortran & Cobol, all input was hand written to coding forms and sent to the Data Preparation department, where it would be punched onto Hollerith cards by a team of pretty young girls. And since neither language was free form the issue of tabs never arose as far as I know. Assembler was similarly fixed although by convention the operator field was set at column 11, operands at 21, and comments at 39.
Quote:
a team of pretty young girls
You had pretty young girls? Back when I was doing coding sheets they were a team of middle-aged angry women! Try telling that to the kids of today!
- I would love to change the world, but they won’t give me the source code.
-
Member 7989122 wrote:
We did have a pre-commit plugin rejecting commit of files with tab stops, but then there were projects still using classical makefiles, so we had to slack up on that.
Find a plugin that can be configured to have exceptions for makefiles and anything else that's tool generated?
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
Dan Neely wrote:
Find a plugin that can be configured to have exceptions for makefiles and anything else that's tool generated?
We didn't have to find another tool, just to reconfigure the one we had. But the first decision, to deny tabs from anything that consisted of plain text, has to be revised.
-
Member 7989122 wrote:
huge Univac 1110
I worked on a number of Univac systems from the 1108 to 2200/800 systems. Most of my time was spent poring over 500 page (printed) memory dumps trying to find bugs in the operating system. But at least it gave me job security. :-D
Then you may know the one-operand infinite loop of 1108 - it didn't even take the whole of an instruction to create an infinite loop. I don't remember all the details of Univac addressing formats, so this description may not be a 100% exact: You could set a bit in the address field for one extra level of indirection - in the location given, you won't find the data, but the address of the data. There you might find another address with the indirection bit set. Any levels of indirection was allowed, all executed as part of the operand value decoding. If you set up one such indirection pointing to itself, you had a single operand version of an unconditional jump to itself. Only that while decoding that indirection, the CPU didn't respond to interrupts. A single-instruction loop could be broken, e.g. by the system operator. The single-operand loop totally locked up the entire CPU; it had to be rebooted - which, for a Univac 1100 system was something more than Ctrl-Alt-Del :-). Most graduate, "responsible" students were aware of this quick way of taking the system down, but everyone tried to keep it secret to the younger, and potentially less responsible, student who might want to "try it out for fun". The U had an old 1108 and a new 1110. I don't think the 1110 went down many times (if at all) from one-operand infinite loops. It could be that Univac had made it interruptible on the 1110, or it could be that my generation of students never did assembly programming on the Univac; we were on our way into the OO world (beliving that Simula would forever be The superhero of OO languages...). Very few of my fellow students ever saw the U1100 instruction set and addressing modes at all.
-
W∴ Balboos, GHB wrote:
Opening brace on same line as conditional
Only in Java. C,C++ and C# it goes on the next line under the "i" character. ;P And if you would like to see something truly horrible with braces, take a look at some of @OriginalGriff's code.
Richard MacCutchan wrote:
Only in Java. C,C++ and C# it goes on the next line under the "i" character
I was speaking in terms of coding professionals and should have made that clearer!
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
I do not see why the inner "if" is indented 2*4 spaces. I think it should line up with the first comment. Small sidetrack: Your style of commenting the end brace to indicate what it terminates can be very helpful in complex code. But what I long back to is the CHILL style: Any block can be labeled (the label applies to the block, not to a point in the code). If you repeat the label after the closing brace, the compiler will check it, giving a compilation error if it doesn't match. You could also break out to any outer block level, referring to the block label. Like
Outerloop: if (true) {
Innerloop: while (moreToDo) {
// some thing here
if (reasonToTerminate) exit Outerloop;
} Innerloop;
} Outerloop;This is far more readable and far safer. Unfortunately, it isn't straightforward to introduce it into the syntax of C class of languages. But as an emergency solution, your comments is a great alternative. Not necessarily for 2-line innermost loops/ifs, but certainly when the loop/if spans a dozen lines or more.
I think I fixed the (accidental) double indent. As for the use of labels - no compiler differences to worry about if you keep it all in comment form. Maybe it's just me, but have a consistent convention across all of the coding languages is rather helpful at my age.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
Then you may know the one-operand infinite loop of 1108 - it didn't even take the whole of an instruction to create an infinite loop. I don't remember all the details of Univac addressing formats, so this description may not be a 100% exact: You could set a bit in the address field for one extra level of indirection - in the location given, you won't find the data, but the address of the data. There you might find another address with the indirection bit set. Any levels of indirection was allowed, all executed as part of the operand value decoding. If you set up one such indirection pointing to itself, you had a single operand version of an unconditional jump to itself. Only that while decoding that indirection, the CPU didn't respond to interrupts. A single-instruction loop could be broken, e.g. by the system operator. The single-operand loop totally locked up the entire CPU; it had to be rebooted - which, for a Univac 1100 system was something more than Ctrl-Alt-Del :-). Most graduate, "responsible" students were aware of this quick way of taking the system down, but everyone tried to keep it secret to the younger, and potentially less responsible, student who might want to "try it out for fun". The U had an old 1108 and a new 1110. I don't think the 1110 went down many times (if at all) from one-operand infinite loops. It could be that Univac had made it interruptible on the 1110, or it could be that my generation of students never did assembly programming on the Univac; we were on our way into the OO world (beliving that Simula would forever be The superhero of OO languages...). Very few of my fellow students ever saw the U1100 instruction set and addressing modes at all.
-
Richard MacCutchan wrote:
Only in Java. C,C++ and C# it goes on the next line under the "i" character
I was speaking in terms of coding professionals and should have made that clearer!
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
I think I fixed the (accidental) double indent. As for the use of labels - no compiler differences to worry about if you keep it all in comment form. Maybe it's just me, but have a consistent convention across all of the coding languages is rather helpful at my age.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
Certainly a valid argument - in particular when that is your only choice (but of course: Comment syntax varies across languages, and some languages don't even have an explicit block terminator to which you can affix your comment; you have to create a separate comment line, and must explain it by eg. "// end of if (condition)" so that it doesn't look as a commented-out if-statement. And you don't get the compiler check. But if you can't get that, anyway, you certainly haven't lost anything. I fully support you commenting style here. Yet I keep wishing that we had compiler support for it, and a simpler and cleaner syntax. ... Bemoaning what you can't get, begets nothing. Yet, moaning is a sort of self-comforting in hard times.