Jump to content

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
https://linustechtips.com/topic/392050-whats-your-style/
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5292526
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5296837
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5302817
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5303115
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5303138
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5306025
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5312370
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5313003
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5313044
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5315154
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5315949
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
https://linustechtips.com/topic/392050-whats-your-style/#findComment-5321759
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

×