4 ms·
What notable languages don't have an opinionated auto-formatter? Like Python/Black, Rust/rustfmt, JS/prettier, etc.
by tombh 3y ago
What notable languages don't have an opinionated auto-formatter? Like Python/Black, Rust/rustfmt, JS/prettier, etc.
- theawless 3y agoJava for sure. I don't think Google style is good enough to be called the default.
- The_Colonel 3y agoSomehow it doesn't seem to be such a big problem in Java land. I think there's some common baseline shared by basically everyone - I don't remember ever seeing Java classes which were not indented with 4 spaces for example.
- xigoi 3y agoAuto-formatting is also used for enforcing a line width limit while keeping the code readable, which is hard and tedious to do manually.
- marginalia_nu 3y agoYeah, this dates back pretty far: https://www.oracle.com/technetwork/java/codeconventions-150003.pdf https://www.oracle.com/technetwork/java/codeconventions-1500... While minor variations exist, virtually all Java code follows these conventions pretty closely. Although I'll note it seems to get a bit more chaotic with regards to indenting newer constructions like streams and lambdas.
- SOLAR_FIELDS 3y agoPeople like to pooh pooh Java in the circles I hang out in, but I’m always quick to point out stuff like this, things that are just basically mostly solved in Java land and no one really wastes time on anymore because some pretty good decisions were made 20-25 years ago. How to handle a lot of aspects of dependencies is another classic example.
- xigoi 3y agoC(++). There is clang-format which has good defaults, but it's highly configurable.
- 3836293648 3y agoclang-format has so many useless options and yet it cannot do normal readable argument handling. At least not according to the documented options (as of a few versions back at least). function( arg, arg ); New line per argument, closing parenthesis on a new line. This is standard in most langauges, yet clang-format cannot handle it. Then it also insists on aligning everything prettily. Most, but not all of it can be disabled though. And lastly it doesn't do very well with tab indents. Most of it works perfectly, you just need to set both tab size and indent size, but then it decides to do its alignment thing and suddenly that line is all spaces, even the base indent. Clang-format is honestly by far the worst formatter I've had the displeasure to fight. C/C++ still needs to be formatted manually
- SOLAR_FIELDS 3y agoI think with this kind of stuff, it should be, give me a sane set of defaults and make me change it when they don’t make sense. Rather than go to make me search and configure and have to make 100 different decisions on minutiae and exhaust my brainpower on what I would consider important but relatively low impact work in the short term
- kps 3y agoSounds like {AlignAfterOpenBracket: BlockIndent, BinPackArguments: false}
- 3836293648 3y ago(EDIT: Newlines in the code example) Oooh, that's much closer. Not perfect, but so much better. Do you have a solution for this as well? →(StructType){ →····.a = 1, →····.b = 2, →}; It's not just this scenario, but this is the worst one. It does it regardless of useTab and what's worse is that it's four spaces when both indent width and tab size are set to 8
- culi 3y agoSeems like the point of this is to work across languages though. I'm not sure how I feel about it. Different languages have their own conventions. Often times there's a reason why one convention might be preferred in a language over a different convention in another
- culi 3y agoElm even comes packaged with it's own auto-formatter
- SOLAR_FIELDS 3y agoI really like the batteries included philosopy. I think golang really took the idea mainstream but deno, heavily inspired by go and that philosophy, also is a joy to use.
- armchairhacker 3y agoOne of Haskell's most popular formatters, Formolu [1], is explicitly not opinionated and has custom whitespace as a goal: > Let some whitespace be programmable. The layout of the input influences the layout choices in the output. This means that the choices between single-line/multi-line layouts in certain situations are made by the user, not by an algorithm. This makes the implementation simpler and leaves some control to the user while still guaranteeing that the formatted code is stylistically consistent. Coq, Agda, etc. also don't have formatters either, partly because "user-defined layout", but also partly because their syntax is just so complicated and they have smaller ecosystems [1] https://hackage.haskell.org/package/fourmolu https://hackage.haskell.org/package/fourmolu