Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider exporting functions as default #56

Open
tomek-he-him opened this issue Aug 3, 2015 · 6 comments
Open

Consider exporting functions as default #56

tomek-he-him opened this issue Aug 3, 2015 · 6 comments

Comments

@tomek-he-him
Copy link
Contributor

My two cents to #46:

When I started using trine it was a surprising discovery that trying to import map from 'trine/iterable/map' failed. It cost me some time to find out that I should have imported {map} instead.

Since I heard that “Default exports are favored” I’ve always tried to only export default out of my modules, and I’ve seen others do the same. I’ve grown to expect that of other ES 2015+ libraries as well.

Is there any reason why you use named exports instead of exporting default? That would make for even simpler syntax:

import dropTail from "trine/iterable/droptail";
import dropHead from "trine/iterable/dropHead";
import intersection from "trine/iterable/intersection";
import sortAlphabetically from "trine/iterable/sortAlphabetically";
import uniq from "trine/iterable/uniq";
import difference from "trine/iterable/difference";
import enumerate from "trine/iterable/enumerate";
import zip from "trine/iterable/zip";
import toFunction from "trine/value/toFunction";
import partial from "trine/function/partial";
@jussi-kalliokoski
Copy link
Owner

Is there any reason why you use named exports

Yes, actually. This allows code editors to know the name of the export, so for example one could imagine having a keyboard shortcut for importing a new thing and just type in the module path (or part of it) and the editor can handle the rest, including naming. :)

Also some of the modules have multiple exports:

import { partial, _, ___ } from "trine/function/partial";

@tomek-he-him
Copy link
Contributor Author

This allows code editors to know the name of the export

Sincerely, I don’t think basing a design decision on features of a code editor is the way to go.

When you import map from 'trine/iterable/map', it’s just as easy to determine the name of the export – it’s default. A good editor should figure that out.

one could imagine having a keyboard shortcut for importing a new thing and just type in the module path (or part of it) and the editor can handle the rest, including naming. :)

On Sublime I used to have a snippet for that: https://github.com/tomekwi/sublime-snippets/blob/ae89045999dff04977174fc27a694df17081364c/JS/import.sublime-snippet – no need for named exports there.

Also some of the modules have multiple exports:

No problem:

import { default as partial, _, ___ } from "trine/function/partial";

@alkhe
Copy link
Contributor

alkhe commented Aug 6, 2015

It's actually even easier.

import partial, { _, ___ } from 'trine/function/partial';

@tomek-he-him
Copy link
Contributor Author

Wow, good to know! :)

@jussi-kalliokoski
Copy link
Owner

Hmm, I'm a bit torn in between on this - I have an ideal nagging in my head that everything should be named, but then again default exports are the most convenient way to use libraries like this that export (mostly) one thing per module. :D I'd love to get more input, but I'm pretty sure you're right about this being the right way forward.

@sladiri
Copy link

sladiri commented Jul 14, 2016

If editors need named exports and can even provide some GUI to make imports easier, I can live with the extra brackets just fine. So I am a bit surprised about your last comment @jussi-kalliokoski. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants