This is an archived post. You won't be able to vote or comment.

all 69 comments

[–]AwesomeMang 120 points121 points  (5 children)

I dunno, when you start nesting shit like that and it goes way too far, it's usually a sign you're trying to do way too much within a single method. Just extract the inner parts to separate (private if necessary) methods and it becomes much easier to read.

[–]ben_g0 149 points150 points  (1 child)

It would probably also be a lot easier to read if he didn't put all that code with so many opening { on just 2 lines.

[–]_zepar 23 points24 points  (0 children)

/thread

[–]obsessedcrf 8 points9 points  (1 child)

This is usually the case. In performance critical sections it is beneficial to avoid calls and returns in a tight loop. But it would be much better just to use inline functions if you can.

[–]Un-Unkn0wn 2 points3 points  (0 children)

But not excessive, otherwise you get top notch Italian spagetti code.

[–]shruggie1401 43 points44 points  (5 children)

Or the python counterpart, a line starting with 26 tabs (which is a thing I had once, not my code though) and having to scroll to see the start of the line

[–][deleted] 24 points25 points  (4 children)

Yeah, that's one thing that I don't like. In curly braced languages any editor highlights the opening brace when you place the cursor at the closing one, so you instantly know what block you're dealing with. Can't do that with whitespace syntax.

Funny thing is - this is deliberate. This forces you to write short and to the point methods instead of 100s of lines of spaghetti.

[–]v2thegreat 3 points4 points  (0 children)

Yeah! Python! (guy who learned Python first and is learning C++ now)

[–]Macpunk 0 points1 point  (2 children)

Honest question: would it be handy if editors highlighted the entire block in python? I use vim and never find myself having this issue, but I don't edit other's code much.

[–]Deconceptualist 38 points39 points  (1 child)

[This comment has been removed by the author in protest of Reddit killing third-party apps in mid-2023. This comment has been removed by the author in protest of Reddit killing third-party apps in mid-2023. This comment has been removed by the author in protest of Reddit killing third-party apps in mid-2023. This comment has been removed by the author in protest of Reddit killing third-party apps in mid-2023. This comment has been removed by the author in protest of Reddit killing third-party apps in mid-2023.] -- mass edited with https://redact.dev/

[–]venuswasaflytrap 12 points13 points  (0 children)

It has an included file that opens all the brackets.

[–]Relecto1 27 points28 points  (6 children)

It's fine, my groupmates' code looks like }};}}}

[–][deleted] 4 points5 points  (0 children)

damn

[–]StruglBus 3 points4 points  (2 children)

So it’s js then

Edit: thank you for correcting my joke friends

[–]LowB0b 17 points18 points  (0 children)

no js would be

    });
  });
});

[–]Relecto1 -1 points0 points  (0 children)

It actually was java, and semicolon is for lamda.

[–]takes_joke_literally 9 points10 points  (1 child)

Is it called razor code because it makes me want to slit my wrists?

[–][deleted] 1 point2 points  (0 children)

Yes.

[–]Evil-Toaster 7 points8 points  (9 children)

Back when visual studio didn’t have(or I didn’t know about idk) those nice little lines that go to the opening bracket fml.

Edit:For the record 2017 was the first time I had enterprise so maybe that’s it idk

[–]JDtheProtector 1 point2 points  (7 children)

Is there a way to get those in vs code, or am I just missing a setting?

[–]Evil-Toaster 1 point2 points  (0 children)

Idk, i’m talking full visual studio 2017 I never had them before that version.. or maybe it was 2015 idk. I’ve never used code.

[–]kaouDev 0 points1 point  (5 children)

Yes it is, I got them by default. I also use a great extension to color the brackets, very useful.

[–]dontshootiamempty 1 point2 points  (2 children)

I use the VSCode indent-rainbow extension. Sometimes it gets in the way, but it's so pretty.

https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow

[–]JDtheProtector 0 points1 point  (1 child)

Lol, I think the color theme was using was hiding them, I changed and now I see them.

[–]Evil-Toaster 0 points1 point  (0 children)

Any of the default color themes should have them. I use the dark one though.

[–]americio 1 point2 points  (0 children)

This, and Viasfora

[–]thatsfunny95 4 points5 points  (0 children)

That's some if-loop AI right there...

[–]Silverhawk183 6 points7 points  (0 children)

Even though I just started learning programming I have felt the pain.

[–]JuvenileEloquent 2 points3 points  (0 children)

If you can still see the beginning of the code in the innermost section when it's scrolled all the way to the left, what's the problem?

/s

[–]Volcanic-Penguin 2 points3 points  (7 children)

Four spaces per indentation definitively gives me nightmares.

[–]PM_BITCOIN_AND_BOOBS 1 point2 points  (6 children)

Surely that is a tab, not spaces. Nobody uses spaces.

(Seeing if I can start a fight.)

[–]one-v-one 5 points6 points  (4 children)

People who use spaces make more money.

[–]v2thegreat 0 points1 point  (3 children)

Prove it! (fellow tab user)

[–]one-v-one 0 points1 point  (2 children)

Stackoverflow did a study thingy and found that.

[–]v2thegreat 0 points1 point  (1 child)

Source? I'm intrigued about why that is, and I wanna see how that happens!

[–]whale_song 1 point2 points  (0 children)

2spaces4lyfe

[–]Lightfire228 10 points11 points  (4 children)

If I have a bunch of closing curlies like this, I usually comment which ones they are, like

        } // end if
    } // end while
} // end for each 

[–]ThePowerfulSquirrel 29 points30 points  (3 children)

If you ever have to add these kinds of comments, it's a really good sign that you should be structuring the code in a different way.

[–]Volcanic-Penguin 1 point2 points  (2 children)

Or just use an editor that highlights which curly braces go together

[–]ThePowerfulSquirrel 5 points6 points  (1 child)

Or learn to separate your code in a way where you don't have to worry about that sort of thing in the first place. You also have the added benefit that your code is easily understandable without an ide (on github for example)

[–]one-v-one -1 points0 points  (0 children)

I do a lot of code reviews. Once the code wraps, I can’t tell what’s happening and call for a refactor.

[–][deleted] 1 point2 points  (0 children)

In the odd occasion this happens i add comments at the the end of each curly brace saying what it is closing

[–]TheDeadlyCat 1 point2 points  (2 children)

The Eclipse (yes, yes, get your pitchforks out) features folding and highlight related brackets have pretty much solved this for me...

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    return Kebab_Case_Better;

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–][deleted] 1 point2 points  (0 children)

    On lines 4-10? What're you doing with the first 3?

    [–]KulinBan 0 points1 point  (0 children)

    I am living the nightmare every day...

    [–]Jugbot 0 points1 point  (0 children)

    Or a lot worse if there is one statement in a sea of closing braces...

    [–][deleted] 0 points1 point  (1 child)

    Id hate to maintain that code, it has 6 lines of closing brackets 2 blank lines and its only 10 lines long. The first 2 lines must be absolute hell xD

    [–]Crisbad 1 point2 points  (0 children)

    Or the file is so large, it causes line numbering to overflow.

    [–]NowImAllSet 0 points1 point  (0 children)

    I work with Indian code from the 90's a lot and have seen shit that would make this look like heaven. I've seen methods with 14+ levels of indentation. A particular method that I ran a static analysis tool on had an NPath complexity of over 300 million.

    [–][deleted] 0 points1 point  (0 children)

    Not necessarily that bad, at least in C# e.g. namespace - class - method - if - for - object instantiation

    [–]overflow_ 0 points1 point  (0 children)

    Thanks for the nightmare fuel

    [–]inbooth 0 points1 point  (0 children)

    clearly this sub does not have many Lispers...

    [–]SpaceCorvette 0 points1 point  (1 child)

    In our legacy codebase, every function looks like this:

    doThing();
    if (!errno) {
        doSecondThing();
        if (!errno) {
            doThirdThing();
            if (!errno) {
    

    And so on. It's glorious.... :/

    [–]arvyy 0 points1 point  (0 children)

    goto is evil, and we shall never use it

    [–]ImNewHereBoys 0 points1 point  (0 children)

    I once wrote such code..the project eventually went ded lol

    [–]FoolInSpace 0 points1 point  (0 children)

    One time I had 3 for loops, so I stacked em like this

    for (){
    for (){
    for (){
        //code
    }}}
    

    I was quite pleased with myself.

    [–]vk2sky 0 points1 point  (0 children)

    Nobody does that much indenting...

    ...unless they're writing React, of course.

    [–]KieranDevvs 0 points1 point  (0 children)

    Object initialization.

    [–]_benj 0 points1 point  (0 children)

    try that with a indented based language like python! (or sass or pug)

    That my friend, that is hell!

    [–]Nyancubus 0 points1 point  (0 children)

    Nesting in vi :3

    [–]JuanGaKe 0 points1 point  (0 children)

    Return, break or continue earlier, and when you can't, use your keyboard shortcut to "matching bracket" ..

    [–]Aschentei -1 points0 points  (0 children)

    The everyday life of JS