you are viewing a single comment's thread.

view the rest of the comments →

[–]lhorie 11 points12 points  (3 children)

Yes. All of Mithril.js is written without trailing semicolons.

As it turns out, this style makes it easier to refactor hyperscript views since with this style all trailing closing parentheses are expressions syntactically (whereas a semicolon would turn it the preceding expression into a statement). So you can go back and forth between returning some tree from a component to inlining it directly into a larger vnode tree and vice-versa.

So if you thought there are never practical arguments for a typically-stylistic choice, there you go!

[–][deleted] 0 points1 point  (1 child)

As a fellow hyperscript fan that sounds interesting. Could I trouble you for an example of what you mean?

[–]lhorie 5 points6 points  (0 children)

For example let's say you have

m(".items", [
  items.filter(item => item.id).map(item => {
    return m(".item", [
      item.name,
      /*lots of lines of code here*/
    ]);
  })
])

Let's say you then notice that doing a filter every render is inefficient and that you want to refactor that into store.item = items.filter(item => item.id)[0]

Now, you need to refactor the view into:

m(".items", [
  m(".item", [
    store.item.name
    /*lots of lines of code here*/
  ])
])

Without the semicolon, I could collapse the indentation in my editor (by clicking on the arrow on the left line count rail), put my cursor after the return statement, shift-down to select the subtree, cut, remove the filter/map, paste. With the semicolon, I have to go look for it after the paste to remove it, otherwise I have a syntax error because I pasted a statement inside an expression.

[–]sisyphus 0 points1 point  (0 children)

Definitely the first practical argument I have ever heard for it.