Hacker News new | ask | show | jobs
by ilyash 1263 days ago
Comments Section

In Next Generation Shell I've experimented by adding

    section "arbitrary comment" {
      code here
    }

and this is staying in the language. It looks good. That's instead of

    # blah section - start
    code here
    # blah section - end

Later, since NGS knows about sections, I can potentially add section info to stack traces (also maybe logging and debugging messages). At the moment, it's just an aesthetic comments and (I think) easily skip-able code section when reading.

Symbols

I've decided not to have symbols in NGS. My opinion (I assume not popular) is that all symbols together is one big enum, instead of having multiple enums which would convey which values are acceptable at each point.

4 comments

I sometimes do something like:

  var foo string
  { // Do stuff
      // ...
      foo = "..."
  }

  { // Other section...
  }
You can also split stuff up in to sections, but for some kind of functions where you know the functions will never be re-used and are intimately related, I find this clearer.

Of course, your language will need to have block scope, or at least blocks.

If it's just for comments, IIRC Lisp has docstrings - the very first expression in a Lisp function can be a string literal which gets compiled into the final executable as a docstring which can be retrieved at runtime.
You can do something similar in JavaScript

> const love = "love"; > { // Section > console.log(`What is ${love}`); > }

Not the same ergonomic.

The language doesn't "understand" it's a section (no opportunities listed in the original comment).

Actually, it does, though the only real use is with the `break` keyword for breaking out of a labelled block (or break / continue in a for loop): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Things like stack traces don't track them, unfortunately.

C# has #region/endregion

They are foldable in IDEs

And the result is people writing 10k LOC files.

I'm not sure this is the right approach…