Live data from Hacker News

Django: Reformatted code with Black

github.com

251–256 of 256 posts

Re: Django: Reformatted code with Black

#251
post #247

Earlier quoted context omitted.

It’s an unfortunate compromise with code formatters. As someone who takes code formatting really serious and puts a lot of manual thought into code formatting, code formatters almost always make my code worse, in my opinion, or at best unchanged outside of small errors like double spaces, etc. But it creates a standard that it loves everyone’s code towards, which is good., and also obviously alleviates the chore of m…

I often wish they were _less_ configurable. Even Black's handful of config options are too many... Each one is a chance to pick a whole new color for the bikeshed.

That makes sense, but it's a problem when the formatter makes a rather opinionated choice and doesn't allow one to configure it. The primary example I'm thinking of in Elixir is comments for pipelines.

For example, if I use the pipe example on Elixir's landing page and add comments to it (obviously a contrived example):

    "Elixir"              # string to get frequencies for
    |> String.graphemes() # Get all graphemes (i.e., character units)
    |> Enum.frequencies() # Get the number of occurrences of each grapheme
This gets formatted by the Elixir formatter to:

    # string to get frequencies for
    "Elixir"
    # Get all graphemes (i.e., character units)
    |> String.graphemes()
    # Get the number of occurrences of each grapheme
    |> Enum.frequencies()
This is a rather strongly opinionated format stance, and as far as I know, it's not configurable.

Re: Django: Reformatted code with Black

#252

Earlier quoted context omitted.

I can see how that would make it hard for you. I hope your team is accommodating.

I'm like her in that I have eye issues and thus can't use screens that are too large (16" absolute maximum) and even there it needs to be with large font. I wish everyone had stayed with 80 chars so I could have two vertical emacs buffers, but I've sorta gotten used to these ugly wrap around lines. I wish people just used more locals though. I don't see what the problem is and it makes Sentry errors easier to debug.

Having two vertical buffers/terminals side by side in a single screen is so useful!

Re: Django: Reformatted code with Black

#253

Earlier quoted context omitted.

Yup, that's a bug. All assignments are treated as properties and moved to the top. Fix to follow shortly.

Have pushed fix as version 0.10.0. Thank you very much for reporting.

Cool no problem! I'll keep an eye on this project

Re: Django: Reformatted code with Black

#254

I suggested Black to a team I was on a year ago and one developer hemmed and hawed about how he likes to format arrays or something. I didn't win any friends by pointing out that disregarding those personal preferences is part of why I was recommending it. A year later and it seems to be the default on all projects I'm working on and I'm loving it.

Autoformatters are hell for 2d arrays of data where the columns have meaning and you want them to be aligned (time series, matrix math). It’s my only real gripe.

Re: Django: Reformatted code with Black

#255
post #189

“Black” developer refused for a long time to add option to format code with single quotes with very aggressive manners. Now Django devs didn’t see that option for single quotes and code looks unpleasant.

To keep the single quotes, which in my opinion make the code less cluttered and closer to the REPL, I use the pre-commit hook double-quote-string-fixer, in conjunction with black's option skip-string-normalization set to true.

And black is supposed to make our lives easier?

Re: Django: Reformatted code with Black

#256
post #89

Earlier quoted context omitted.

Using black is not about how the code looks but to eliminate an entire suite of review comments/discussions. Everyone simply runs black over all code before submitting and no one ever comments about how anything is formatted.

With a style guide and linter I've never experienced this and idk why you would. Then the only time style comments come up is pointing someone to the guide

and that is exactly what tools like black do for you. A linter tells you a line of code could be better while as something like black goes further and makes the change for you so you don't even need to think about it.
Post reply on HN