GENERAL: Programming Code Guidelines & Styles [closed]

I know that each programming language has certain guideline and styles. My question is about two languages that I write code in, that isn’t very popular or documented.

I know this topic is very broad, and everyone has their own unique way of doing things. What I would like is to hear advantage, disadvantages to certain styles.

In order to explore this question, imagine you are writing your own programming language, based on what you’ve experienced in the past, what is the best way of going about things?

Remember, there may be ups and downs based on specific languages, so think if this language didn’t matter. I am still fresh to programming, so I want to get the best habits of making my code readable and easy to follow.

There are so many topics to talk about, Ill get run by the basics:

Global Variables
Should they start with _ and be all capitalized?

Local Variables
Should they end with _ and be always be lowercased?

Variable Names
If I am defining something like an employee’s hourly wage, should it be EmployeeHourlyWage, Employee_Hourly_Wage?

Variable Types
Should you include the type of variable it is in the name, for example if I define $Hours and it has stored to it an integer, should I name it $Hour_INT so that I know when referring to it what type it is? Who knows, I might have an $Hours_FLOAT

Curly Brackets
Should the brackets line up with themselves such, the words, or what? Which one of these are best, preferred, most readable?

IF ($Test) {
 //code
} ELSE {
 //code
}

IF ($Test)
{
 //code
} ELSE {
 //code
}

IF ($Test)
{
 //code
}
ELSE
{
 //code
}

Alignment
I am constantly lining up variables and their values so I have an idea where what goes where. Is this bad practice:

// Assuming GUI(TOP, LEFT, HEIGHT, WIDTH)

GUI( 23    , 44   , 245   , 2323    )
GUI( 232   , 4332 , 22    , 6576    )
GUI( 21    , 4    , 1     , 5       )
GUI( 34235 , 13   , 31237 , 4564665 )

// OR

GUI(23,44,245,2323)
GUI(232,4332,22,6576)
GUI(21,4,1,5)
GUI(34235,13,31237,4564665)

Indenting
Why do some coders use spaces instead of tabs? is there a amount of spaces that is recommended?


I understand all of these could be questions in their own. I am not sure where to get all this knowledge from? I could spend hours just asking you what is the best method. I am sure the more college courses I take, the more it will be hit on (or not).

It would be awesome if there was a site where programmers of all kinds talk/discuss/rate/wiki the best methods and practices of programming. Would also help serve future languages to better suit the needs. I guess if there was one right way, there wouldn’t be so many variations in languages and style. I just would like to know your arguments and whats mainstream so my coworkers know what I am coding.

Answer

These are all really subjective issues – people mostly disagree about these sorts of things, and to be honest it really doesn’t matter that much! 🙂

I’d say that the only thing that you can actually do wrong is to be inconsistent about whatever pattern you do use.

Leave a Reply

Your email address will not be published. Required fields are marked *