Hacker News new | ask | show | jobs
by twic 1919 days ago
In 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.
1 comments

Note to onlookers: blocks can soemtimes act weird in javascript. I loved using them but alas.
Not 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.

The 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".
I 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.