factoriolib / flib

A set of high-quality, commonly-used utilities for creating Factorio mods.
https://mods.factorio.com/mod/flib
MIT License
64 stars 15 forks source link

Style guide #1

Closed raiguard closed 2 years ago

raiguard commented 4 years ago

I have been trying to follow this style guide recently, and it has served me pretty well. I like it because it has rationales for most of its points, and most of them are very reasonable.

But there are a few exceptions that I would like to make:

  1. Two-space indent instead of three-space indent
  2. Hard line limit at 160 characters. As per discussion on Discord, there is no hard line limit, though try to keep everything under 120 characters. If something goes a bit over, it's not the end of the world.
  3. Omitting parenthesis for functions that take a unique table argument on a single line is allowed:
    foo{bar=true, lorem="ipsum"}
  4. We are not using a top-level src directory.
JanSharp commented 4 years ago

I'd like to recommend this guide for git commit messages.

mspielberg commented 4 years ago

I like 120-160 characters as a line limit, if for no other reason than readability on Github with side-by-side diffs. Your screen may have room for 200 characters when writing the code; it probably doesn't have room for 400 characters when reviewing somebody else's PR.

justarandomgeek commented 4 years ago

I don't usually enforce a strict line length limit, but I just measured the editor layout i'm using and the main pane is close to 100 apparently, with a smaller (<80) pane next to it. If I full-screen a single pane i get out to about 190 or so.

I think a limit in 100-160 range is probably reasonable. I'd like most lines to be <100, but the occasional very long line doesn't really bother me.

justarandomgeek commented 4 years ago

You should not omit parenthesis for functions that take a unique table argument on a single line. You may do so for table arguments that span several lines.

I'm gonna disagree with this one too, since table arguments are so common in factorio's api and we're all used to it already.

raiguard commented 4 years ago

I agree, I overlooked that one. I'll add it to the list.

raiguard commented 2 years ago

flib uses stylua now, so there's no need for manually upkeeping style any longer.