timrwood / moment-es6

MIT License
3 stars 0 forks source link

Feedback about export code style #8

Closed timrwood closed 9 years ago

timrwood commented 9 years ago

most files have one export at the top, but there are some with inline exports. I guess we should enforce one export at the top with jscs or similar.

via @ichernev

trek commented 9 years ago

Why'd you pick top exports and not bottom? I've mostly seen bottom exports in the wild.

ichernev commented 9 years ago

Because its kind of the metadata of the file, and it makes sense to be easily visible immediately when you open the file.

Not to mention that some files just have a random export here and there, which is worse that being always at the top or always at the bottom.

When I looked more deeply -- most function definitions (because they bubble to the top) are exported at the top, but the variables and classes don't bubble (appear to be defined at the top), so they're not exported at the top (there is no way :))

timrwood commented 9 years ago

I think it's kinda nice to split up the private/public interfaces in a module.

// Public
export { foo, bar };
import { baz } from "baz";

// Private
var bar = "Bar";
function foo () {}
function privateFoo () {}

Unfortunately, when transpiling to other formats, because vars are not hoisted like functions, they end up being undefined. This is why I exported all vars inline, but functions at the top.

I guess if we are looking for a consistent export style, all inline as export function bar () {} or all as an object at the bottom of the file would be better.

timrwood commented 9 years ago

Switched all exports to inline export function foo () {} style.