Format problem

Started by
5 comments, last by Oluseyi 18 years, 8 months ago
a lot of source code file look good at vc,but bad in notepad ,write,or other text editor. How could I fix it? Do you often face these problem?
Advertisement
What do you mean it looks bad?

Is it that tabs are too wide? VC allows you to set tabspace (default 4), while the windows default is 8, I think. Depending on which version of VC you are running, you can convert tabs to spaces in the Edit->Advanced menu.

Or is there a rectangle character instead of a newline? This would be due to the text format. That is, Windows uses CRLF for newlines, while Linux uses LF only and I believe older macs use CR. You can set the output format in File->Advanced Save Options if you are running VC++.NET.


jfl.
// in vc look goodint   i;char  c;type  d;//in other editorint  i;char        c;type    d;


I mean this;
That's just the tab spacing. I usually go through my code and eliminate all spaces (like in the 2nd example, some are shorter some are longer), and replace them with tabs.

Like jflanglois said, other editors use a different number of spaces for tabs. I would get in the habbit of either always hitting TAB after the type, or just hit space after the type.

You will notice the same thing if you post some code in a message here, if it has spaces and tabs mixed to create formatting that looks correct in the VS editor.
The problem is the width of the tabs that the program uses. Some (like notepad) use 8 character wide tab spaces (or something like this), while others use less. For instance, I've set Dev-C++ up to use tab spaces that are 2 characters wide. One solution would be to use spaces instead, since there's a very good chance that the width of a space will always be one.
Umm... no, I think the problem here is the fonts being used :)

Serious programmers use a "monospace" font (such as Courier, Monaco, Fixedsys...), where every letter is the same width; that keeps things lined up. Many editing programs will use a "proportional" font by default (such as Arial, Times New Roman...) because they "look better", which is true if you are writing a letter, but horrible for code.
Quote:Original post by Zahlman
Serious programmers use a "monospace" font (such as Courier, Monaco, Fixedsys...), where every letter is the same width; that keeps things lined up.
I just wanted to add that monospace fonts also represent the space character as the same width as every letter, which is critical. Proportional fonts tend to have a very narrow space delineation, which can be up to one-fourth the width of a letter like 'w'! And that's not to mention the havoc that hinting and kerning can cause.

If you're looking at code, always use a monospace font.

This topic is closed to new replies.

Advertisement