Skip to content

Discussion: DSL syntax #75

Open
Open
@isaac-udy

Description

@isaac-udy

I'd like to start a bit of a discussion around the DSL syntax.

Multiple paths to one goal:

router.clear()
router.push(Route())
router { 
    clear() push Route()
}
router {
    clear()
    push(Route())
}

There are several ways to perform similar actions. The first way isn't correct, as it won't bundle up the actions as a single item, but my understanding is the last two ways are essentially the same. ̛I think it would be a better idea to have a single syntax, even if it means that a single "push" needs to be performed as:

router { push() }

Builder syntax:

router {
    clear() push RouteA() push RouteB() push RouteC()
}

The builder continuation syntax that allows a user to push a series of routes like this is inconsistent with the use of infix functions, as a user is unable to split these onto different lines. The following code will not compile:

router {
    clear() push RouteA()
        push RouteB()
        push RouteC()
}

I have two questions:

  1. Is the builder/continuation syntax actually useful? Could commands just be split onto different lines?
  2. If the builder/continuation syntax is useful, should the use of infix be removed, so a user can split the continuation over multple lines?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions