django-stars / backend-skeleton

108 stars 41 forks source link

codestyle with black #10

Closed Quard closed 5 years ago

alexryabtsev commented 5 years ago

@Quard What length of the line did you specify to run black?

Quard commented 5 years ago

default - 88

You probably noticed the peculiar default line length. Black defaults to 88 characters per line, which happens to be 10% over 80. This number was found to produce significantly shorter files than sticking with 80 (the most popular), or even 79 (used by the standard library). In general, 90-ish seems like the wise choice.

alexryabtsev commented 5 years ago

But in our code style it's 120. And it's also configurable in Black.

I've asked my previous question because with 120 symbols length Black will reformat this code:

@admin.register(models.User)
class UserAdmin(DjangoUserAdmin):
    fieldsets = (
        (None, {"fields": ("password",)}),
        (_("Personal info"), {"fields": ("first_name", "last_name", "email")}),
        (
            _("Permissions"),
            {
                "fields": (
                    "is_active",
                    "is_staff",
                    "is_superuser",
                    "groups",
                    "user_permissions",
                )
            },
        ),
        (_("Important dates"), {"fields": ("last_login", "date_joined")}),
    )

to:

@admin.register(models.User)
class UserAdmin(DjangoUserAdmin):
    fieldsets = (
        (_("Personal info"), {"fields": ("first_name", "last_name", "email")}),
        (_("Permissions"), {"fields": ("is_active", "is_staff", "is_superuser", "groups", "user_permissions")}),
        (_("Important dates"), {"fields": ("last_login", "date_joined")}),
    )

@Quard @romanosipenko @SergeyKubrak Do we want to change the length of the string to 88?

P.S. I'm not blaming. It could be rationale. Because we agreed on 120 symbols length when didn't have plans to use automatic linters that could reformat code automatically (yapf is not the case, because we haven't agreed finally about it).

Quard commented 5 years ago

you still able to change it in your project but according to science in general it's hard to keep so many object in mind for general people

romanosipenko commented 5 years ago

@alexryabtsev I prefer 120 in any case.

Quard commented 5 years ago

btw 120 will not always work

If you're paid by the line of code you write, you can pass --line-length with a lower number. Black will try to respect that. However, sometimes it won't be able to without breaking other rules. In those rare cases, auto-formatted code will exceed your allotted limit.

Quard commented 5 years ago

so no one want to try to increase readability by applying Miller law(7±2) to our code?

alexryabtsev commented 5 years ago

Argument to choose 88 symbols

alexryabtsev commented 5 years ago

@alexryabtsev I prefer 120 in any case.

Yes. But in this case it doesn't make sense to use 88 in skeleton because it will be reformatted on first linter run.