3 ms·
I'd be curious to see experiments with variable numbers of line breaks to create additional structure. I find my own code significantly more readable by separat
by Ankintol 6y ago
I'd be curious to see experiments with variable numbers of line breaks to create additional structure. I find my own code significantly more readable by separating certain "sub-blocks" of code with two line breaks, with their internal structures having single line breaks.
thing_1_a
thing_1_b
thing_1_c
thing_2_a
thing_2_b
It fits into the framework proposed here but is not mentioned specifically as having been investigated.
- viklove 6y agoThe problem is, to most people it just looks like you made a mistake. If you want to create breaks in your code, consider adding comments or breaking blocks out into their own functions.
- Ankintol 6y agoDoes it look like I made a mistake to most people? I've never received a comment in a PR about it and I observe other developers using the same technique, so I'm surprised to hear this, do you feel very confident in this assessment? Just trying to gather feedback here.
- Leherenn 6y agoMaybe not a mistake, but code smell, often, yes. If you add blocks, it's usually because you want to group things together, and avoid scope leakage (if that's an issue, then you're probably doing similar things multiple times). Often a function will be a better fit here.
- twic 6y agoIn some long functions (really only very long app-setup functions), i break up related bits into blocks: { thing_1_a thing_1_b thing_1_c } { thing_2_a thing_2_b } Blocks are are a language feature in a few languages, but are barely ever used, so it is rather weird to write and read at first.
- danlugo92 6y agoNote to onlookers: blocks can soemtimes act weird in javascript. I loved using them but alas.
- qayxc 6y agoNot just in Javascript. Since blocks define a scope, visibility and unexpected lifetime issues may occur in other curly-braces languages like C and C++ just as well. Using blocks like that is something you should be very careful about - might have some surprising effects especially for novice programmers.
- twic 6y agoThe blocks here act exactly the same as any other blocks, like the ones you write for loops and ifs etc. So i wouldn't exactly call the consequences "unexpected".
- danlugo92 5y agoI can't recall right now but I remember having errors that would not happen inside a normal for loop block. And I was using let/const not var.