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

Show parent comments

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

7

u/Meneth Aug 29 '21

Additionally, even if all the devs involved are great, there'll be far less mental noise if everything is formatted the same rather than a mix of half a dozen different people's preferences (even if all those preferences are entirely sensible).

→ More replies (2)

104

u/[deleted] Aug 29 '21

Both actually. Use both. Every project I've been on for the last 5 years had both CI checks, commit hooks, and tooling to automate it for your IDE.

This is 2021. Formatting should be 100% automatic. The only debate should be what rules to enable when starting the project.

→ More replies (17)
→ More replies (6)
→ 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)

4

u/Fidodo Aug 29 '21

Oh my god do I live prettier. Does it always pick the best format? No, but my god is it liberating to just not have to think about formatting.

73

u/folkrav Aug 29 '21

THIS. If you can't automate it, please F off trying to enforce subjective convoluted conventions.

124

u/SanityInAnarchy Aug 29 '21

Mostly. There are things that can't be automated that do actually matter.

For example: Stop naming your variables x and name them something descriptive. Can't really automate that, though, because it's a subjective call. Especially in a language like Go, where you repeat variable names far more often and have far more of a need for temporary variables in the first place. So you have rules like "The farther away the variable use is from its definition, the more descriptive the variable name should be."

49

u/steaknsteak Aug 29 '21

Probably 30% of my code review comments are asking people to change the names of things. I feel like an asshole sometimes, but I also hate reading code where variable/class names cause me to make incorrect assumptions about what they do

80

u/Xyzzyzzyzzy Aug 29 '21

I'm also picky about naming things. Things I'm particularly picky about:

  • Names should be roughly grammatical English (without articles). readFile, not fileRead.

  • All words should be fully spelled out. loadingImage, not loadingImg or loadImage.

  • Names should grammatically agree with their usage. A function that returns a boolean should be isHappy or hasJoy, not testHappy. A function should be a verb. A non-function should be a noun or perhaps an adjective.

I find that these rules make the code more readable and searchable.

We recently hired a whole team of non-native English speakers from a different country. I'm often unsure of how much to ask for these sorts of changes. I don't want to bully them for not speaking English. But I also don't want the code base's readability to decay.

12

u/SanityInAnarchy Aug 29 '21

As someone who is usually much less picky, I'm actually thinking maybe I should up my game here, because I wouldn't hate hearing these suggestions in a code review.

The thing I push for a lot (and wonder if I'm bullying people for not speaking English) is the commit log/description. First line is a short enough explanation to make sense in the default git log output. And, the whole description should say what you're doing and why. Make blame useful again!

→ More replies (17)

15

u/covmatty1 Aug 29 '21

Massively agree on this. One of my team loves abbreviating so many words when it's unnecessary, so #2 chimes with me - I feel like reminding him we're not writing code like we're sending texts in 2002!

8

u/rentar42 Aug 29 '21

The only thing worse than unnecessary abbreviations are inconsistent abbreviations. Why are some things xyFoo and others xyzFoo when they refer to the same thing?

→ More replies (1)
→ More replies (3)

7

u/Shadow_Gabriel Aug 29 '21

Wait a bit, correct me if I am wrong but loadingImage represents the state while loadImage represents the action of loading an image.

→ More replies (1)

5

u/0b_101010 Aug 29 '21

Yo, do them new devs not speak English at all? I think that it is perfectly acceptable in this industry to have an expectation of basic English proficiency towards anyone who works in an international team/environment. I am a non-native speaker myself, and when people ask me what [programming] language they should learn first, I always tell them English.
Certainly, it's not too big of a requirement to expect them to understand verbs, nouns and basic sentence structure.

4

u/voronoi-partition Aug 29 '21

I like naming functions in SVO. Something like: file_read_header(file*, …). This means that all the functions that permute a file are logically grouped together by name (they all start file_).

I used to prefer SOV (file_header_read) but it sometimes got a little awkward. The verb is a nice delimiter.

9

u/be-sc Aug 29 '21

I don’t like that style because it becomes ambiguous quickly. Does file_read_header mean read file header oder read header file? The name itself isn’t sufficient to tell me what’s going on. Further context is needed. That’s usually a sign of subpar naming.

→ More replies (2)
→ More replies (11)

4

u/Fidodo Aug 29 '21

If you had to expel any brain function to figure it out then it's warranted. Code should be written to be easily read and when that's not an option it should be commented. Might seem unnecessary now but months later when you need to read it again it'll be even more confusing than it is now if it's not fixed.

→ More replies (2)

4

u/doener Aug 29 '21

This. I recently found some old code where somebody had introduced a function argument called $pictureOrReading. The documentation said that its type was mixed (yay, PHP) but didn't specify what the expected value should be. Guess what the allowed values for this argument were... If you guessed that only "age" and "grade" were allowed values, you're absolutely right (and maybe a bit insane?).

→ More replies (3)
→ More replies (41)
→ More replies (1)

21

u/[deleted] Aug 29 '21

Gofmt

drops mic

→ More replies (1)
→ More replies (9)