Spyke
Solrac
lemmy.world

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?

70
gerryflapreply
feddit.nl

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

10
t_veorreply

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.

11

Meh, it's what you get when you write a language in a different language's "style".

5

You should see how a Lisper writes in their native language

They are super extra not okay

2
Gork
lemm.ee

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

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

61
feddit.uk

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

56

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

6
psycho_driverreply
lemmy.world

If you use if (blah) { then when you fold your code you still see the { but not the closing } (I suppose some IDEs might be smart enough to do something about this, but when not it looks like your code has an overbite).

And then you've got a mental disorder if you indent your opening and closing brace more than the statement spawning them.

3

Yeah, I just don't see why IDEs couldn't make them all fold in the same way. It's trivial. I don't see it as a valid complaint.

4
lemmy.world

All line breaks. Just one tower of code.

class
HelloWorld
{
public
static
void
main(String[]
args)
{
System.out.println("Hello,
World!");
}
}
33

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

16
qazreply

Iโ€™ve seen some people who code like this

3

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

31

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.

22
7heoreply

Hear me out: brainfuck, but with parentheses only.

>    )))
<    (((
+    ())
-    (()
.    ()(
,    )()
[    )((
]    ))(

Hello world example:

()))(((()(())))(())(())))))()))))(()
(()(()(()(()(((((())(((((()(()((((()
(()(()))()))(()()()))))))))())()()))
)))()(()(())())()))((()()))))(((((((
((((((()(())())())()((()(()(()(()(()
(()()((((((((()()())))))))))))())()(

Python transpiler:

#!/usr/bin/env python
"""Lipsfuck to brainfuck transpiler"""

from sys import stdin

OPS = {")))": '>', "(((": '<',
       "())": '+', "(()": '-',
       "()(": '.', ")()": ',',
       ")((": '[', "))(": ']'}


def main():
    """Obvious main procedure"""
    _d = ''.join(stdin.readlines()).rstrip('\n')
    for _op in [_d[x:x+3] for x in
                range(0, int(len(_d)), 3)]:
        print(OPS[_op], end='')
    print()


if __name__ == "__main__":
    main()
1
Eagle0600reply
yiffit.net

Indents should exclusively be a single tab per indent, not any number of spaces, and width should be handled by the IDE renderer, configurably, rather than baked into the code.

25
lemmy.world

Tabs should be 4 spaces because it can be replaced 1:1 with "tabs".

For example...

def foo():
    if bar:
        foobar()

vs...

def foo():
tabsif bar:
tabstabsfoobar()

Put that in your code review, cowards!

24
ToastedPlanetreply
lemmy.blahaj.zone

Only if a person's machine is set to a tab size of four spaces. By this logic, we would need eight spaces for the people with a larger tab size of eight on their machines so they could be 1:1. Minimizing horizontal space is ideal as not everyone has huge horizontal monitor space to work with. But, everyone has infinite vertical space with scrolling.

6

I'm a tab stop = 8 kinda guy 2 is just tiny looks like an accidental leading space

(this is also why using spaces for indentation is bad)

15
feddit.de

using 3 space wide tabs ๐Ÿ™‹

although it doesn't matter to others, because it's an editor setting.

I use nano btw.

4

People code like that????

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

Words cannot express my displeasure

12

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

11
Psythik
lemmy.world

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

10
wer2reply

For real, this is why I enable format on save.

2

GNU style is logical, because braces are syntactically a single statement:

while (x == y)
  func1();  // can be replaced by { ... }

However, I prefer to entirely avoid unbraced single statements after while/if:

while (x == y) {
  func1();  // easy to add func2(); later
}

Although this is ok when it fits:

while (x == y) func1();  // brevity!
2

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

9
wer2reply

To be fair, some of these look very different in non-C-like languages (e.g. Lisp/Haskell).

2

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.

6

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.

5
lemmy.blahaj.zone

If prefer two spaces per indention instead of tabs, but otherwise I agree with the choice of style.

4
BeigeAgendareply
lemmy.ca

Tabs has no place in code, just recently I started a project with four space indentation, that quickly got changed to two.

4

The reason I loathe tabs is that over time a codebase with tabs becomes mixed tabs and spaces and unless your editor shows tabs you can't see them.

In the end you have to choose either spaces or tabs, and enforce it with some lint tool.

3
_cnt0reply
sh.itjust.works

I love compromises, so I use 3 spaces for indentation.

9
BeigeAgendareply
lemmy.ca

Some people just want to see the world burn ๐Ÿ˜

4

Why would a development environment show you code in a different style from what you like? It's a simple conversion.

Why would your IDE show you code in a language other than you prefer? It's just a conversion.

Even my web browser shows any text in languages I can read, but for some reason it doesn't let me edit a document through the translation.

3
feddit.de

On a serious note tho, I never understood the benefits of GNU's spaces after functions. I don't really mind most of the rest but I just don't get the benefits of 'funcname (arg)' vs. 'funcname(arg)'. Is there a specific reason for this? Personally, I find this to reduce readability because I have to think for a split second whether I'm looking at a variable or a function call.

Of cause this is also due to my habits, but I'm curious as to what the reasoning is.

3
lemm.ee

Honestly I think it's just "spaces before open parens" and at least it's consistent. K&R, which I use, wants spaces before the parens in conditionals and loops but not in method sigs or method calls and the linter at work gets me almost every time I type the word "if".

4

Fair enough if the GNU dudes valued consistent spacing more than taking function calls as one "logical block". Not my cup of tea but that's what configurable auto formatting is for.

1

I want a language that takes this and has a specification for the editor to prettify it

while x==y
     func1
     func2
2

I might argue that rhe syntax of God's language is the one true syntax.

I am tired and unmotivated so I probably won't though.

1
Bonsoir
lemmy.ca

That's why Python has a superior syntax. There is usually one obvious way to do it, and that's the right way.

1