Live data from Hacker News

Alternative code styles

swalladge.id.au

21–30 of 107 posts

Re: Alternative code styles

#21
post #13

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

I'd prefer something like 3^n. Would really make you try to avoid needless nesting.

Why should I avoid needless nesting ? Is there any other reason besides the holy 80 character limit !? Nesting can for example be used to limit variable scope and make use of closures, or to avoid creating more code paths, or just make the code more readable. You can however often break some code down to named functions and it will be easier to read, with the added benefit of less nesting. But I don't see how avoiding nesting is a good rule by it's own.

Re: Alternative code styles

#22
post #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.

I don't think even you believes that. You're telling me you would be "happy" if every source file was one line?

Re: Alternative code styles

#24
post #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.

Put another way... if the proponent of a particular (serious) syntax style guide can't be bothered to automate it, then they are pissing in the wind.

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.

Re: Alternative code styles

#25
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.

"This is being used everyday in production by most financial institutions" — you can't be serious...

Re: Alternative code styles

#26
post #21
post #13

Earlier quoted context omitted.

I'd prefer something like 3^n. Would really make you try to avoid needless nesting.

Why should I avoid needless nesting ? Is there any other reason besides the holy 80 character limit !? Nesting can for example be used to limit variable scope and make use of closures, or to avoid creating more code paths, or just make the code more readable. You can however often break some code down to named functions and it will be easier to read, with the added benefit of less nesting. But I don't see how avoidin…

I think it would help with clarity - too much nesting in a function can mean it's doing too much and might need splitting into several functions

Re: Alternative code styles

#27
post #14

Earlier quoted context omitted.

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.

"This is being used everyday in production by most financial institutions" — you can't be serious...

I'm not surprised, it's an APL family language.

Re: Alternative code styles

#29
post #14

Earlier quoted context omitted.

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.

"This is being used everyday in production by most financial institutions" — you can't be serious...

KDB developers make BIG money. It's an APL-like language and used to analyze financial time-series.

Re: Alternative code styles

#30
post #21
post #13

Earlier quoted context omitted.

I'd prefer something like 3^n. Would really make you try to avoid needless nesting.

Why should I avoid needless nesting ? Is there any other reason besides the holy 80 character limit !? Nesting can for example be used to limit variable scope and make use of closures, or to avoid creating more code paths, or just make the code more readable. You can however often break some code down to named functions and it will be easier to read, with the added benefit of less nesting. But I don't see how avoidin…

You've given some good examples of nesting which don't introduce branches, but most nesting does and therefore, nesting is an approximation for the cyclomatic complexity of a piece of code. Reducing this complexity helps with testability and (moreso) with the ability of humans to understand the code https://en.wikipedia.org/wiki/Cyclomatic_complexity

Agree with you that reducing nesting is not in and of itself beneficial.

Post reply on HN