473,769 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change the length of "\t"?

Hi,

It is possible to change the length of "\t" to a number other than 8.

std::cout << "\t";

Thanks,
Peng
Jul 14 '08
25 30987
On Jul 15, 7:01 pm, "Alf P. Steinbach" <al...@start.no wrote:
* James Kanze:
Using anything other than 8 for tabstops is a dumb thing,
since that's the universal defacto standard today (and you
certainly don't look at text only in an editor).
I'm sorry, but that's not correct. The de facto Windows
standard is 4 character positions per tab stop. Tools from
early eighties (e.g. Notepad) excepted.
Windows doesn't make the standard; it was established long
before windows appeared.

And a quick check on my Windows machine showed it using 8 as
well (under Windows XP). So I'm not sure what you're talking
about when you speak of 4; until your statement above, I had
assumed that it was a personal configuration of the editor.

If they did try to make it 4... Trying to change such an
established standard is almost as dumb as another systems
attempt to change the de facto standard for line endings (which
is, of course, CR,LF).
Regarding what's dumb, the *nix de facto standard of 8
character positions per tab stop is clearly dumb, since it's
impractical for anything,
Historically, I don't know where the 8 comes from; it was the de
facto standard before I got into computer programming, and that
goes back some. Before Windows or Unix.
and the lack of a standard for indicating the tab stop and
indentation settings of source code is clearly dumb (would be
a good candidate for a new C++ preprocessor directive :-)).
But I'm pretty sure that folks who have not enjoyed the
benefits of working in an environment with consistent 4-tabs,
actually using tabs in source code, will not immediately grasp
why any of the abovementioned should be dumb. After all, we
manage quite fine without using tabs at all, thank you.
Yes. You shouldn't use tabs in your source code; that much is
clear. And there's no problem with an editor doing whatever it
wants with the tab key (emacs reindents the line according to
its idea of how it should be indented). The problem is when the
editor (or any other program) inserts a tab character in the
code, or displays an existing tab character as if tab stops were
anything else but 8.
If you're using an indentation other than 8 (and 8 is too
big), then you have to use some spaces for the indentation.
(Because people are stupid enough to set tabstops in their
editor at something different than 8, I've given up using
tabs at all in text files. Just spaces, so everyone will
see the code as it was meant to be formatted.)
Using spaces instead of tabs is a good recommendation for
cross-platform work, and it is, for example, the solution
adopted by Boost.
Not just cross platform. It comes into play anytime you do a
diff or whatever Windows equivalent of grep is. (I'll admit
that I'm lazy---rather than learn the Windows tools for such
essential tasks, I just installed a Unix tool kit. Which is far
from ideal, but since I already know it, and don't work enough
under Windows to justify learning anything else...)

Letting the editor indent however much you want (I like four,
but three or five is also acceptable) is also a good thing; just
get everyone on the project to agree. And make sure that when
the indentation gets into the files, it's as spaces, not tab
characters, or you'll run into problems downstream.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 15 '08 #21
In article <e9f92aeb-08bd-44bc-aeda-
4a**********@f3 6g2000hsa.googl egroups.com>, ja*********@gma il.com
says...

[ ... ]
Could you explain please. Starting with what use you see for
tabs.
Well, almost none, quite frankly...
They don't occur in written text, or at least, you can't
distinguish between a tab character and so many spaces.
Historically, they ended up in files as a very primitive means
of reducing file size---and 8 apparently worked well there.
Not really -- 8 was used there, but never worked worth a darn, IMO.
(Note that the critical position in Fortran is 72. A multiple
of 8.)
....and therefore, also a multiple of 4.
Today, frankly, I don't see much use of them in files at
all, and find the best solution is to ban them. Except that
some old programs (like make) still require them. (And I agree
that for make, 4 would be better. But 8 is still quite usable.)
To be honest, I was thinking primarily in terms of people who still use
them for indenting code. For that purpose, I find tab stops of 8
(regardless of whether implemented using actual tab characters or by
inserting spaces) to be quite unusable -- a pointless waste of space at
best.

When I mostly wrote C, I'd have said it didn't matter much -- you should
rarely have code nested deeply enough for it to make much difference. In
C++, however, quite a bit of code is (for example) in a member function
in a class in a namespace, so you frequently end up with two or three
levels of indentation before you start writing code at all. Even a
perfectly reasonable level of indentation the code itself (e.g. 2 deep)
and your code is indented 40 spaces. Given that I normally prefer to
limit lines to no more than 72 characters, that leaves less than half
the line available for real use. More than once I've seen people
shortening identifiers to make things fit at that point, and IMO, that
fully merits being called "completely unusable".

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 15 '08 #22
On Jul 15, 9:50 pm, Jerry Coffin <jcof...@taeus. comwrote:
In article <e9f92aeb-08bd-44bc-aeda-
4a783c2b1...@f3 6g2000hsa.googl egroups.com>, james.ka...@gma il.com
says...
[ ... ]
Could you explain please. Starting with what use you see for
tabs.
Well, almost none, quite frankly...
They don't occur in written text, or at least, you can't
distinguish between a tab character and so many spaces.
Historically, they ended up in files as a very primitive means
of reducing file size---and 8 apparently worked well there.
Not really -- 8 was used there, but never worked worth a darn, IMO.
"worked" is relative. When your files are copies of Fortran
programs, on cards, with a serial number starting in column 72,
it could reduce the file size by half.

Of course, it's no where near as effective as gzip.
(Note that the critical position in Fortran is 72. A multiple
of 8.)
...and therefore, also a multiple of 4.
Yes, but when skipping from the end of the actual text to this
position, you only need half as many tab characters if they are
eight.
Today, frankly, I don't see much use of them in files at
all, and find the best solution is to ban them. Except that
some old programs (like make) still require them. (And I agree
that for make, 4 would be better. But 8 is still quite usable.)
To be honest, I was thinking primarily in terms of people who
still use them for indenting code. For that purpose, I find
tab stops of 8 (regardless of whether implemented using actual
tab characters or by inserting spaces) to be quite unusable --
a pointless waste of space at best.
Tabs don't work here, regardless of the tab stop. What happens
when you look at the output of diff, or grep?
When I mostly wrote C, I'd have said it didn't matter much --
you should rarely have code nested deeply enough for it to
make much difference. In C++, however, quite a bit of code is
(for example) in a member function in a class in a namespace,
so you frequently end up with two or three levels of
indentation before you start writing code at all. Even a
perfectly reasonable level of indentation the code itself
(e.g. 2 deep) and your code is indented 40 spaces. Given that
I normally prefer to limit lines to no more than 72
characters, that leaves less than half the line available for
real use. More than once I've seen people shortening
identifiers to make things fit at that point, and IMO, that
fully merits being called "completely unusable".
Which raises the question: what should you indent, when. I
don't find myself indenting more in C++ than in C. If anything,
less, because C++ seems to lend itself to better encapsulation,
and smaller, simpler functions. But then, I don't indent for
the namespaces, and I don't define member functions in the
classes.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 15 '08 #23
In article <b1cc8b8e-2bfc-4e18-b3e4-97a1e4a4e305@
2g2000hsn.googl egroups.com>, ja*********@gma il.com says...

[ ... using tabs ]
"worked" is relative. When your files are copies of Fortran
programs, on cards, with a serial number starting in column 72,
it could reduce the file size by half.

Of course, it's no where near as effective as gzip.
Even an incredibly simple RLE should work quite nicely for this...

[ ... ]
To be honest, I was thinking primarily in terms of people who
still use them for indenting code. For that purpose, I find
tab stops of 8 (regardless of whether implemented using actual
tab characters or by inserting spaces) to be quite unusable --
a pointless waste of space at best.

Tabs don't work here, regardless of the tab stop. What happens
when you look at the output of diff, or grep?
Oh, you're better off without tabs at all, no doubt about that. The
obnoxion is reduced (slightly) when they're four-stop instead of eight-
stop tabs though.

[ ... ]
Which raises the question: what should you indent, when. I
don't find myself indenting more in C++ than in C. If anything,
less, because C++ seems to lend itself to better encapsulation,
and smaller, simpler functions. But then, I don't indent for
the namespaces, and I don't define member functions in the
classes.
Hmm...I usually indent for namespaces, though I'll admit I don't feel
strongly about it. I frequently write member function definitions inside
of the class definition at first, and move them into separate files only
when/if I see a reason to do so.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 16 '08 #24
On Jul 15, 11:17 pm, "Alf P. Steinbach" <al...@start.no wrote:
* James Kanze:
On Jul 15, 7:01 pm, "Alf P. Steinbach" <al...@start.no wrote:
* James Kanze:
>Using anything other than 8 for tabstops is a dumb thing,
since that's the universal defacto standard today (and you
certainly don't look at text only in an editor).
I'm sorry, but that's not correct. The de facto Windows
standard is 4 character positions per tab stop. Tools from
early eighties (e.g. Notepad) excepted.
Windows doesn't make the standard
It is of course the common practice for Windows that sets that
Windows de-facto standard; maintaining anything else is just
silly.
it was established long before windows appeared.
Well, that olde "standard" was tab size 8 or 10 (!), for printers.
That's true. If you go back far enough, 10 was in widespread
use as well. But practically speaking, before Windows or Unix,
all I've ever seen on computers was either 8, or fully
configurable. And before computers, it didn't matter, because
of course, what you got was always spaces; tab was just a
special key, but whether you typed so many spaces, or used the
tab key, made no difference in the document.
And a quick check on my Windows machine showed it using 8 as
well (under Windows XP).
Dunno what you checked but obviously the Wrong Thing. ;-)
I created a file with a tab character in it, and viewed it (with
the "type" command---which is the most basic Windows you can
get, I think). The tab caused the text to be indented 8 spaces.

I just rechecked on my machine here: all of the programs which
are available for editing or displaying text seem to use 8:
"type" (from the command line), Notepad, Wordpad.

If there *is* a standard of 4, it seems to be limited to Visual
Studios. Although in the version which is installed here, it's
completely configurable: I can specify both the tab size and the
indent size, and specify that I want it to use spaces for
indentation. In sum, what I'd expect from any program text
editor. The default isn't really useful, but that's pretty much
the case for ever editor I've ever seen.
So I'm not sure what you're talking about when you speak of
4; until your statement above, I had assumed that it was a
personal configuration of the editor.
No, it isn't. Nearly all Microsoft code uses tab size 4. So
do nearly all Windows programmer's editors, and reportedly
that's also the case on the Mac.
All of my code uses an indentation of 4, too. But the files
don't contain a tab character.
If they did try to make it 4... Trying to change such an
established standard is almost as dumb as another systems
attempt to change the de facto standard for line endings
(which is, of course, CR,LF).
He he. Everybody knows it's just CR. Nobody'd be fool enough
to use anything but a Mac.
:-). Everyone except ASCII, of course.

Actually, there were two widespread practices before Unix:
CR,LF, and LF,CR. According to ASCII, both should give the same
results. (I've never tried LF,CR on either Unix or Windows,
though.)
Regarding what's dumb, the *nix de facto standard of 8
character positions per tab stop is clearly dumb, since it's
impractical for anything,
Historically, I don't know where the 8 comes from; it was the de
facto standard before I got into computer programming, and that
goes back some. Before Windows or Unix.
Wikipedia, which as we all know is the final arbiter of such
questions, the highest authority[1], says "it is unclear why
the 8-character horizontal size was chosen [for printers], as
5 characters, half inch in a typical printer at that time [no
reference or timeframe given], was much more popular at that
time as a paragraph indentation. It may have been chosen to
match early Fortran conventions for where the statement text
started after the line number and continuation character. Or
it may have been chosen as the smallest size that would fit
numbers typically printed in a table."
Well, I seem to remember the 10 you mentioned as the default on
typewriters, back then. And since computer scientists insist on
everything being a power of 2, 8 is the closest power of 2.
and the lack of a standard for indicating the tab stop and
indentation settings of source code is clearly dumb (would be
a good candidate for a new C++ preprocessor directive :-)).
But I'm pretty sure that folks who have not enjoyed the
benefits of working in an environment with consistent 4-tabs,
actually using tabs in source code, will not immediately grasp
why any of the abovementioned should be dumb. After all, we
manage quite fine without using tabs at all, thank you.
Yes. You shouldn't use tabs in your source code; that much is
clear.
Only for cross-platform code. For Windows programming you'd
have a very hard time if you didn't tackle tabs, since MS's
code uses them. And since you have to tackle them anyway, it
would be silly to give up the benefits (yes, there are).
Who looks at MS's code:-)? More generally, I've seen code from
many different sources, and a lot does use tabs. But not always
the same: I've seen 2, 3, 4 and 8. Worse, I've seen code where
parts were obviously written using one tab setting, and other
parts using a different tab setting; you had to change the
configuration of your editor depending on which function, or in
a couple of cases, which part of the function, you wanted to
display correctly.

Under Windows... What do the Windows equivalents of grep and
diff do with tabs, when they display?
And there's no problem with an editor doing whatever it
wants with the tab key (emacs reindents the line according to
its idea of how it should be indented). The problem is when the
editor (or any other program) inserts a tab character in the
code, or displays an existing tab character as if tab stops were
anything else but 8.
On *nix. In Windows (and presumably on the Mac) the problem is
when an editor displays existing tab characters as if tab
stops were anything else but 4. Makes havoc of the existing
code you have to relate to.
Doesn't that depend on what existing code you're talking about.
Obviously, if you've been using tab stops to indent, you don't
want to change the editor configuration until you've untabified
them. Of course, if you've done it right to begin with, this
isn't a problem.

If you're dealing with an external library which is so poorly
documented you have to look at the sources, then this depends on
the library. But what Microsoft may or may not do isn't an
issue here, since Microsoft's libraries (at least those I've
looked at) are very well documented.
>If you're using an indentation other than 8 (and 8 is too
big), then you have to use some spaces for the indentation.
(Because people are stupid enough to set tabstops in their
editor at something different than 8, I've given up using
tabs at all in text files. Just spaces, so everyone will
see the code as it was meant to be formatted.)
Using spaces instead of tabs is a good recommendation for
cross-platform work, and it is, for example, the solution
adopted by Boost.
Not just cross platform. It comes into play anytime you do a
diff or whatever Windows equivalent of grep is. (I'll admit
that I'm lazy---rather than learn the Windows tools for such
essential tasks, I just installed a Unix tool kit. Which is far
from ideal, but since I already know it, and don't work enough
under Windows to justify learning anything else...)
Not sure what the imagined problem would be.
Tools like diff and grep output lines from your code with some
additional characters in front of them. Which messes up any
indentation using tabs.
Letting the editor indent however much you want (I like four,
but three or five is also acceptable) is also a good thing; just
get everyone on the project to agree. And make sure that when
the indentation gets into the files, it's as spaces, not tab
characters, or you'll run into problems downstream.

Yes, yes, for cross-platform code, certainly.
Since there's no hope of ever convincing *nix folks to give up
the stupid 8 positions per tab stop convention, and adopt the
much more rational 4. <g>
It's not really a question of Unix. The convention was too well
established even before Unix came along for it to be possible to
change it.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 16 '08 #25
James Kanze <ja*********@gm ail.comwrites:
If they did try to make it 4... Trying to change such an
established standard is almost as dumb as another systems
attempt to change the de facto standard for line endings
(which is, of course, CR,LF).
>He he. Everybody knows it's just CR. Nobody'd be fool enough
to use anything but a Mac.

:-). Everyone except ASCII, of course.

Actually, there were two widespread practices before Unix:
CR,LF, and LF,CR. According to ASCII, both should give the same
results. (I've never tried LF,CR on either Unix or Windows,
though.)
They would give the same result on a glass tty, but not on a normal
teletype. There, if you send LF, and then CR, the first characters of
the following lines would be printed in the middle of th eline,
because CR takes more time to move the carriage from the right side to
the left side, than LF takes time to move up the paper. That's why
you should always use CR-LF, and not LF-CR, and when you're on a unix
system, convert LF to CR-LF, and when you are on a MacOS system,
convert CR to CR-LF.

>Since there's no hope of ever convincing *nix folks to give up
the stupid 8 positions per tab stop convention, and adopt the
much more rational 4. <g>

It's not really a question of Unix. The convention was too well
established even before Unix came along for it to be possible to
change it.
The best thing to do is to ban the TAB control code in your text
files. Always use spaces to indent or align columns. Any good editor
(eg. emacs) will have an option to do so.
--
__Pascal Bourguignon__
Jul 16 '08 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
5127
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is relative NOT to the immediate script that is including it, but is relative to the top-level calling script. In practice, this means that you have to constantly worry and adjust paths in includes, based on the startup scripts that call these...
2
2941
by: steve | last post by:
Hi, I need to do conditional script "include", but like to pull the code from db instead of a file. How do I do that? Reason: I like to implement some complex regex logic, and make it table driven. The regex would include if/then/else type logic, and would like my script to conditionally execute the logic. -- http://www.dbForumz.com/ This article was posted by author's request
81
7349
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
8
7599
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
8
3619
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n <br>mais pour avoir des resultats probant il faut pas faire les mariolles, comme le &quot;fondateur&quot; de bvs
2
4005
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down arrow and you see the entries in a dropdown. But how would I control this thing from javascript? Here is the HTML: <div class="selection" style="top:0; left:89; width:159; height:21;"
5
3686
by: Maria Sudderman | last post by:
I have a prblem with the "onClick" command. onClick="insert('<a href="URI">', '</a>')"> but this is not correct! why? Maria
1
2845
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. 1)<tm:bom-expression>{Conf.getEquityConfLookupFields().getEventFieldText(&quot;AdditionalDisruption&quot;,&quot;Change in Law&quot;)}</tm:bom-expression> 2)07:41:08 Default ( call ( . ( call ( . Conf getEquityConfLookupFields ) ) getEventFieldText ) ( , AdditionalDisruption Change inLaw ) ) value=Not applicable Can you please...
4
4216
by: thaytu888888 | last post by:
Here is my codes in aspx page: <td colspan="2" class="main_menu" runat="server" onclick='toggleDisplay(<%#Eval("description")%>);'><%#Eval("description")%></td> Here is in "View source": onclick="toggleDisplay(&lt;%#Eval(&quot;description&quot;)%>);">Administrator Functions</td> When putting <%#Eval('description')%> in <td> tag, it understand & show the correct value, but when in onclick='toggleDisplay(<%#Eval("description")%>);'> it didn't...
2
37796
by: jmash | last post by:
Suppose I have the following string whch is part of an xml string: String s= "Script Id=&quot;Test&quot; " And I need to get s= "Script Id="Test" " Can anyone tell me how this can acheived? Thanks, jmash
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.