Ask HN: Examples of Unusual Code Formatting Styles?
The recent discussion [1] on the Black formatter for Python had me thinking about whether there is any innovation still happening in the realm of code formatting. Most of the possible ways to format code in each language must have been tried by now, and I would expect we've converged on a narrow range of permutations purely for practical reasons. But recently I did see an interesting example [2] of Java formatting from the Boot library for Clojure, with a style that I had never seen before in that language.
Are there other major variants of code formatting style still being developed out there?
[1] https://news.ycombinator.com/item?id=30130315
[2] https://github.com/boot-clj/boot/blob/master/boot/base/src/main/java/boot/App.java
21 comments
[ 4.6 ms ] story [ 63.3 ms ] threadhttps://shitcode.net/
https://govnokod.ru/
I mean this seriously, because the people are trying to solve their real problems with the tools available to them. So this has a good educational exercise.
Given near all code (let's say for large projects) is authored with IDEs, elaborate formats can be applied consistently and automatically, at little or no cognitive or typing cost.
To me the question is then if such formatting can increase the legibility of the code. The grid of static variable declarations in [2] is nice, but I wonder if sorting the variable lexicographically would make it easier to read/find a var by name?
Not sure how splitting method signature names onto a second line helps, though.
With the availabily of syntax highlighting including color, has anyone seen merit in skipping indentation altogether?
For that matter, what if block color or font size took the place of indentation (under control of syntax highlighting). I'll have to try it by hand.
However, we have more async stuff than ever before. Heavy nesting is frequent.
And then you have the weird new imperative UI stuff like Flutter/Jetpack Compose where a simple layout is brackets in brackets in brackets in brackets.
Rainbow brackets are a thing though - one of the most popular plugins in many IDEs is something that highlights different colour brackets.
I myself am a huge fan of Pascal, and limiting code to one function per line. I find that clever/terse code is unmaintainable code.
Here's some code I wrote back in 1991 for a TECO clone that reflects that style. Looking back, I think some things could have a few more comments, but it seems fairly easy to read the intent of the code.
https://github.com/mikewarot/teco
[1] https://en.wikipedia.org/wiki/Indentation_style#Horstmann_st... [2] https://bugs.llvm.org/show_bug.cgi?id=27263
I personally use 1TBS wherever possible. It just looks the cleanest to me.
GNU C formatting is odd: https://en.wikipedia.org/wiki/GNU_coding_standards
Zlib still uses K&R-1st-edition-era function definitions: https://github.com/madler/zlib/blob/cacf7f1d4e3d44d871b605da...
Sound confusing - very. I could see his "logic" but as to teaching programming students ... yes confusion all round, and wait till the poor students move on to any other language #@%%!$#!!!
Example:
https://google.github.io/styleguide/htmlcssguide.html#HTML_F...Niklaus Wirth, Verilog: http://people.inf.ethz.ch/wirth/FPGA-relatedWork/RS232R.v
all of ioccc)
I think that was done to make grepping for function definitions easier (when searching for the definition of foo, grep for “^foo\b”. That makes implementing “go to function definition” possible without having to parse code)
To make it "less crowded", and allow space for future comments, I was told.