Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Lisp Style" indentation on curly brace languages [closed]

I'd like to know what the people think about using a Lisp indentation style for languages like C++, Java, JavaScript, etc. I've always been a fan of Python and how it's formatted without braces. It's very compact and clean to me. I was wondering whether or not it would be a good idea to do something similar in a curly brace language. I've been doing work in JavaScript lately so I'm going to use JavaScript as an example.

Normally, I use something like this, e.g.

function doStuff (stuff1, stuff2) {
    if (stuff1 === stuff2) {
        doMoreStuff();
        doEvenMoreStuff();
    }
    else {
        takeABreak();
    }
}

This would then become

function doStuff (stuff1, stuff2) {
    if (stuff1 === stuff2) {
        doMoreStuff();
        doEvenMoreStuff(); }
    else {
        takeABreak(); } }

Which is compact, and focuses more in the indents rather than the braces like Python. Lisp wasn't known for being a particularly pretty language, but I kind of like this, and don't think it looks too terrible, albeit things can get a bit hairy when you have a lot of nested blocks ending at the same time. I'd like a second opinion though. Maybe I just shouldn't try to code Python in JavaScript?

like image 590
SpaceFace Avatar asked Oct 06 '22 13:10

SpaceFace


1 Answers

I've certainly seen code like this in the past. There's nothing wrong with it, just as long as you and any colleagues find it legible.

If you're working on an existing product or with an established team, then it's always best to keep your code consistent with what you see around you until (unless) everybody agrees to switch style. If the code and the team are both new (or the code is new and the team is just you) then feel free to do whatever feels natural. Experimentation is what drives us forward.

like image 93
Eric Avatar answered Oct 10 '22 10:10

Eric