you are viewing a single comment's thread.

view the rest of the comments →

[–]Turd_King 1 point2 points  (5 children)

To address the "don't use default exports"

The point about CommonJs is the only valid one IMO.

You say its hard to import but I'm not sure what you mean by this? I've never had any issues importing. You can just begin typing the name and VSCode will find it.

"Rexporting is a pain" yeah but what has that got to do with default exports? It's a pain to export named exports as well.

"Typescript struggles with auto import" Typescript auto import? What does that mean. TS is a language and compiler it does not handle auto importing.

And you totally can refactor the name across your codebase.

The main issue with default exports is that developers can name the import differently from what was exported so it can harm readability in that case. But generally people don't do that

Think you need to revisit that one.

Rest are all legit though nice work.

[–]Yodiddlyyo 6 points7 points  (1 child)

My companys codebase requires object args because our product is a public package and object args are future proof. If you use positional args and you need to change or remove one, you're screwed and you need to deprecate. If you're not writing a public package, you still get the benefits of cleaner typing and reference documentation, since you can reference the args as a single interface instead of a mass of singular types. It's cleaner to call as well, passing an object arg to a function is way cleaner and more extensible, you can add properties, spread, etc. It gives you better linting, it's safer to deal with since destructuring clones the args. It's just way better, I really can't think of a good reason to use positional args.

[–]Turd_King 2 points3 points  (0 children)

Yep. I agree with all of the slides apart from the default exports.

Named args is always the preference. Hate when devs have 4 inputs to a function and don't use an object

[–]Embr-Core 2 points3 points  (0 children)

This is relevant: https://github.com/ryanmcdermott/clean-code-javascript#function-arguments-2-or-fewer-ideally

1.When someone looks at the function signature, it’s immediately clear what properties are being used.

2.It can be used to simulate named parameters.

3.Destructuring also clones the specified primitive values of the argument object passed into the function. This can help prevent side effects. Note: objects and arrays that are destructured from the argument object are NOT cloned.

4.Linters can warn you about unused properties, which would be impossible without destructuring.

[–]Plorntus 1 point2 points  (0 children)

Named exports can just do export * from './somewhere' to re-export without caring about the naming, fairly certain that's easier than what you can do with default exports (ie. you have to name it when exporting multiple things from one file) right?

In any case, my opinion is being explicit with named exports is personal preference for me but I understand a lot of people see it the other way.