this post was submitted on 10 Feb 2024
610 points (99.7% liked)

196

16601 readers
2244 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 93 points 9 months ago (1 children)

Allman is very practical for JSON

[–] [email protected] 71 points 9 months ago (4 children)
[–] [email protected] 21 points 9 months ago

Always Allman. Those others give you cancer

[–] [email protected] 19 points 9 months ago

Allman all the way.

[–] UNWILLING_PARTICIPANT 6 points 9 months ago (1 children)

Allman makes the code look almost academic

load more comments (1 replies)
[–] [email protected] 73 points 9 months ago (6 children)

Finally, someone understands that Allman is not that great, and that Kernighan & Ritchie is the way to go. Also, Haskell, my guy, you good? Lisp, are you ok? Do I need to call your parents?

[–] [email protected] 38 points 9 months ago

Do I need to call your parens*

[–] [email protected] 34 points 9 months ago

Allman all the way baybeeee

[–] [email protected] 10 points 9 months ago (1 children)

I've written Haskell quite a bit, and I don't fully understand why this is called Haskell style. Haskell code looks nothing like this, the syntax is completely different. For Haskell's syntax I think it works fine, because I never noticed something weird. But this code in "Haskell style" looks absolutely insane

[–] [email protected] 11 points 9 months ago

It's sometimes called comma-leading style where you move all the special characters to the front of the line and it is exceedingly common in Haskell, possibly due to how Haskell treats significant whitespace. You've surely seen list definitions that look like this:

someList =
  [ 1
  , 2
  , 3
  ] 

or a data definition like this:

data Color
  = Red
  | Green
  | Blue
  | RGB Int Int Int
  deriving (Show, Eq)

or a list of module exports like this:

module Foo
  { bar
  , baz
  , quux
  } 

Or in a long function type declaration where the arrows are moved to the start of the line, or a record definition, etc. etc.

load more comments (3 replies)
[–] [email protected] 61 points 9 months ago (1 children)

All of those are heretical. The one True Language is Brainfuck, where the coding syntax for Hello World is

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

load more comments (1 replies)
[–] [email protected] 55 points 9 months ago (2 children)

Allman looks fine to me. But I'm a C# dev so maybe I'm just used to it.

[–] [email protected] 22 points 9 months ago

It's not my favorite but it's fine.

[–] [email protected] 6 points 9 months ago

Allman changes the way I code. I avoid using imperative constructs so much more because they waste so much more space on my screen.

[–] [email protected] 46 points 9 months ago (3 children)

Allman works best if you like folding code blocks.

load more comments (3 replies)
[–] [email protected] 33 points 9 months ago (1 children)

No line breaks. Just one long line of code.

[–] [email protected] 33 points 9 months ago* (last edited 9 months ago) (3 children)

All line breaks. Just one tower of code.

class
HelloWorld
{
public
static
void
main(String[]
args)
{
System.out.println("Hello,
World!");
}
}
[–] [email protected] 15 points 9 months ago* (last edited 9 months ago)

as always, c++ lets us do better in breathtakingly elegant fashion:

#\
i\
n\
c\
l\
u\
d\
e\
 \ 
<\
i\
o\
s\
t\
r\
e\
a\
m\
>

finishing out hello world is left as an exercise to the reader, but the advantages and superior performance of this format should be obvious

[–] [email protected] 7 points 9 months ago* (last edited 9 months ago)

why not

...

System
.out
.println(
"Hello,

...

?

load more comments (1 replies)
[–] [email protected] 31 points 9 months ago

Tell me you're a Java developer without telling me you're a Java developer.

[–] [email protected] 28 points 9 months ago (1 children)

Haskell, baby, what is you doing??

load more comments (1 replies)
[–] [email protected] 22 points 9 months ago* (last edited 9 months ago)

Noone writes Haskell like that. People generate Haskell like that because layout syntax is a fickle beast to generate and outputting braces means you can make mistakes in layout without breaking things, the way the braces and semicolons are output emphasise how they actually don't matter, they're also easy to delete in a text editor.

Also it matches up with other Haskellisms, e.g. lists:

let foo = [ bar
          , baz
          , quux
          ]

See how it's immediately apparent that you didn't miss a single comma? It's also trivial to match up opening and closing brackets like that, even in deeply nested situations.

Not doing that is actually my main pet peeve with Rust's standard formatting.

[–] [email protected] 19 points 9 months ago

Allman is the only other one that has some sanity.

[–] [email protected] 18 points 9 months ago (2 children)

That's not Lisp...

(while (== x y)
  (func1)
  (func2)
)
[–] [email protected] 16 points 9 months ago (1 children)

(((((Not(enough)))((parentheses)))))

[–] [email protected] 7 points 9 months ago (1 children)

No syntax, only parentheses

load more comments (1 replies)
[–] [email protected] 8 points 9 months ago

What kind of monster writes lisp with the closing bracket on its own line.

[–] [email protected] 16 points 9 months ago

Allman is objective the correct choice

[–] [email protected] 12 points 9 months ago* (last edited 9 months ago)

People code like that????

People indent braces more than the line before and less than the line after?

Words cannot express my displeasure

[–] [email protected] 11 points 9 months ago (1 children)
load more comments (1 replies)
[–] [email protected] 11 points 9 months ago

Looking at them all, I don't hate whitesmiths. Keeps all the associated block on one line which makes it a bit easier to parse

[–] [email protected] 10 points 9 months ago (1 children)

If you have ADHD, your coding style is a combination of all of these, and sometimes none of the above.

load more comments (1 replies)
[–] [email protected] 9 points 9 months ago

I use Allman for control statements and K&R for declarations

[–] [email protected] 9 points 9 months ago (1 children)

oh so you hate Richard stallman?

[–] [email protected] 10 points 9 months ago
[–] [email protected] 7 points 9 months ago (1 children)

Some of those made me physically ill.

Like. You do WHAT with your whitespace?!

load more comments (1 replies)
[–] [email protected] 6 points 9 months ago

Go is a very opinionated language which is why I was so lucky for their opinion on this (and other things) to agree with mine.

[–] [email protected] 5 points 9 months ago

Allmans what I learnt then went to K&R on my own because it made more sense to me. I think GNU is fine I guess, not the others though. Not that what I say matters I've forgotten how to code and can barely do Hello World these days.

[–] [email protected] 5 points 9 months ago

The eternal holy wars rage on

load more comments
view more: next ›