howl-editor / howl

The Howl Editor
http://howl.io
Other
712 stars 68 forks source link

[moonscript] import vs destructuring at the beginning of files #542

Closed Delapouite closed 4 years ago

Delapouite commented 4 years ago

Hello

While exploring the codebase, I stumble upon similar patterns. Examples:

in lib/howl/breadcrumbs.moon:

{:signal, :config, :sys, :timer} = howl

in lib/howl/bindings.moon:

import signal, command, sys from howl

My knowledge of moonscript syntax is pretty low, but I assume they mean the same. (It's somehow confirmed in this section of the manual : https://moonscript.org/reference/#the-language/destructuring-assignment)

So, if they are indeed equivalent, which form should be favored? For example if the import form is the blessed way to express this intention, should we rewrite the incipit of all the files having the destructuring form?

The advantages of this refactoring would be:

Should this kind of decisions about syntax styles be written in a "contribution guideline doc" to help developers who want to be involved with the project? Better, could this be enforced during the linting phase through moonpick?

shalabhc commented 4 years ago

Yeah I like the import syntax but usually I just copy whatever is in the file. I assume one pattern was used first and then switched to another one. Wanna ask if @refi64 has any opinion here..

refi64 commented 4 years ago

I had assumed that the import syntax was the preferred way and the destructured assignment was used in some older code? I mean personally the import syntax is way nicer, though it did cause me some confusion at first since it doesn't, err, actually import anything.

On Thu, Nov 14, 2019 at 7:04 PM Shalabh Chaturvedi notifications@github.com wrote:

Yeah I like the import syntax but usually I just copy whatever is in the file. I assume one pattern was used first and then switched to another one. Wanna ask if @refi64 https://github.com/refi64 has any opinion here..

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/howl-editor/howl/issues/542?email_source=notifications&email_token=AAM4YSNGPW3CHXRIYSSCUP3QTXYTFA5CNFSM4JNLHGFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEED5JDA#issuecomment-554161292, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM4YSOET4NQIKZVH4YR6GTQTXYTFANCNFSM4JNLHGFA .

-- Ryan (ライアン) Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone else https://refi64.com/

On Thu, Nov 14, 2019 at 7:04 PM Shalabh Chaturvedi notifications@github.com wrote:

Yeah I like the import syntax but usually I just copy whatever is in the file. I assume one pattern was used first and then switched to another one. Wanna ask if @refi64 https://github.com/refi64 has any opinion here..

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/howl-editor/howl/issues/542?email_source=notifications&email_token=AAM4YSNGPW3CHXRIYSSCUP3QTXYTFA5CNFSM4JNLHGFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEED5JDA#issuecomment-554161292, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM4YSOET4NQIKZVH4YR6GTQTXYTFANCNFSM4JNLHGFA .

-- Ryan (ライアン) Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone else https://refi64.com/

shalabhc commented 4 years ago

I don't feel too strongly about this so I'm not inclined to modify existing code. I'm ok with saying new code should prefer imports. We don't have a style guide and would need a bit more material than just 'use imports' to get one going. Do you want to get a style guide page started on the wiki, @Delapouite?

nilnor commented 4 years ago

I can add some light on the history of this. Moonscript didn't have destructuring assignments from the start so only the import keyword was available. Destructuring was added later, after which that became an option instead of import. Destructuring has one advantage of import in that it's possible to alias the imports, e.g. to import table.insert as the local append:

{insert: append} = table

Apart from that both are usable.