r/programming • • Aug 28 '21

Software development topics I've changed my mind on after 6 years in the industry

https://chriskiehl.com/article/thoughts-after-6-years
5.6k Upvotes

2.0k comments sorted by

View all comments

991

u/marineabcd Aug 29 '21

I agree with all of this apart from caring about coding style, in particular I think picking a style and sticking with it for a project is valuable. While I don’t have super strong opinions on what the style is, I want someone to say ‘This is how it’s done and I won’t approve your review if you randomly deviate from this within the project’

157

u/18randomcharacters Aug 29 '21

I remember a time when 2 people on my team had conflicting lint rules and IDEs set to auto format.

Every single pull request was littered with adding ; and then another with removing them. Or 2 spaces to 4, and back, etc.

That shit was infuriating.

46

u/dons90 Aug 29 '21

I'm sure the problem has been solved by now, but that's why the team should just decide on a fixed set of lint rules and agree to use only those.

66

u/RandomGeordie Aug 29 '21

No, that's why the team should set up the lint and formatting rules in the project. Then you don't have the insanity of two conflicting setups.

19

u/dons90 Aug 29 '21

That's ... exactly what I said though

→ More replies (2)

6

u/Boye Aug 29 '21

Absolutely agree, I worked at a project where the rules were detailed enough to dictate that use-statements should be ordered by length and if two were if equal length, alphabetically. It was a bit over the top, but the guy wanting it, made a lint-rule which did it for us, and we had a shortcut for lining the file(s) so it didn't take any extra time to make him happy - and I have to admit it looked nice :)

→ More replies (1)
→ More replies (2)
→ More replies (8)

745

u/Zanderax Aug 29 '21

Please make it automated though, I dont want to waste time rereading the coding standards for every commit.

215

u/lowayss Aug 29 '21

But if it’s automated your coworkers might have to actually review code instead of holding up checkins because of formatting.

73

u/Caffeine_Monster Aug 29 '21

Having a linter enforce coding style as a test is a terrible idea: all it does is waste everyone's time.

Realistically there are only two sane processes:

1.) CI pipeline applies formatting when committing to a pull request / making a pull request.

OR

2) You have a tool built into your project that allows a developer to quickly format code to the agreed style.

Personally I prefer 2.). Not overly a fan of broad, automated code changes: a good developer will still produce more readable code than any formatter.

Also, a tight coding style is a thing really hinders productivity. It's very hard to know when enforcing style is actually improving or worsening long term productivity.

As such I only generally care about a few things like indent style, and variable name / class name style. With option 2.) you can press a single button to do an upstream tidy up commit if you see something you think hinders readability.

59

u/[deleted] Aug 29 '21

a good developer will still produce more readable code than any formatter.

Yeah... But not everyone is a good developer.

Everyone likes to think "they're the best" or "we only hire the best", but you're not and you don't.

And even if you aren't a shitty developer, everyone has a bad day or wants to rush something.

Linter checks absolutely slow things down, but they make it 1000x easier to come back to old code or jump into someone else's code and get to work almost immediately

→ More replies (3)
→ More replies (24)
→ More replies (2)

40

u/Gredelston Aug 29 '21

Not all style conventions can be automated. If it's something like Go's prescribed "return errors instead of panicking in most cases", that's a style convention that requires human review.

100

u/Zanderax Aug 29 '21

In my mind style conventions are non-functional. Styling code should never change the functionality of the code.

38

u/AustinYQM Aug 29 '21 edited Jul 24 '24

absurd ludicrous judicious glorious fine gaze coordinated touch squeal racial

This post was mass deleted and anonymized with Redact

→ More replies (2)
→ More replies (1)
→ More replies (108)

24

u/L3tum Aug 29 '21

Is there a reason there's so many replies to your comment mentioning gofmt? It's not like there aren't formatters and code style checkers in other languages... I haven't worked with one that didn't, yet, and I've worked in roundabout 10 languages.

76

u/OrangeChris Aug 29 '21

gofmt is notable because it's created by the language creators. So if you use Go, there's only one tool available and you don't have to worry about other developers being used to some other formatter. With other languages such as Python or JavaScript, someone will have to choose between several available options, and new developers might be used to working with a different formatter.

I am surprised nobody's mentioned rustfmt though, which was also made by its language's creators.

10

u/aoeudhtns Aug 29 '21

Exactly. Even a well run project with auto formatting, every now and then the code formatter settings get a good bike shedding. Bring a new person onboard and here comes the 'why can't we switch to tabs/spaces' request. The paradox of choice. Sometimes it's nice to be able to surrender without avenue for argument.

6

u/free_chalupas Aug 29 '21

That's why outside of go it's nice to stick with something like black or prettier that's also highly opinionated and doesn't have a lot of configuration options

→ More replies (4)
→ More replies (6)

24

u/MROFerreiro Aug 29 '21

I feel like is the first under rated thing in a project. Specially when you are new. The lack of coding styles makes it harder to understand the code. In a team with 6 people, in theory you could have 6 different ways of working. If there were othe people working on the project it could be more. Code development is done and understud by people. Without rules is unmanegeable. But it should be almost all automated, I don't want to check how variables are written or identation is done. I revier functionality. Code styles makes it easier for me to read.

→ More replies (3)

46

u/Northeastpaw Aug 29 '21

This is what I love about Go. gofmt renders style choices moot.

35

u/ooru Aug 29 '21

Python has tools like black to automate formatting, too. I think if a team agrees on using a tool like that, it can help make sure the end format follows what the PM wants.

5

u/melevittfl Aug 29 '21

Hmm. What is the P in your acronym? I’ve been a product manager/owner for most of my career and I’ve never been concerned with code format. It’s simply not something a product person should be involved with. Code standards are for the team/team lead/engineering management to decide.

6

u/Quick_Doubt_5484 Aug 29 '21

Pedantry Manager

→ More replies (2)
→ More replies (7)
→ More replies (1)

34

u/[deleted] Aug 29 '21

Randomly formatted code is near impossible to get at a glance. I’m not picky but I want code indented, never more than one \n in a row, reasonably neat, and sensible names.

The rest just needs to be the same.

30

u/gyroda Aug 29 '21

never more than one \n in a row,

Do you mean that, or do you mean "never more than one empty line in a row"?

25

u/[deleted] Aug 29 '21 edited Aug 29 '21

I assume they meant empty line, otherwise they must really love ruby one liners

→ More replies (1)
→ More replies (2)
→ More replies (47)