Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up style guide and tooling for consistency in backend code #1008

Closed
silentninja opened this issue Jan 21, 2022 · 17 comments
Closed

Set up style guide and tooling for consistency in backend code #1008

silentninja opened this issue Jan 21, 2022 · 17 comments
Labels
affects: dx Related to developer experience affects: technical debt Improves the state of the codebase ready Ready for implementation type: enhancement New feature or request work: backend Related to Python, Django, and simple SQL
Milestone

Comments

@silentninja
Copy link
Contributor

silentninja commented Jan 21, 2022

Problem

Right now the backend code has inconsistent styling in few places though they are all valid according to flake8. We should aim to have a style guide that should be followed as much as possible and convert the existing codebase to follow that styleguide

Proposed solution

Come up with a draft of style guide + associated tooling (linters, formatters, etc.), then discuss with the rest of the backend team and finalize it.

Additional context

@silentninja silentninja added type: enhancement New feature or request status: triage affects: dx Related to developer experience affects: technical debt Improves the state of the codebase work: backend Related to Python, Django, and simple SQL and removed status: triage labels Jan 21, 2022
@dmos62
Copy link
Contributor

dmos62 commented Jan 21, 2022

Part of this is a copy-paste of a comment I left in Matrix.

The issue is called "Backend Codebase should follow consistent coding style", but I think that's too strong of a statement. I was expecting to discuss adding automatic formatting rules.

Style is not a very well defined term. I'd say we should discuss the formatting we use and/or want to enforce.

@silentninja
Copy link
Contributor Author

We definitely cannot expect 100% consistent codebase, but we can add a few rules that would choose one style over the other when given two sensible options

@kgodey kgodey added this to the [07.2] 2022-02 improvements milestone Jan 21, 2022
@kgodey kgodey added ready Ready for implementation and removed status: draft labels Jan 21, 2022
@kgodey kgodey changed the title Backend Codebase should follow consistent coding style Set up style guide and tooling for consistency in backend code Jan 21, 2022
@mathemancer
Copy link
Contributor

As I argued on Matrix: I think the easiest way to get this off the ground quickly would be with the black. I recognize that it's overly opinionated, and we may disagree with some of its formatting (I know I do). I also remember that these reasons are why we removed it from the pipeline initially. However, black is also completely hands-off. We just run it, commit it, and go on by having it run on files in the pipeline. This could be done by the end of the day, without any configuring or thinking needed other than just adding the GH action. There's value in that.

@dmos62
Copy link
Contributor

dmos62 commented Jan 24, 2022

I wish we could have personal setups and a single neutral rule-set for the repository. We apply black to what we check out to personalize the code, then we apply black to de-personalize when commiting. Not sure if that's feasible.

Totally tangential, but I feel like code versioning systems should account for the fact that there's a lot of changes you can make to code that only affects its formatting and are totally irrelevant to compilers. Then you could format stuff however you like and not affect any other developer's experience. Though, you'd still have to take care to write good code. Short functions and all that.

@kgodey
Copy link
Contributor

kgodey commented Jan 24, 2022

@mathemancer and I discussed the usage of black during our check in call today. I don't think the issues we've been facing with code reviews are because of formatting, it's because of different views on code structure and readability. It's better to address those issues as they come up and creating a style guide and using as much linting as we can to enforce the style guide. This will probably involve making smaller pull requests than we're currently making.

The issue with black or any auto-formatting is not the formatting that it produces, it's that it automatically rewrites code without knowing the intention of the humans that produced that code.

@dmos62
Copy link
Contributor

dmos62 commented Feb 4, 2022

I've looked at black's style guide: https://black.readthedocs.io/en/latest/the_black_code_style/current_style.html and I really liked it. It should solve some pain points that I've been experiencing.

I'm antsy to try it out on our codebase to get a better picture of the effect. I don't feel like I have an hour to burn at the moment. If anyone would like to do it, go ahead!

@kgodey
Copy link
Contributor

kgodey commented Feb 4, 2022

@dmos62 I'm very skeptical of black, see my previous comment. Please wait until I have time to work on this, hopefully in the next week or two. Once there's a concrete proposal for styling, it will be easier to discuss.

@dmos62
Copy link
Contributor

dmos62 commented Feb 4, 2022

@kgodey my idea is let's run black and look at the output. Then we have something to talk about.

I haven't looked at its style configuration, but it mentions that it purposefully doesn't offer a lot of options.

@kgodey
Copy link
Contributor

kgodey commented Feb 4, 2022

@dmos62 We already did that early on in the project and then disabled it. I've also used it at previous workplaces.

@dmos62
Copy link
Contributor

dmos62 commented Feb 10, 2022

I'll include another link here to the code-style guidelines/tooling discussion thread, since we seem to be discussing this on two threads simultaneously: #1007.

@seancolsen
Copy link
Contributor

Sorry, I wasn't aware of this ticket when I commented on #1007.

@kgodey said:

The issue with... auto-formatting is... that it automatically rewrites code without knowing the intention of the humans that produced that code.

I'm curious to hear more about your concern here. Can you provide an example of a case in which you find it helpful to communicate intent through code formatting? I also wonder whether Mathesar's python code might contain intent within formatting that fails to reach me because I typically do not attempt to infer intent from formatting while reading code. If we have conventions for communicating intent through formatting in our codebase, are those conventions documented anywhere?

@kgodey
Copy link
Contributor

kgodey commented Feb 14, 2022

If we have conventions for communicating intent through formatting in our codebase, are those conventions documented anywhere?

@seancolsen We have no backend conventions documented anywhere. The action item for this issue is to first document backend style and formatting conventions, and then set up tooling to support those conventions.

I'm curious to hear more about your concern here.

I plan to create a draft of our backend style guide first before spending more time on this conversation; I think we'll have a more productive discussion when we actually have a concrete proposal to discuss. I'm reading through everyone's comments on this issue and on #1007 and I'll make sure to address them in the style guide. It might take me a couple of weeks because my current priority is getting the Views product work done.

@dmos62
Copy link
Contributor

dmos62 commented Feb 15, 2022

@kgodey you've mentioned disliking black for this. The rest of us aren't familiar with it though and it's such a low effort alternative that I think it's worth looking at (collectively). It would be nice to have its output around for comparison when discussing other options, for example.

@kgodey
Copy link
Contributor

kgodey commented Feb 15, 2022

@dmos62 Turning on black is low effort but it has huge consequences across the codebase since it reformats everything and wipes out all existing formatting. Please have patience until the style guide is ready.

You are free to experiment with black or other tools locally if you want to see their output for comparison when discussing other options.

@dmos62
Copy link
Contributor

dmos62 commented Feb 15, 2022

Please have patience until the style guide is ready.

Didn't mean to hurry. I don't think this is a high priority.

@kgodey kgodey modified the milestones: [06.2] 2022-04 improvements, [08.1] 2022-05 improvements May 2, 2022
@kgodey kgodey removed this from the [08.1] 2022-05 improvements milestone Jun 1, 2022
@kgodey kgodey removed their assignment Jun 2, 2022
@kgodey kgodey added this to the Unprioritized milestone Jun 2, 2022
@github-actions
Copy link

github-actions bot commented Feb 4, 2023

This issue has not been updated in 90 days and is being marked as stale.

@github-actions github-actions bot added the stale label Feb 4, 2023
@dmos62 dmos62 removed the stale label Feb 6, 2023
@kgodey
Copy link
Contributor

kgodey commented Dec 19, 2023

This is not a current priority, closing this.

@kgodey kgodey closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: dx Related to developer experience affects: technical debt Improves the state of the codebase ready Ready for implementation type: enhancement New feature or request work: backend Related to Python, Django, and simple SQL
Projects
No open projects
Development

No branches or pull requests

5 participants