20
Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Code Style GuidesOr: How I Learned to Stop Worrying and Love Spaces

Page 2: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Who?● David M Sibley

● New MyUW Full Stack Developer

● Previous 7 years at US Geological Survey

● As Technical Lead, I had many opinions

● Coming in to MyUW, I decided to shove those to the back and learn

Page 3: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Tabs vs Spaces

Page 4: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

MyUW Values● Open Source

● Small Directed

Commits

● Pull Request

Review

Page 5: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Which fights are worth it?● As Technical Lead, I had many opinions

○ Tabs

○ No extraneous commas

○ One return statement

○ Semicolons at the end of every statement

● Coming in to MyUW, I decided to shove those to the back and learn

○ There is no one true way to write code

Page 6: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

What is going on here?● You don’t want to scroll through a thousand line diff for a fifty line change

Page 7: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

The Crux

Style differences are the bottleneck for productivity of a team.

Not style merits

Page 8: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

MyUW Plan● Arbitrarily pick ONE overarching style

● Give team members the tools to succeed

Page 9: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

MyUW Implementation● Google Style for Javascript

● ESLint

○ Husky Plugin to Lint on Commit

Page 10: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Google Style● There’s a lot of

rules!

● Let someone

else figure this

out.

Page 11: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Google Style● I don’t want to

look through

this every time

I write code.

Page 12: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

ESLint● Automated

Style Checking

Page 13: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Google Style● Two Spaces per Indentation

● Don’t Pad Functions with Whitespace

● Trailing & Extraneous Commas

● 80 Characters per Line

Page 14: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

ESLint● 2925 ERRORS?!

Page 15: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

ESLint● Run Autofix

● Warn down large

scale offenses

● Left with ~300

miscellaneous

errors

○ Over 20 files? I

can handle that.

Page 16: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

ESLint● Add rules back in

one by one until

you’re adhering

to the standard

Page 17: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

ESLint● Add rules back in

one by one until

you’re adhering

to the standard

Page 18: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

ESLint● Add rules back in

one by one until

you’re adhering

to the standard

Page 19: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Lessons Learned● Commit by Rule, not Structure

● Don’t make exceptions, unless style would change

functionality.

● Save Line Length for last.

Page 20: Code Style Guides - University of Wisconsin–Madison€¦ · Code Style Guides Or: How I Learned to Stop Worrying and Love Spaces

Thanks!