Skip to content

[✨] Reducing boilerplate #50

@Nefcanto

Description

@Nefcanto

Is your feature request related to a problem?

After working with Qwik for almost a year and migrating an entire web design company from Next.js to Qwik, we are happy that we made this choice. Qwik is fast, and we add pages without worrying about the performance trade-offs and penalties.

Now, we want to give you some feedback on ways that you can improve your code.

We are very strict about boilerplate code. We do our best and go beyond our ways to reduce boilerplate as much as we can. These are some examples in our internal static-code analyzer:

  1. If there is an arrow function with only one parameter, we ask parentheses to be removed
  2. We don't use parentheses and empty fragments to enclose a JSX, we use one of them but not both of them together
  3. If there are multiple imports from the same from clause, we emphasize merging them together
  4. We use barrelling extensible to reduce the paths inside the from clause
  5. ...

The point is we eliminate boilerplate as much as we can.

However, Qwik is filled almost with boilerplate. These are examples that we see:

  1. The long name of the package. We need to write @builder.io/ to access imports constantly. That's not the case with react or next.
  2. The dollar sign is almost useless for us after a year of working with Qwik and after using it in more than 50 projects.
  3. The need to enclose a component with component$ is useless for us. We wish we could eliminate it.
  4. The head element, which should be a named export, is a pain now. We have hundreds of pages that need to repeat five lines of code.
  5. We found ourselves using strategy: 'document-ready' on all of our useVisibleTask$ usages.

Describe the solution you'd like

1- We wish we could write qwik and qwic-city in our imports. For each import we add @builder.io/, which is 13 characters. Multiply it by two per component. Then, multiply it by thousands of components across many projects.

2- Why onClick$ and why not onClick. I read $ and may we ask for a flag to turn all of my JS code into $ codes automatically? We accept that. We say it after thousands of components in many different real-world projects. We prefer Qwik to consider our code to be fully marked with $. But we're tired of writing it constantly. It meaks code less readable.

3- We wish we could have the option to tell Qwik that all of our components are the same, thus not asking us to enclose them all with component$. We want to write all of the components in Qwik as simply as we can in Next.js.

Instead of:

import { component$ } from '@builder.io/qwik`

const Hero = component$(() => {})

We wish we could write it as:

const Hero = () => {}

And still, be able to use everything inside it. That means reducing 58 boilerplate characters per component. Multiply it by thousands of them, and you'll get a huge number.

4- This is what we have to copy/paste between all of our pages (hundreds of them):

const head = ({ resolveValue }) => {
    return useSeo(getData, resolveValue)
}

export { head }

Not even one character changes. Why should we undergo this boilerplate?

5- Maybe we have used useVisibleTask$ more than a hundred times in our code, and all of them have this at the end:

, {
        strategy: 'document-ready'
    }

Can we get an option to make it the default strategy?

Describe alternatives you've considered

There is no alternative that we can think of. If we remove component$ code won't compile. If we remove head from our index pages, we lose our SEO capabilities. If we remove $ code won't work. If we don't put strategy: 'document-ready' code won't work.

Additional context

Please note that we are thankful for your fantastic library. These are just some feedbacks from real-world projects from a team that is sensitive to boilerplate.

Thank you so much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions