this post was submitted on 10 Feb 2024
204 points (100.0% liked)

196

18191 readers
587 users here now

Be sure to follow the rule before you head out.


Rule: You must post before you leave.



Other rules

Behavior rules:

Posting rules:

NSFW: NSFW content is permitted but it must be tagged and have content warnings. Anything that doesn't adhere to this will be removed. Content warnings should be added like: [penis], [explicit description of sex]. Non-sexualized breasts of any gender are not considered inappropriate and therefore do not need to be blurred/tagged.

If you have any questions, feel free to contact us on our matrix channel or email.

Other 196's:

founded 2 years ago
MODERATORS
204
Antimemes rule (lemmy.dbzer0.com)
submitted 2 years ago* (last edited 2 years ago) by moosetwin@lemmy.dbzer0.com to c/196@lemmy.blahaj.zone
 
all 33 comments
sorted by: hot top controversial new old
[–] 9point6@lemmy.world 63 points 2 years ago (4 children)

Anything but K&R is psychopathic, fight me

[–] bort@feddit.de 28 points 2 years ago* (last edited 2 years ago) (2 children)

Allman if the condition is very long

while(isSomething
    && isSomethingElse
    && nFoo < 10)
{
    bla();
    bla();
}

vs

while(isSomething
    && isSomethingElse
    && nFoo < 10) {
    bla();
    bla();
}
[–] 9point6@lemmy.world 50 points 2 years ago (1 children)

Hmm, I think the condition gets newlined and you K&R on the closing parenthesis IMO:

while (
    isSomething 
    &amp;&amp; isSomethingElse
    &amp;&amp; nFoo &lt; 10
) {
    blah();
    blah();
}

You could also keep isSomething on the first line too, but I think it's nice to keep the whole multiline condition at the same indent width

[–] nnullzz@lemmy.world 11 points 2 years ago

This is the way.

[–] isVeryLoud@lemmy.ca 10 points 2 years ago

Allman is allright, anything else I agree.

[–] Frozzie@lemmy.world 6 points 2 years ago

No no, you're speaking the truth

[–] pineapplelover@lemm.ee 3 points 2 years ago

Isn't Java like this? Everybody I know who codes java does it like this and I've been trying to follow along despite it looking stupid.

[–] Onlytanner@lemmy.world 29 points 2 years ago (1 children)

I had to look this up to verify that these are not only real styles, but there are/were some individuals had the gall to make other people consider these awful indentation styles. Of course it was only the C gods themselves to actually come up with something both readable and aesthetically pleasing.

All joking aside, I'd have to imagine some of these make more sense when applied to languages other than C. Even still, there is clearly one true winner in my book.

[–] Sibbo@sopuli.xyz 9 points 2 years ago

Yes, I totally agree with you. There is no better style than Whitesmiths.

[–] amotio@lemmy.world 28 points 2 years ago (2 children)

I was for long a long time using Kernighan style, but recently switched to Allman. Everything is suddenly more readable. It's a journey.

[–] Hawk@lemmy.dbzer0.com 3 points 2 years ago (1 children)

Won't even compile in languages like Go though

[–] amotio@lemmy.world 6 points 2 years ago

Good thing I dont use Go. Primarly php for work, c# for hobby racing game in unity.

[–] gandalf_der_12te@feddit.de 3 points 2 years ago* (last edited 2 years ago) (1 children)
while (x == y) {

   func1();
   func2();
}

notice the newline

[–] lordmauve@programming.dev 16 points 2 years ago (1 children)

This bullshit is why I use Pyrhon

[–] pkill@programming.dev 7 points 2 years ago

For concise, FP-style scripts it's quite neat. For complex OO software? Pass

[–] gandalf_der_12te@feddit.de 12 points 2 years ago

Wir sind eine diskriminierungsfreie Gemeinschaft.

[–] AVincentInSpace@pawb.social 8 points 2 years ago

Please add this to the list of things I will fight Richard Stallman about

love wins !! <33

[–] timfi@lemmy.world 6 points 2 years ago

We love them all <3

[–] Wirlocke@lemmy.blahaj.zone 5 points 2 years ago* (last edited 2 years ago)

I feel like I'd use Allman for large blocks of code (though in those situations it's probably better to stick the code in a function first) and I'd use K&R for 1 or 2 lines of code (like calling a function).

[–] ChildEater@iusearchlinux.fyi 5 points 2 years ago (2 children)

I was a K&R guy forever but I've been learning C++ recently (I know..) and I've found myself gravitating towards Allman more and more

[–] 1993_toyota_camry@beehaw.org 3 points 2 years ago (1 children)

K&R has always seemed like home to me, but I agree that Allman is pretty alright

[–] AzzyDev@beehaw.org 2 points 2 years ago

I used Allman in my C# days and the spacing always felt weird to me since i came from java :(

[–] SandLight@lemmy.world 2 points 2 years ago

I started as K&R myself due to work but switched to Allman for personal stuff and I much prefer it.

[–] SpunkyMcGoo@lemmy.world 4 points 2 years ago

hot take: python using whitespace to format rather than curly braces and semicolons is cool and epic, actually

[–] camelbeard@lemmy.world 4 points 2 years ago

I'm used to K&R so no real need to switch, also my IDE by default formats in that style. Allman also looks fine, most of the others just seem to make code less readable.

[–] moosetwin@lemmy.dbzer0.com 4 points 2 years ago

the paint bucket tolerance was too high before and fudged some of the text

[–] boo_@lemmy.blahaj.zone 3 points 2 years ago

I formatted all my C code in High School with the GNU style. I'm not sure my teacher even read the code :P

I mostly write Lisp today, but that GNU style still has a special place in my heart. As long as it's automatically formatted, I'm fine with whatever style, though.

[–] Feathercrown@lemmy.world 3 points 2 years ago
[–] Dragon@lemmy.ml 1 points 2 years ago

I've never seen Haskell used, but it looks the most readable. I would consider using it if I didn't think it would piss off other devs.

[–] lugal@sopuli.xyz 1 points 2 years ago

Haskell style would be a recursive function