pewgar_seemsimandroid,

oh so you hate Richard stallman?

threethan,

Based

NoLifeKing,

>:(

psycho_driver,

Allman works best if you like folding code blocks.

JackbyDev,

Why?

psycho_driver,

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.

JackbyDev,

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.

fidodo,

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

Luvon,

Allman or even horstmann I could still deal with, the rest would be difficult.

Though none are as bad as whoever came up with right aligning all the brackets to make any code look like python until you spot the deranged line of brackets on the right…

I cannot for the life of me find it now but the dude put it on GitHub

AzzyDev,

I found this from ~9 years ago on imgur, “A Python programmer attempting Java” https://beehaw.org/pictrs/image/9781a70d-0129-42ff-9edd-6c96c202c8a8.webp

Luvon,

Haha ya that is probably it, looks great, just don’t read all the way to the right 😆

Tehdastehdas, (edited )
@Tehdastehdas@lemmy.world avatar

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.

glibg10b,

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

Bonsoir,

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

7heo,

Ok, 2 spaces or 4?

Bonsoir,

4, just like the PEP8 gods intended

ToastedPlanet,

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

BeigeAgenda,
@BeigeAgenda@lemmy.ca avatar

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

_cnt0,
@_cnt0@sh.itjust.works avatar

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

BeigeAgenda,
@BeigeAgenda@lemmy.ca avatar

Some people just want to see the world burn 😁

_cnt0,
@_cnt0@sh.itjust.works avatar

It’s warm and bright when everything burns.

zea_64,

Change your tab width, but tabs are literally made for indentation.

BeigeAgenda,
@BeigeAgenda@lemmy.ca avatar

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.

Luvon,

That last line is the solution though, choose a linter, enforce all style arguments, so they are just the way the code is. No arguments.

Every single project I work on is setup with prettier. With Java there is a maven plugin that runs it on compile. And with ts projects it is part of the built pipeline.

I wish I could use prettier for Abap, reminds me how much I like having an opinionated formatter. I don’t like wasting time formatting code manually.

Abap has one formatter that is not very opinionated, and lets way more to much wierd spacing through, especially for a language that is as verbose as abap.

Solrac,

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?

brown567,

You should see how a Lisper writes in their native language

They are super extra not okay

v_krishna,
@v_krishna@lemmy.ml avatar

Do I need to call your parens*

gerryflap,
@gerryflap@feddit.nl avatar

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

t_veor,

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:


<span style="color:#323232;">someList </span><span style="font-weight:bold;color:#a71d5d;">=
</span><span style="color:#323232;">  [ </span><span style="color:#0086b3;">1
</span><span style="color:#323232;">  , </span><span style="color:#0086b3;">2
</span><span style="color:#323232;">  , </span><span style="color:#0086b3;">3
</span><span style="color:#323232;">  ] 
</span>

or a data definition like this:


<span style="font-weight:bold;color:#a71d5d;">data </span><span style="color:#0086b3;">Color
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">Red
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#0086b3;">Green
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#0086b3;">Blue
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#0086b3;">RGB Int Int Int
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">deriving</span><span style="color:#323232;"> (</span><span style="color:#0086b3;">Show</span><span style="color:#323232;">, </span><span style="color:#0086b3;">Eq</span><span style="color:#323232;">)
</span>

or a list of module exports like this:


<span style="font-weight:bold;color:#a71d5d;">module </span><span style="color:#323232;">Foo
</span><span style="color:#323232;">  { </span><span style="background-color:#f5f5f5;font-weight:bold;color:#b52a1d;">bar</span><span style="color:#323232;">
</span><span style="color:#323232;">  , </span><span style="background-color:#f5f5f5;font-weight:bold;color:#b52a1d;">baz</span><span style="color:#323232;">
</span><span style="color:#323232;">  , </span><span style="background-color:#f5f5f5;font-weight:bold;color:#b52a1d;">quux</span><span style="color:#323232;">
</span><span style="color:#323232;">  } 
</span>

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

Phoenix3875,

Meh, it’s what you get when you write a language in a different language’s “style”.

MechanicalJester,

Allman all the way baybeeee

tanja,

W take

AVincentInSpace,

People code like that???

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

Words cannot express my displeasure

blindsight, (edited )

idk, Allman is very readable. Easy to scan vertically to find the matching open brace. Not quite as vertically-space efficient as the best way, but it’s not offensive.

I_am_10_squirrels,

Plus one for Allman gang

rubythulhu,

this is only true if you don’t indent properly

blindsight,

I literally don’t understand. I’ve read your comment several times and I don’t know what you’re talking about. Sorry!

Did you think I was saying that made Allman better than the best way? Because it’s easy to scan vertically the best way, too. It’s just also easy with Allman, so it’s not offensive.

ubergeek77,
@ubergeek77@lemmy.ubergeek77.chat avatar

I don’t think they were disagreeing with you, I think they were just trying to say:

You shouldn’t need braces to be vertically aligned if your code is uniformly indented. Then you can easily see what code is paired together just by their indentation level.

Of course this is not always true if you’ve got a bunch of crazy nested indentation pushing things off to the right.

hardware26,

In my first ever programming class textbook was using Allman. Probably for this reason, it is easy for a beginner to match braces. It is a lot loss common industry to my knowledge.

seth,

deleted_by_author

  • Loading...
  • kryptonianCodeMonkey, (edited )

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

    For example…

    
    <span style="color:#323232;">def foo():
    </span><span style="color:#323232;">    if bar:
    </span><span style="color:#323232;">        foobar()
    </span>
    

    vs…

    
    <span style="color:#323232;">def foo():
    </span><span style="color:#323232;">tabsif bar:
    </span><span style="color:#323232;">tabstabsfoobar()
    </span>
    

    Put that in your code review, cowards!

    ToastedPlanet,

    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.

    brown567,

    I think they mean the word ‘tabs’

    ToastedPlanet,

    oh lol, I missed that =p

    ChairmanMeow,
    @ChairmanMeow@programming.dev avatar

    If your code takes up so much horizontal space with 4-space tabs, you’re putting too much on one line or indenting too deep. 4-space tabs keeps your line length manageable.

    ToastedPlanet,

    Or you’re using four spaces per tab, just throwing that out there. =p

    kryptonianCodeMonkey,

    If you have to nest more than 2 layers, rewrite your code.

    Eagle0600,
    @Eagle0600@yiffit.net avatar

    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.

    Still,
    @Still@programming.dev avatar

    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)

    gandalf_der_12te,
    @gandalf_der_12te@feddit.de avatar

    using 3 space wide tabs 🙋

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

    I use nano btw.

    CheesyFox,

    nano? I mean, really?

    gandalf_der_12te,
    @gandalf_der_12te@feddit.de avatar

    nano on the command line with syntax highlighting

    CheesyFox,

    why not nvim?

    iAvicenna,
    @iAvicenna@lemmy.world avatar

    amen

    Spaghetti_Hitchens,

    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.

    strepto,
    @strepto@kbin.social avatar

    I quite like GNU

    p1mrx,

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

    
    <span style="color:#323232;">while (x == y)
    </span><span style="color:#323232;">  func1();  // can be replaced by { ... }
    </span>
    

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

    
    <span style="color:#323232;">while (x == y) {
    </span><span style="color:#323232;">  func1();  // easy to add func2(); later
    </span><span style="color:#323232;">}
    </span>
    

    Although this is ok when it fits:

    
    <span style="color:#323232;">while (x == y) func1();  // brevity!
    </span>
    
  • All
  • Subscribed
  • Moderated
  • Favorites
  • 196@lemmy.blahaj.zone
  • fightinggames
  • All magazines