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

    zarkanian,
    @zarkanian@sh.itjust.works avatar

    Crockford gang approves.

    Ashiette,

    Allman is very practical for JSON

    brianary,

    Allman is the way.

    Zugyuk,

    Always Allman. Those others give you cancer

    deadbeef79000,

    Allman all the way.

    FlorianSimon,

    With all due respect, 🤮

    brianary,

    Touché!

    UNWILLING_PARTICIPANT,

    Allman makes the code look almost academic

    brianary,

    Academic code is specifically created to be easily understood, so I’d agree.

    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.

    blackn1ght,

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

    nik9000,

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

    redempt,

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

    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>
    
    pewgar_seemsimandroid,

    oh so you hate Richard stallman?

    threethan,

    Based

    LazaroFilm,
    @LazaroFilm@lemmy.world avatar

    No line breaks. Just one long line of code.

    kryptonianCodeMonkey,

    All line breaks. Just one tower of code.

    
    <span style="color:#323232;">class
    </span><span style="color:#323232;">HelloWorld
    </span><span style="color:#323232;">{
    </span><span style="color:#323232;">public
    </span><span style="color:#323232;">static
    </span><span style="color:#323232;">void
    </span><span style="color:#323232;">main(String[]
    </span><span style="color:#323232;">args)
    </span><span style="color:#323232;">{
    </span><span style="color:#323232;">System.out.println("Hello,
    </span><span style="color:#323232;">World!");
    </span><span style="color:#323232;">}
    </span><span style="color:#323232;">}
    </span>
    
    Oszilloraptor,

    why not

    System
    .out
    .println(
    "Hello,

    ?

    eupraxia,
    @eupraxia@lemmy.blahaj.zone avatar

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

    
    <span style="color:#323232;">#
    </span><span style="color:#323232;">i
    </span><span style="color:#323232;">n
    </span><span style="color:#323232;">c
    </span><span style="color:#323232;">l
    </span><span style="color:#323232;">u
    </span><span style="color:#323232;">d
    </span><span style="color:#323232;">e
    </span><span style="color:#323232;">  
    </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">lt;
    </span><span style="color:#323232;">i
    </span><span style="color:#323232;">o
    </span><span style="color:#323232;">s
    </span><span style="color:#323232;">t
    </span><span style="color:#323232;">r
    </span><span style="color:#323232;">e
    </span><span style="color:#323232;">a
    </span><span style="color:#323232;">m
    </span><span style="font-weight:bold;color:#a71d5d;">>
    </span>
    

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

    qaz,

    I’ve seen some people who code like this

    barsoap, (edited )

    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:

    
    <span style="font-weight:bold;color:#a71d5d;">let</span><span style="color:#323232;"> foo </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> [ bar
    </span><span style="color:#323232;">          , baz
    </span><span style="color:#323232;">          , quux
    </span><span style="color:#323232;">          ]
    </span>
    

    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.

    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

    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 😆

    NoLifeKing,

    >:(

    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.

    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

    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.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • 196@lemmy.blahaj.zone
  • fightinggames
  • All magazines