Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

What Programming-Style Do You Guys Follow?

What programming-style do you follow?

  • K&R

    Votes: 0 0.0%
  • Allman/Allman-8

    Votes: 0 0.0%
  • GNU

    Votes: 0 0.0%
  • Horstmann

    Votes: 0 0.0%
  • Pico

    Votes: 0 0.0%
  • Stroustrup

    Votes: 0 0.0%
  • 1 True-Brace-Style(1TBS)

    Votes: 0 0.0%

  • Total voters
    1
  • Poll closed .

Mathematical

Silver Coder
Hey there.

So, we all know the debate about programming-styles in the world of programming and CS. Tabs vs spaces, braces on a new line or on the same line of a function/class, you get the idea. So, I figured, why not ask the CF community on what style they follow.

There are many well known styles in programming. Those being: K&R(Named after Brian W. Kernighan and Dennis Ritchie, creator of C, and both authors of The C Programming-Language, practically the Bible for all C programmers) and Allman Style(Named after Eric Allman, a programmer who wrote many utilities for *BSD). Of course, there are other styles such as GNU style(Named after the GNU Project, which was founded by free-software activist, Richard Stallman), and Horstmann Style(Named after Cay S. Horstmann, who has written and still continues to write many programming books).

But those are just the "indentation-styles". So, how you layout your braces, and how many spaces you insert, and whether you use tabs or spaces. I'd also like to know how you guys name and declare your variables, if you aim to make your code more compact or space it out several lines, and also how frequently you comment your code.

There is a poll in this thread that you can choose to vote on which style you use.

I myself personally, follow my own style. Here's my specifications:
  • 5-Spaces
  • 100-Columns maximum
  • Function/Class/Method braces on the same line they're declared; conditional-statements, arrays, loops, and structure braces go on their own line.
  • Do not insert braces inside single-line bodies of loops and conditional-statements.
  • Do not group operators and variable names together(E.g. Instead of Var1==Var2 or Num1+=Num2, I write Num1 += Num2 and Var1 == Var2).
  • All variable names are written in CamelCase(E.g. Instead of int big_number, I write int Big_Number).
  • I frequently comment my code(I don't only use multi-line comments all the time. C'mon folks, single-line comments have hears too!)

Those right there, are my specifications for my own, preferred style of writing my code in. Feel free to punch it, kick it, or do whatever to it. Hell, even feel free to test it out for yourself to see if it's a style you like.
 
For reference: https://en.wikipedia.org/wiki/Indentation_style .
For work, I've mainly been working in Java, which had defined a suggested coding style: https://www.oracle.com/technetwork/java/codeconventions-150003.pdf . Of note in most commercial applications I've worked on: curly braces always follow on the next line, and even single line statements are curly braced:

Code:
if (doSomethingCool)
{
    makeItSo();
}
else
{
    engageWarpFactorFive();
}

Spaces over tabs, usually an indent of 4.

Composite booleans can be split over multiple lines in an if/while:

Code:
if (oneThing || anotherThing ||
      thingTwo ||
      thingThree)
{
    fireOnTheKlingons();
}

In Java, camelCase on functions and variables, CamelCase on class names, UPPER_CASE on constant declarations. in C# and C, I've seen CamelCase for functions.

So far in Java I've been relying on the IDE (IntelliJ) to make sure the coding style is followed. C# is typically tied to .NET and Visual Studio, so I go with whatever Microsoft recommends. When doing non-IDE mandated formatting, I usually follow the "opening curly brace on a new line" thingy.

Last time I tried to do C and C++, I tried doing function comment blocks like Java's javadocs. I've always wanted to try doxygen.
 
Last edited:
I've got my own too, I like to put explanations at the end though for example

PHP:
<?PHP
$a = 1;
$b = 1;

    if($a == $b){
        
        echo "Im too awsome";
        
    }else{
        
        echo "Too Sad";
        
    }// End of a = b
    
?>

it just helps to make it neat, i always like to keep spaces between lines too
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom