Jump to content

What's your style

maxib7

So we all have a personal style guide we adhere to and I was wondering what's your preference concerning brackets?

 

Here's the way I do it

int main (void){    printf("hello, world!\n");    if (/*condition*/)    {        // stuff here    }     else     {        // stuff here    }    return 0;}

However I have seen people do it like this and it drives me crazy when I see it. It's so less legible

int main (void){    printf("hello, world!\n");    if (/*condition*/){         // stuff here    } else {        // stuff here    }        return 0;}

No... I'm not ready for my thread to die, not yet.... nooooo......

Link to comment
Share on other sites

Link to post
Share on other sites

Snip

I do it the same way you do but I used to do it the other way. I only swapped because some of my functions had like 10+ parameters and moving the brackets down a line helped readability.

Link to comment
Share on other sites

Link to post
Share on other sites

First one for me, well that's how I would type it because I like the organization

~Man is least himself when he talks in his own person. Give him a mask, and he will tell you the truth - Oscar Wilde~

Link to comment
Share on other sites

Link to post
Share on other sites

Yeah I hate trying to read other people's code when the brackets are like that. It feels a lot harder to read

No... I'm not ready for my thread to die, not yet.... nooooo......

Link to comment
Share on other sites

Link to post
Share on other sites

I make sure that my code is as illegible as possible since anyone looking at my code probably can't understand the genius anyway.

Link to comment
Share on other sites

Link to post
Share on other sites

I make sure that my code is as illegible as possible since anyone looking at my code probably can't understand the genius anyway.

i like to think that you secretly use PHP for all of your applications, and this comment of yours just made my hypothesis even more realistic

Link to comment
Share on other sites

Link to post
Share on other sites

i like to think that you secretly use PHP for all of your applications, and this comment of yours just made my hypothesis even more realistic

 

I program mostly in PHP for my job, so in a way you're right.

Link to comment
Share on other sites

Link to post
Share on other sites

I program mostly in PHP for my job, so in a way you're right.

 

True geniuses only use Lisp 

No... I'm not ready for my thread to die, not yet.... nooooo......

Link to comment
Share on other sites

Link to post
Share on other sites

The first one. However if there's only 1 line of code to run I sometimes do it like this

if(condition) { /*one line of code*/ }else{//more code}

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
Share on other sites

Link to post
Share on other sites

first in c#

second in jquery

Desktop:

CPU : i5 4440 | Motherboard : Gigabyte B85M-D3H | RAM : Kingstone HyperX blu 4GB x2 | GPU : Asus R9 280X DC II Top [RIP 2017] | PSU : Corsair VS 550W | Display(s) : Dell S2240L | Mouse : Logitech G400s | Operating System : Windows 7 64bit

 

Laptop:

Acer Predator Helios 300 (CPU: Intel Core i5 7300HQ | GPU: GTX 1050ti | RAM: 16GB RAM | Operating System: Windows 10 64bit)

Link to comment
Share on other sites

Link to post
Share on other sites

int main (void){    printf("hello, world!\n");    if (/*condition*/)    {        // stuff here    }    if (/*condition*/)    {        // stuff here    }    else     {        // stuff here    }    return 0;}

int main (void){    printf("hello, world!\n");    if (/*condition*/){         // stuff here    }    if (/*condition*/){         // stuff here    } else {        // stuff here    }        return 0;}

2nd (you might see why)

Mini-Desktop: NCASE M1 Build Log
Mini-Server: M350 Build Log

Link to comment
Share on other sites

Link to post
Share on other sites

i usually let visual studio format my c# code but i do tend to shorten if clauses if possible

string test = condition?"iftrue":"iffalse";

"You know it'll clock down as soon as it hits 40°C, right?" - "Yeah ... but it doesnt hit 40°C ... ever  😄"

 

GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled) CPU: Ryzen 5600X (watercooled) RAM: 32GB 3600Mhz Corsair LPX MB: Gigabyte B550i PSU: Corsair SF750 Case: Hyte Revolt 3

 

Link to comment
Share on other sites

Link to post
Share on other sites

First one :)

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

I've used both in the past but I think I mostly use the brackets in their own line.

I cannot be held responsible for any bad advice given.

I've no idea why the world is afraid of 3D-printed guns when clearly 3D-printed crossbows would be more practical for now.

My rig: The StealthRay. Plans for a newer, better version of its mufflers are already being made.

Link to comment
Share on other sites

Link to post
Share on other sites

Every time I have to deal with code that has not been written utilizing Allman style I die a little inside.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

I use bracket styling to separate code by type.

int main(){ //brackets on next line here, shows a function definition, class, namespace etc.  if(/*condition*/){ //but inside a function I condense the code to conserve space.    //stuff here  }  return 0;}

Every time I have to deal with code that has not been written utilizing Allman style I die a little inside.

I don't understand people that follow that sort of stuff. Brackets can easily add 15-20 pointless lines in a complex state-dependent algorithm, stretching it way over single screen height. Same goes for elitists sticking to C stuff like [] arrays in C++11 era.

Link to comment
Share on other sites

Link to post
Share on other sites

...

I don't understand people that follow that sort of stuff. Brackets can easily add 15-20 pointless lines in a complex state-dependent algorithm, stretching it way over single screen height. Same goes for elitists sticking to C stuff like [] arrays in C++11 era.

 

And I don't understand people who pile stuff into the smallest possible space at the cost of readability to 'save 15-20 pointless lines' in their opinion.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

/*funciton name *short description or pseudocode *argument 1 - description *argument 2 - description **/int functionname(/*arguments*/){    /*variable declarations and initialization*/    /*descriptions*/    /*code*/    /*more descriptions*/    /*more code*/    subfunction(/*arguments*/){        /*varable declarations and initailization*/                /*descriptions*/        /*code*/        /*more descriptions*/        /*more code*/    }}

I eat up a lot of space with documentation stuff... which I mostly remove once debugging is done...

Link to comment
Share on other sites

Link to post
Share on other sites

I eat up a lot of space with documentation stuff... which I mostly remove once debugging is done...

 

In an ideal world there should be very little need for documentation/comments in the code at all.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

And I don't understand people who pile stuff into the smallest possible space at the cost of readability to 'save 15-20 pointless lines' in their opinion.

but 1TBS is better readable ?! (especially considering if/else blocks)

Mini-Desktop: NCASE M1 Build Log
Mini-Server: M350 Build Log

Link to comment
Share on other sites

Link to post
Share on other sites

And I don't understand people who pile stuff into the smallest possible space at the cost of readability to 'save 15-20 pointless lines' in their opinion.

If you use spacing/tabbing properly, it makes the shorter versions just as readable as the long one, and if I have to choose between 1 screen height worth of space or 1.5 I'll choose the 1st one, because that can directly impact readability. With constant scrolling to find reference to a variable or name it's much harder to follow the flow.

As I said before, heavily nested state-based functions end up looking like bracketfest, sitting there meaninglessly.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×