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

Or no delimiter at all in case there are no ambiguities to solve. Make a language that knows that different lines are for different stuff

  sections = [
    "one" 
    "two" 
    "three" 
  ] 
and separate with commas when you want to write something on the same line

  sections = [
    "one" 
    "two", "three" 
  ]


    sections: [
        "one"
        "two"
        "three"
    ]
and

    sections: [
        "one"
        ["two" "three"]
    ]
exists already and is named rebol (and their derivatives)


In your first example you’re just using newlines as delimiters, the second is allowing either newline or comma.


Or taking a Lisp perspective, atoms separated by white space.


That's how I do it in Civet (the CoffeeScript of TypeScript). It's a very small amount of complexity to add to the parser for a ton of convenience when using the language. https://github.com/DanielXMoore/Civet


Ruby has an interesting syntax for defining arrays of literal values.

  irb(main):001:0> sections = %w(one two three)
    => ["one", "two", "three"]


I know and it works on multiple lines too. However I never use it. Requirements change, refactoring happens, one of those literals becomes an interpolated string and all of a sudden I have to rewrite all the array. Furthermore %w() is just not nice to look at IMHO.




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

Search: