mlemgroup / mlem

Mlem for Lemmy
https://lemmy.ml/c/mlemapp
GNU General Public License v3.0
180 stars 31 forks source link

Conventions Convention #55

Closed EricBAndrews closed 8 months ago

EricBAndrews commented 1 year ago

How should we format our code?

Discuss.

ShadowJonathan commented 1 year ago

cc @mormaer and @JakeShirley since they have been working on this

Sjmarf commented 1 year ago

Filenames should have no spaces and should match the name of the struct/class inside of the file where possible imo.

tht7 commented 1 year ago

I know that the current file names are weird like who tf puts spaces in file names Buttt it’s kinda growing on me, feels oddly friendly

mormaer commented 1 year ago

Don't succumb to the dark side @tht7 - stay strong

I'd vote for any new files we create being in UpperCamelCase and matching the struct/class they contain as @Sjmarf said... it's the sane choice πŸ™ƒ

It'd be worth fixing the others but given the potential nightmarish rebases against large changes to the project file I'd perhaps suggest if/when a particular file is refactored, we fix the file name at the time rather than an all at once approach

EricBAndrews commented 1 year ago

Personally I prefer the spaces--there isn't any downside to it (it's not like we're navigating through this on a terminal--Xcode handles spaces very nicely), and it makes the file name easier to read. The only reason to use CamelCase is when it's actually impractical to use spaces.

It's a very minor concern either way, though, so if people like the CamelCase I don't mind using it

Sjmarf commented 1 year ago

Every other Swift project I've worked on uses CamelCase for filenames, and so do all of the most popular Swift repos I've seen (CodeEdit, Whisky, Firefox, etc). I'm yet to see a project that doesn't do this, and thought it was some kind of standard. Google and Microsoft seem to think so, but I can't find any comments on file naming from Apple themselves.

As you say, one of the reasons why we typically avoid spaces in filenames is because of the terminal - and sure, we may not be using it now, but we may need to in future.

I'd prefer to use CamelCase for consistency with the wider Swift community, but don't really mind that much.

boscojwho commented 1 year ago

I was definitely thrown off by the spaces in some filenames. For example, when I was looking for AppState using Open Quickly:

Obviously, this is only relevant if the file only contains one type with the same name, but it gets a little tedious having to possibly think about this when you're just trying to open something quickly.

PascalCase has definitely been the convention not just in Swift, but also Objective-C, Cocoa (Touch), and first/third party Apple ecosystem frameworks. Much of this is cultural (especially within the "indie" Apple dev community), but Apple also loves to be opinionated on this subject. For example: See here for an old Apple article on naming header files in Objective-C. I couldn't find Apple's newer documentation that directly discusses filenames, but Apple's own repos also use Pascal Case, for example apple/swift-syntax

I guess it's not a big deal, as long as we don't do snake case πŸ˜†πŸ˜†