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.
Alternative code styles
61–70 of 107 posts
Re: Alternative code styles
#62Imagine every non-whitespace character in your code were replaced with garbage. Indent so that the reader could still understand the structure of your code.
Re: Alternative code styles
#63Earlier quoted context omitted.
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 benefi…
Re: Alternative code styles
#64The 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 languag…
Re: Alternative code styles
#65Re: Alternative code styles
#66Wow! I've never heard of bournegol. That is really cool.
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.
Re: Alternative code styles
#67Earlier quoted context omitted.
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 benefi…
Re: Alternative code styles
#68Nowadays 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
#69Earlier quoted context omitted.
Sign of an experienced architect. Read: "I'm old and too tired to argue, just don't break it ok."
I'm 32 and I feel like I'm already at that stage sometimes. What will I be like when I'm 50?