Introduce formatter
See original GitHub issueMotivation
If we introduce a formatter to Optuna and just use it, we do not need to think about formatting.
Description
There are famous formatters in python:
c.f. https://blog.frank-mich.com/python-code-formatters-comparison-black-autopep8-and-yapf/
We need to discuss what formatter is best.
Differences of above formatters
black
- Use
"
instead of'
. - Add trailing commas to expressions that are split by comma where each element is on its own line.
- Break a line before a binary operator when splitting a block of code over multiple lines.
black vs yapf
c.f. https://news.ycombinator.com/item?id=17155048
- YAPF would at times not produce deterministic formatting (formatting the same file the second time with no changes in between would create a different formatting); Black treats this as a bug;
- YAPF would not format all files that use the latest Python 3.6 features (we have a lot of f-strings, there’s cases of async generators, complex unpacking in collections and function calls, and so on); Black solves that;
- YAPF is based on a sophisticated algorithm that unwinds the line and applies “penalty points” for things that the user configured they don’t like to see. With a bit of dynamic programming magic it arrives at a formatting with the minimal penalty value. This works fine most of the time. When it doesn’t, and surprised people ask you to explain, you don’t really know why. You might be able to suggest changing the penalty point value of a particular decision from, say, 47 to 48. It might help with this particular situation… but break five others in different places of the codebase.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Introducing the Q# Formatter - Microsoft Developer Blogs
Introducing the Q# Formatter · Unit Type References – Replaces () with Unit when referencing the Unit type (for example, in callable signatures)....
Read more >Introduction to Formatting the Essay
The first box is the Introductory Paragraph. As the visual above shows, these three types of paragraphs combine to form an essay. In...
Read more >formatter-maven-plugin – Introduction
Introduction. Maven plugin for formatting source code. This plugin allows formatting java source code using the Eclipse code formatter.
Read more >How to introduce a code formatter without messing up Git history
How to introduce a code formatter without messing up Git history. We still want to see who and why a line of code...
Read more >Introduction to Formatting
Formatting is the process of turning the result of an XSL transformation into a tangible form for the reader or listener. This process...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
imo, I want to use black as our formatter.
I created a PR addressing above comment https://github.com/optuna/optuna/pull/1030 (c.f. https://github.com/optuna/optuna/pull/1020#issuecomment-599403792). It has now been merged so let me close this issue. Thanks a lot @keisuke-umezawa for the long running investigation.