Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

C-style languages tend to have squiggly brackets which can limit scope somewhat, but not as totally as you describe.

For example:

   doThing(){
      x = 7; //x visible in whole function
      {
         y = x*2; //y only visible in this block.
      }
      // x still visible, y no longer visible
   }
Explicitly removing things from scope doesn't seem to be a feature though.


The application i am working on right now has a 766-line setup method written like this. Each block corresponds to the setup of one component. If there is something from that block that needs to be reused (typically, the channels that the component published data to), it is declared immediately above the block.

Many small bits of logic are broken out into their own methods (checking if today is a public holiday, configuring the HTTP server, configuring the KV store client, etc), but the setup of the domain logic components is all in one method.

There's no way to split the setup of the components into methods without either introducing a comparable volume of boilerplate, or having to write some kind of framework to make it easier. Neither would be a win.

A caveat: this codebase uses a language which doesn't have out parameters or multiple-value returns. If it could use those, the boilerplate involved in breaking up the setup method would be considerably smaller. But still probably not worth it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: