Raised This Month: $51 Target: $400
 12% 

Indentation Convention [A notepad++ tutorial]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 11-03-2012 , 11:37   Indentation Convention [A notepad++ tutorial]
Reply With Quote #1

Here the basic thing that must be done to your notepad++ before coding anything in any programing language.

PHP Code:
Step 1:
Go in the 'settings' tab and click 'preferences..'.
Go in 'Language Menu/Tab Settings'.
Make sure 'Tab size' is at 4 and 'replace by space' is checked.

PSSometime this setting reset when you open notepad++, make sure to  check this option every time you start coding on notepad++.

Step 2:
Go in 'Search' tab and press 'Find' alias CTRL F.
Go in the 'Replace' tab.
In 'Search Mode' be sure that 'Extended' is select.
In 'Find what' put the value '\t'
In 'Replace with' put '    ' (four space)
Press 'Replace' button.


Now your script using four space every where and when you press TAB it  put four space instead of a TAB which fix the indentation and 
use 
the correct Convention for sharing codes and not being lost in your  projectsSo basicly it easier to copy past a part of a code if 
someone share you his code if (of courseusing the right convention  (which is supose to be like that on every part of code on this forum).

Compile n enjoy
Now your ready to code like a 'Baws' and listen to this sound on yourepeat while coding: Like a baws.


EDIT:
Before flaming this post just read this reply Thank you <3.

Last edited by Mathias.; 11-04-2012 at 14:02.
Mathias. is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-03-2012 , 14:43   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #2

using spaces is messy..
i would keep the tabs.
Mitchell is offline
Zephyrus
Cool Pig B)
Join Date: Jun 2010
Location: Hungary
Old 11-03-2012 , 19:55   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #3

tabs
__________________
Taking private C++/PHP/SourcePawn requests, PM me.
Zephyrus is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 11-03-2012 , 22:48   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #4

Just telling it the convention...

/* source http://root.cern.ch/drupal/content/c-coding-conventions */

Preferred Coding Style

Here we describe our preferred coding style. Coding style is very personal and we don't want to force our views on anybody. But for any contributions to the ROOT system that we have to maintain we would like you to follow our coding style.

Indentation

To be able to keep as much code as possible in the visible part of the editor of to avoid over abundant line wrapping we use indentation of 4 spaces. No tabs since they give the code always a different look depending on the tab settings of the original coder. If everything looks nicely lined up with a tab setting of 3 spaces, it does not look so nicely anymore when the tab setting is changed to 3, 5, etc. spaces.


/* source http://root.cern.ch/drupal/content/c-coding-conventions */

Sure it cool to have our style and everything, but when it comme to share with the community you should follow certains convention. If everyone using a different style and you try to help someone out it get a realy pain for the one who ask for help.

PS: I know they say 3 but it normaly 4. That was the first article I found on google so yea.


EDIT:

Here an other source:

/* source http://www.riedquat.de/prog/style */

The K&R style rules are:
  • Indent 4 spaces.
  • Braces are not indented.
  • Put the opening brace of a function body in the next line below the function prototype.
  • Put all other opening braces on the same line as the syntax element to which the brace is subordinate.
  • Do not indent case or default inside switch.
/* source http://www.riedquat.de/prog/style */

Oh and also, The indentation convention is for almost all languages.
I don't remember but I think in visual studio when you use TAB it automaticly put 4 space by default settings.

Don't hate me (spread the love: Motherlover)

Last edited by Mathias.; 11-03-2012 at 22:56.
Mathias. is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 11-03-2012 , 23:31   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #5

Notepad++ can already convert all spaces to tabs and vice verses, no need to use Find&Replace. Edit->Blank Operations
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 11-04-2012 , 00:25   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #6

Quote:
Originally Posted by Mitchell View Post
using spaces is messy..
i would keep the tabs.
Tabs are EVIL and should never be used! ALWAYS replace tabs with spaces.

If you don't believe me, I can show you a *lot* of examples of what happens to files with tabs in them that have been maintained by several people over 10-20 years, each using different editors with different tab settings -- the indentation becomes random, leaving the programs mostly unreadable!

Last edited by naris; 11-04-2012 at 00:25.
naris is offline
psychonic

BAFFLED
Join Date: May 2008
Old 11-04-2012 , 00:32   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #7

Quote:
Originally Posted by naris View Post
Tabs are EVIL and should never be used! ALWAYS replace tabs with spaces.
Please god no.

Tab supremacy.

Last edited by psychonic; 11-04-2012 at 00:33.
psychonic is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 11-04-2012 , 00:34   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #8

Quote:
Originally Posted by Black-Rabbit View Post
The K&R style rules are:
  • Put the opening brace of a function body in the next line below the function prototype.
  • Put all other opening braces on the same line as the syntax element to which the brace is subordinate.
/* source http://www.riedquat.de/prog/style */
The K&R braces style is a horrid practice and should never be followed. Braces should ALWAYS be placed on a separate line:
Code:
if (something)
{
    do_something();
}
Using proper indentation and brace placement makes the code cleaner, easier to understand and easier to maintain. It is especially helpful when the braces are placed in the same column, making it easier to find missing or mismatched braces, especially if the code inside the braces is more than a couple of lines.
naris is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 11-04-2012 , 00:41   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #9

Quote:
Originally Posted by psychonic View Post
Please god no.
Tab supremacy.
Please god no indeed -- Tabs should never be allowed in source files ever.

A space is a space -- it is always 1 space. No matter what editor or what settings are used. Tabs are sometimes 3 spaces, sometime 4 spaces often 8 spaces or whatever random number of spaces or column positions the particular editor is configured for (if it is configurable).

Using tabs ultimately leads to code that looks like this:
Code:
if (something)
                                      something();
                         for (int i=1;i<10;i++)
{
                                                  if (xxx){
           perform_somethinh)'
                                     if (yet_another_condition)
                break;
}
        perform_something_else();
}
}
of the several million lines of the code I have been maintaining in production for over 12 years, quite a bit of it looks like that due to the use of tabs.

Last edited by naris; 11-04-2012 at 00:42.
naris is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-04-2012 , 00:52   Re: Indentation Convention [A notepad++ tutorial]
Reply With Quote #10

Quote:
Originally Posted by Black-Rabbit View Post
Just telling it the convention...
No you are not. You are repeating the convention ONLY for http://root.cern.ch/ and does not apply elsewhere.

Quote:
Originally Posted by Black-Rabbit View Post
No tabs since they give the code always a different look depending on the tab settings of the original coder. If everything looks nicely lined up with a tab setting of 3 spaces, it does not look so nicely anymore when the tab setting is changed to 3, 5, etc. spaces.
That is actually the best thing about tabs when sharing code.

Quote:
Originally Posted by Black-Rabbit View Post
Sure it cool to have our style and everything, but when it comme to share with the community you should follow certains convention.
Regarding the question "tabs or spaces" in this community the convention is to "use one or the other."


Quote:
Originally Posted by Black-Rabbit View Post
If everyone using a different style and you try to help someone out it get a realy pain for the one who ask for help.
If the code is indented properly it does not matter if you use tabs or spaces as long as it is only one or the other as I previously stated. If you have problems handling code with this community's convention then you need to learn about the other functions of Notepad++.

Quote:
Originally Posted by Black-Rabbit View Post
PS: I know they say 3 but it normaly 4. That was the first article I found on google so yea.
This makes me want to not believe anything you say. Do you believe every article that you first encounter?

Quote:
Originally Posted by Black-Rabbit View Post
EDIT:

Here an other source:

/* source http://www.riedquat.de/prog/style */

The K&R style rules are:
  • Indent 4 spaces.
  • Braces are not indented.
  • Put the opening brace of a function body in the next line below the function prototype.
  • Put all other opening braces on the same line as the syntax element to which the brace is subordinate.
  • Do not indent case or default inside switch.
/* source http://www.riedquat.de/prog/style */
Where in your sources does it say that those conventions apply to the AlliedModders Community?

Quote:
Originally Posted by Black-Rabbit View Post
Oh and also, The indentation convention is for almost all languages.
That is an opinion.

Quote:
Originally Posted by Black-Rabbit View Post
I don't remember but I think in visual studio when you use TAB it automaticly put 4 space by default settings.
That is the thing I hate most about Visual Studio (and other derivatives). Just because Microsoft enforces it does not mean it is THE only way to do it else you be shunned.


Offtopic, What in the world is a "Baws"??????


Quote:
Originally Posted by naris View Post
A space is a space -- it is always 1 space. No matter what editor or what settings are used. Tabs are sometimes 3 spaces, sometime 4 spaces often 8 spaces or whatever random number of spaces or column positions the particular editor is configured for (if it is configurable).
Which as I stated above is the best thing about tabs. Everybody can configure their editor to view them how they want them and not have to conform to others (which will likely make you less efficient when dealing with other's code)

Quote:
Originally Posted by naris View Post
Using tabs ultimately leads to code that looks like this:
Code:
if (something)
                                      something();
                         for (int i=1;i<10;i++)
{
                                                  if (xxx){
           perform_somethinh)'
                                     if (yet_another_condition)
                break;
}
        perform_something_else();
}
}
Who ever writes code such that that would happen doesn't know how to intelligently write code. If the code is written with one or the other, it will never look like that.

Quote:
Originally Posted by naris View Post
of the several million lines of the code I have been maintaining in production for over 12 years, quite a bit of it looks like that due to the use of tabs.
You mean, "tabs and spaces," right?

Quote:
Originally Posted by naris View Post
If you don't believe me, I can show you a *lot* of examples of what happens to files with tabs in them that have been maintained by several people over 10-20 years, each using different editors with different tab settings -- the indentation becomes random, leaving the programs mostly unreadable!
Tab settings do not change the source code and therefore CANNOT affect how subsequent people see the code. I would love to see these examples you claim to have. I bet you that they have tabs and spaces.
__________________

Last edited by fysiks; 11-04-2012 at 01:14.
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode