slint icon indicating copy to clipboard operation
slint copied to clipboard

Allow trailing commas

Open Tmpod opened this issue 1 year ago • 3 comments

Trailing commas have become a must have in "modern" programming languages, and I think Slint should implement them too.

Let's consider a simple Slint file:

import { Foo, Bar } from "lib.slint";

export component Baz inherits Foo {
  Bar { }
}

Imagine I now want to import Bork as well:

import { Foo, Bar, Bork } from "lib.slint";

But now the line is getting a bit big and I'd like to make it clearer what we're importing:

import {
  Foo,
  Bar,
  Bork
} from "lib.slint";

All good. Now I need Asdf too

import {
  Foo,
  Bar,
  Bork    // missing comma!
  Asdf
} from "lib.slint";

Oops! Now I want to rearrange my imports to be in alphabetical order.

import {
  Asdf    // missing comma!
  Bar,
  Bork,
  Foo,
} from "lib.slint";

:/

The point is, trailing commas help with rapid development, since it's one less weird rule you have to keep in mind. After you've used a language with them, it's hard to go back. They're good because they are mostly an invisible QoL feature.

Tmpod avatar Mar 22 '24 11:03 Tmpod

I like this suggestion :)

tronical avatar Mar 22 '24 12:03 tronical

This needs to be changed in this function: https://github.com/slint-ui/slint/blob/5ec80bcf2e80b2ae04e8d8a74fabe40d611cfdb1/internal/compiler/parser/document.rs#L307 Also the export lists might have the same problem. But note that, for example, functions call argument already support that (see parse_function_arguments)

ogoffart avatar Mar 22 '24 12:03 ogoffart

Nice! Might look into it, but can't promise anything :P

Tmpod avatar Mar 22 '24 19:03 Tmpod