Alternative code styles
swalladge.id.au
swalladge.id.au
My experience is: each time a team started doing this, all coding-style related discussions vanished, and it became a non-issue. It turns out it's a lot easier to accept a coding style you're not the one doing the actual formatting (this is why, BTW, I think stylechecking hooks alone are a bad idea).
I laugh when I see those 50-page English-language documents describing how some institution wants code to be formatted. Ain't nobody got time for that.
What situations have you found where automated formatting doesn’t suffice or has these limits?
Some tools order/deduplicate imports. Prettier does not. [1]
And no tool that I've seen orders fields/constructor/method, etc.
But in any cases, all formatters allow you to selectively disable it for certain liners.
It would be, but as you can see in the linked issue, it was closed for being a non-goal. So, it's not likely to change.
(Prettier generally keeps the AST identical; i.e. whitespace and parentheses changes only.)
That said, I haven't seriously tried programming using variable width fonts; maybe it's a well-kept secret to digesting code. Or maybe it's like Hemp Milk, there's a reason it hasn't caught on.
PS: The idea is not mine but I can't remember where I read the instructions about this editor setup, so Google is your friend.
https://gist.githubusercontent.com/diegoperini/853d54c8873e7...
* to be fair, I’d have trouble with a bad proportional font like Times New Roman, but I’m sure many would have trouble with Courier New on the other side, the specific font matters.
And you can still manually format code, serif or monospace.
Proportional or monospace font choice is orthogonal to formatting.
(Edited to be more specific)
Mono space allows you to do manual alignment, eg if you want ascii art in your code or non standard formatting. Doing this with a proportional font means other people can’t read your code without using the same font.
At the end of the day, it is important that the code looks like it was written by one consistent person and not 20 random different people.
I really don't like the mandatory use of eslint (used as style enforcement), prettier, etc. When used as a bat to hit developers over the head, all this tells me is that the organization has too many anti-social developers that can't check their ego at the door.
Often someone will recommend a tool or technology in place of simple social common sense. If a developer can't follow the existing code style, they should be shunned. It's their problem. It's not a problem to solve with a fancy tool. You solve this particular problem by telling that person that they are an asshole. Using technology to solve social problems just exacerbates the problem.
All of that leads to a situation where we can't have nice things. You go into a codebase and see hundreds of exceptions to turn off eslint or whatever. Instead of just working around one-off style exceptions with common sense (who really gives a damn if a line needs broken/indented a certain way for a specific function) you have to plead with the style cops to let you off each and every time.
Developers really hate each other. Small organizations or teams tend to be a bit better in my experience. There is more camaraderie. But I often feel like I'm in a group of mercenaries, each ready to stab you in the back.
I certainly could go through and make sure all the spacing is exactly right, the functions/properties are in the right place, and rest of the rules of the styleguide are followed. But it's much easier to do when you get a warning, squiggly, or can use an autoformatter to match the rules.
I would never intentionally violate a rule, but I might forget a rule or miss a violation. With linters this is not an issue, the machine will let you know.
Everyone can focus on the correctness and quality of code and let the machine worry about making sure everything is formatted correctly.
Clearly the project you describe, where linting is disabled every other line is bad. But I wouldn't blame the linter for that. I don't know what can be done if a team has such a commitment to their own style that they put in the extra work to disable the linter.
A linter is not a tool for punishing people who violate a style guide, it's an assistant for people who are trying to follow a style guide.
EDIT: looks like the tool support is so bad, Horstmann himself pretty much gave up: http://horstmann.com/unblog/2010-06-28/braces.html
I've been told that the guy who wrote this believe that the brain only has a limited buffer to compute source code. So he is trying to use the shortest code possible everywhere.
As someone who writes q all day, it's typical to see functions written in one line and no white spaces. The mantra is, if it takes you more than 1 line you're probably doing it wrong.
It looks obfuscated, but in fact it is just a lot of information. Many people would claim dividing it in 10 files with longer function names and less tricks would make it easier to understand, but after spending a long time studying (and partly rewriting) this code, I actually find the terse version better.
I'm sure Mr. Goldberg understood his machines just fine, too.
I also started using "result" after seeing it in Pascal code and have quite liked it for many years, but I just had the epiphany that "ans" (answer, as seen on several graphing calculator lines) would be a little more dense.
Basically, it was well worth it to try these radical styles out. They did a lot to smooth my everyday coding.
(.) :: a -> (a -> b) -> b
x.f = f x
And then the author can write e.g. x.length
Instead of length x
I think this is really quite a natural operator (and other languages support it, eg in F# it is pronounced |> and closure has something like it with ->)It doesn't matter which style you prefer. As long as a computer can pick it up and translate it into the project standard style and back to yours again. You can simply setup git filters and live in you own style world.
As such, code should be written for clarity and presentation. To communicate intent. Automated tools destroy this human/code connection. They reduce your coworkers to simple cogs in a machine, rather than authors and communicators.
I'm not a fan of this cold, brave new world.
I applaud companies like Google and Hashicorp for forcing formatting as compilation errors. As it lets you get on with the real tasks ahead.
If at each potential error point you best one level, you quickly find yourself deeply nested.
I find the pattern of exiting early and having the “happy path” running to the end of the scope to make it much easier to comprehend a function (I’m sure there’s a term for this coding style but I can’t find the name of it at the moment).
Agree with you that reducing nesting is not in and of itself beneficial.
Because it is, by definition, needless. If there is a good reason for doing so, it is no longer needless.
it feels like when your handwriting becomes more compressed as you are about to reach the right end of the paper
We still get a curving indentation, and we are still warned against nesting, but the indentation doesn't explode exponentially.
Seriously though, I find myself oddly attracted to the Python-braces style .. if only I could use it without running afoul of my own list.
Aaaand… “we're achieving levels of nerdery that shouldn't be possible.”
I disagree with this comment. That style makes the code extremely hard to follow, as there's no proper indention to identify scope.
Imagine every non-whitespace character in your code were replaced with garbage. Indent so that the reader could still understand the structure of your code.
First job out of school, I joined a place with a lot of EE's writing VHDL tools.
So EE's--no offense--at that time viewed software as a solved problem if you did everything by a book (any book) and a spec and a waterfall.
So despite working in C, which was already plenty idiomatic with a fine K&R standard, they insisted that while(p-- = p--) was verboten and instead made a bunch of FOOL/LOOP, WHILE/ELIHW, IF/FI and other abhorrences to hide the idioms they didn't like (such as braces) and make it more like algol/pascal. This was all less important than actual CS principals.
Then to make matters worse, there was a SPEC, a binder full of PAPER pseudocode mostly in algolish, some hand written. But every piece of code needed to refer back to its spec. Of course those things got out of spec quickly so any new feature was always about triple work.
Yes, and it was uphill both ways.