Live data from Hacker News

Alternative code styles

swalladge.id.au

11–20 of 107 posts

Re: Alternative code styles

#12
post #6

The best coding styles are the ones that allow to be translated back and forth to another style. 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.

Using git filters is a great idea! I've heard of this for translating between unix and dos line endings in git, but hadn't thought about using it for entire styles. There are heaps of automatic code formatting tools becoming more popular these days too.

Re: Alternative code styles

#14
post #9

Surprised nobody talks about the kdb codding style: https://github.com/KxSystems/kdb/blob/master/c/c/k.h

:O that is ... interesting. Sure that's not an entry for the ioccc? ;)

Nope :) This is being used everyday in production by most financial institutions. https://code.kx.com/wiki/Cookbook/InterfacingWithC

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.

Re: Alternative code styles

#15

That Fibonacci based indentation might not be a bad idea after all. Especially when doing callback-style javascript.

there's also the "inverse fibonacci mode", where the indentations become smaller and smaller at each level

it feels like when your handwriting becomes more compressed as you are about to reach the right end of the paper

Re: Alternative code styles

#16
post #14

Earlier quoted context omitted.

:O that is ... interesting. Sure that's not an entry for the ioccc? ;)

Nope :) This is being used everyday in production by most financial institutions. https://code.kx.com/wiki/Cookbook/InterfacingWithC 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.

I think looking at this code has already caused a buffer overrun in my brain ;)

Re: Alternative code styles

#17
The only style there that is actually used by a person is the Bourne style. There are other styles that people develop for themselves, for example there was some Haskell program posted to a mailing list with a warning about personal style. This defines:

  (.) :: 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 ->)

Re: Alternative code styles

#18

That Fibonacci based indentation might not be a bad idea after all. Especially when doing callback-style javascript.

I think something simpler like (n)(n+1)/2 is better. This means that the difference between the n-th and (n+1)-th indentation level is n spaces (barring of by one errors I made).

We still get a curving indentation, and we are still warned against nesting, but the indentation doesn't explode exponentially.

Re: Alternative code styles

#19

> Poetry... quite eye-pleasing I disagree with this comment. That style makes the code extremely hard to follow, as there's no proper indention to identify scope.

Most of these examples are meant to be a joke, I’d assume.

Probably I've taken this so serious since the article mentioned Bourne Shell code, which is a real project, and the Fibonacci indent style is actually nice.

Re: Alternative code styles

#20
Nowadays I couldn't care less about what style is used. As long as the code is consistent and there's an easy way to adhere (clang-format, black, prettier, etc.) I'm happy.
Post reply on HN