Where a curly bracket belongs

preview_player
Показать описание
Like and subscribe!

It might seem like a simple question, but curly bracket placement plays a huge role in structuring your code in an effective way. In this video we explore all available options, and explain why there is one true place to put that curly bracket.

#programming #idea #style #code
Рекомендации по теме
Комментарии
Автор

You
make
a
strong
argument
about
arguments

HansLemurson
Автор

I always thought this way, but this was a really nice way to describe it. I will absolutely share this with anyone I come across that needs convincing otherwise.

novocaine
Автор

My new favorite channel. This format is 👌

MarkShust
Автор

I can't agree more. Working on a legacy-project, I realized this kind of placing brackets and arguments are the most efficient one for reading code.
Also, nice channel idea! Compact and enough details.

leonhardradonic
Автор

I like the format of this channel. This may also be a good format for YouTube Shorts, at least if they stay _short_ (like the first two).

stephfh
Автор

Love the new channel idea! Like usual, you explain the concept very well, thanks for the videos. This will give me some fuel to perhaps convince my colleagues in the future :)

ardentsword
Автор

I keep them on the same line for if and loops, new line for (I think) everything else.

marcusgaius
Автор

I love the video "style" but as some have pointed out, this particular example might be too specific to claim "curly belongs on newline", while also not even achieving what is being described.
To me that's just putting the closing bracket for the argument list on a newline instead of using something more akin to the allman indentation style.

daephx
Автор

... what? For me this is not "placing the brace on a new line", this is "placing the closing bracket(s) on a new line". Which is what I also do, but only when there is a long list of arguments. When you just have a short if statement or for loop, would you also put the closing bracket on a new line?

KommissarBoelles
Автор

I will never understand how the same people voted for opening brace to be on the new line in some cases and on the same one in others in PSR... just make it consistent already!

ZKIUS
Автор

I’m not arguing one way or another, but you _literally_ just replaced a block of red keywords followed by a block of blue keywords (having each line starting with $) with XXX and pretended that it is the same. It’s not. The arguments block was clearly distinguishable, even on a monochromatic vt100 terminal

casualpuck
Автор

Or you could use different indentation:

function foo(
str arg1,
str arg2,
str arg3,
str arg4,
str arg5) {
print(arg1 + arg2);
print(arg5);
return arg3 + arg4;
}

sayven
Автор

If you need to scroll you already fd up.
Stack
Them
Args.
(The brace is never new line)

Oi-mjdv
Автор

First of all, I don't like curly braces. I like Pascals "BEGIN" and "END" keywords much better. I used them for years in C (using conditional compilation) and only abandoned them when I started publishing code. But the result was that those keywords were replaced with curly braces at the beginning of the line.

I don't make prototypes like this. I often produce TWO prototypes, one for K&R and one for ANSI. So there's never any doubt where the body of the function begins. It's a wordy way to lay out code, but added with the comments (I like lots of functional comments, so my intentions are crystal clear) it comprises a body of code that can be maintained 30 years after it was created. And yes, I hate "code speaks for itself" - unless you're making incredibly boring corporate code, techy algorithms are never obvious.

HansBezemer
Автор

This is a bit of a straw man argument. The argument you use here involves a parameter list that is so long that it is preferable to separate them into multiple lines. In this case, I'm with you 100%.

However, when that is not the case, when there are no or only a few short parameters, the argument you use no longer flies.


function foo($bar) {
}

Is not inherently better than

function foo($bar)
{
}

Between those two, it is a matter of preference. When multi-lining I've never even considered using a different formatting than this:

function (
$bar,
$baz,
$qux
) {
}

pindabter
Автор

so whats the story with the { on its own line? ie:


if (something)
{
blah
}

thats always looked wtf to me.

XXXX

)
{

}

williamstam
Автор

New follower... I was expecting you to open a new channel... that's cool

mikeeomega
Автор

public function foo(
){
echo "bar";
}

rouvepofadder