You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
breaking changeFor issues and PRs. Changes that break compatibility and require a major version increment.status: in discussionFor issues and PRs. Community and maintainers are discussing the applicability of the issue.
@mickhansen recently raised the possibility of using babel to allow Sequelize to be written using ES6 features while retaining compatibility with versions of node earlier than v0.12.
I'm writing node apps in ES6. Using generators, co and yield makes it sooooo much simpler to write async code. No more endless .then() promise chains...
But I'm running these apps in node v0.12 with --harmony so the ES6 features are native.
I'd be broadly in favour of transitioning Sequelize to ES6, because the benefits in terms of writing shorter, more comprehensible code are so large.
However, what are the implications for debugging? If the source code goes through a babel compilation, does that make it hard to locate the source of a bug, if a thrown error references a line number which doesn't correspond to the right line in the source code?
I'd suggest if you wanted to go this way, to restrict ES6 features used to those available natively in node v0.12 with --harmony, so it can run without compiling on node v0.12. Babel compilation could be switched on only for older node versions.
IMHO I think the suggestion to just use harmony is sort of dead in the water since you'd basically be telling users that sequelize no longer works with 0.10.x and if they want to use it with 0.12.x they have to run with --harmony: no thanks.
I think babel is your only choice if you want to go down this path, it provides a nice platform for which to support all the things you need to support here while still looking forward.
@mbroadst My suggestion was that Sequelize would work natively on 0.12.x with --harmony, but that when run on 0.10.x it would be babelized. So it'd run on both platforms, but with no need for babelization if you're on node 0.12.x.
But in any case, I didn't realize that as @mickhansen said some of the best ES6 features aren't available in 0.12.x harmony. So my whole idea is dead in the water for that reason!
My question remains though: What are the implications for debugging babelized code? Presumably the cross-compile changes line numbers, so when looking at an error stack trace, it could be hard to follow what's going on - the stack trace wouldn't correspond to the source code. This would be a deal-breaker for me as it could make Sequelize unmaintainable.
That said, I haven't tried babel, so there may be solution for this. Anybody know?
I'd imagine it'd be possible for babel to be written so that line numbers are preserved (by making very long lines in some cases!), but I don't know if it does this.
In my experience using sourcemaps in node (which does not include a project as large as Sequelify), the source maps support using the module linked by @mbroadst has been fine for any debugging I've needed to do.
The tech for ES6 dev is pretty good, so if I were maintaining a popular ES5 project, I would probably worry most about how it affects the core contributors and community. A few examples:
What do maintainers spend most of their time on? Would the improvement in productivity be worth the investment in learning and creating the tooling to use ES6?
How important are PRs from non-core contributors? What is the culture of the community? Would using ES6 in the project reduce the number of PRs and negatively affect the project?
Fork vs. evolve - What are the trade offs of evolving the current project rather than creating a new ground-up ES6 porject (a la koa)?
I love writing in ES6, but for a mature OSS project, I suspect the considerations that have the most gravity are the non-technical ones.
Now that Node v4 is released and so there are two versions of node (v.0.12 with harmony flag and v4) which support some ES6 features, I think it's worthwhile looking at this again.
@mickhansen has mentioned dynamic object keys and destructuring assignment, but for me the killer feature of ES6 is being able to use co and generators. This makes it so much easier to write async code with is both faster to write and much more comprehensible. I've started using it everywhere and it's revolutionised my coding.
This is available natively in node v0.12 with --harmony flag without any transpiling. And also in node v4. To continue support for node v0.10 (which I think Sequelize should), it would require babel.
I see 3 options:
Keep everything as is, natively supporting node v0.10 onwards
Restrict Sequelize code to only what is natively provided in node v0.12 with --harmony, and transpile with babel for node v0.10 (which would allow for co and generators)
Go the whole hog, and transpile with babel for all versions of node, to allow all ES6 features (and also async/await from ES7)
Personally, I think option (2) is a good middle way allowing users of modern node to run Sequelize code natively, while still supporting node v0.10. Extra language features could also be brought into use (e.g. destructuring assignment) as node v4 matures and these ES6 features become natively supported.
Node 4 supports a lot of ES6 functionality now too, including native promises meaning a dependency on bluebird could be removed. This may come with a performance improvement too.
Having switched to co-routines a while back, I really can't sing their praises enough. It makes code so much easier, faster and more pleasurable to write.
I've found I produce less buggy code as you don't have to worry about all the code inside .then(function() { /* code here */ }) constructs having a different scope (and this context) than the next .then() block.
I'd hate having to switch away from CLS, but bluebird has built in support for domains - which also allow you to store values on them, and maintain callback context, see petkaantonov/bluebird#583
@janmeier Well CLS should work, but bluebird author has rejected suggestions in the past to include CLS support. The shim of bluebird used in Sequelize to add CLS support is I suspect a little buggy, so that's what's meaning we don't have full bullet-proof CLS support.
But, in theory, CLS is a universal method for callback context. Just got to iron out the bugs of integrating it with bluebird.
@overlookmotel@mickhansen there is absolutely no need to use promisify-any since Promise is the way async functions will work tomorrow. If you want to use generators with today Sequelize, you juste have to do something like that:
@MarkMurphy It has actually been mentioned :) We're not going with it internally since it would require bluebird-coroutines are we're not sure of the perf implications.
However users are as always welcome to us it, and we might update docs to reflect it.
@verdier I just suggested using promisify-any as currently Sequelize hooks can be written either as classic node callback functions OR promise-returning functions. promisify-any takes care of that, so handling callback functions could be removed from the Sequelize codebase.
The additional support for generator co-routines is an extra benefit.
@verdier There are also some died-in-the-wool callback devotees who like that style of programming and will probably never change. Seems bonkers to me, but different strokes for different folks... our vision of the future isn't necessarily shared by everyone.
breaking changeFor issues and PRs. Changes that break compatibility and require a major version increment.status: in discussionFor issues and PRs. Community and maintainers are discussing the applicability of the issue.
Activity
overlookmotel commentedon Jun 17, 2015
My opinion is:
I'm writing node apps in ES6. Using generators, co and
yieldmakes it sooooo much simpler to write async code. No more endless.then()promise chains...But I'm running these apps in node v0.12 with
--harmonyso the ES6 features are native.I'd be broadly in favour of transitioning Sequelize to ES6, because the benefits in terms of writing shorter, more comprehensible code are so large.
However, what are the implications for debugging? If the source code goes through a babel compilation, does that make it hard to locate the source of a bug, if a thrown error references a line number which doesn't correspond to the right line in the source code?
overlookmotel commentedon Jun 17, 2015
I'd suggest if you wanted to go this way, to restrict ES6 features used to those available natively in node v0.12 with
--harmony, so it can run without compiling on node v0.12. Babel compilation could be switched on only for older node versions.mickhansen commentedon Jun 23, 2015
@overlookmotel The beautiful dynamic object keys and structural deassignments aren't in harmony though :/
mbroadst commentedon Jun 23, 2015
IMHO I think the suggestion to just use harmony is sort of dead in the water since you'd basically be telling users that sequelize no longer works with 0.10.x and if they want to use it with 0.12.x they have to run with
--harmony: no thanks.I think babel is your only choice if you want to go down this path, it provides a nice platform for which to support all the things you need to support here while still looking forward.
overlookmotel commentedon Jun 24, 2015
@mbroadst My suggestion was that Sequelize would work natively on 0.12.x with
--harmony, but that when run on 0.10.x it would be babelized. So it'd run on both platforms, but with no need for babelization if you're on node 0.12.x.But in any case, I didn't realize that as @mickhansen said some of the best ES6 features aren't available in 0.12.x harmony. So my whole idea is dead in the water for that reason!
My question remains though: What are the implications for debugging babelized code? Presumably the cross-compile changes line numbers, so when looking at an error stack trace, it could be hard to follow what's going on - the stack trace wouldn't correspond to the source code. This would be a deal-breaker for me as it could make Sequelize unmaintainable.
That said, I haven't tried babel, so there may be solution for this. Anybody know?
mickhansen commentedon Jun 24, 2015
It would break stack traces, i'm not sure if node.js has great sourcemap support, likely not.
overlookmotel commentedon Jun 24, 2015
I'd imagine it'd be possible for babel to be written so that line numbers are preserved (by making very long lines in some cases!), but I don't know if it does this.
overlookmotel commentedon Jun 24, 2015
This blog post talks about using source maps with ES6 compilation:
http://www.2ality.com/2015/04/node-es6-transpiled.html
mbroadst commentedon Jun 24, 2015
https://github.com/evanw/node-source-map-support ? This was literally just a google search, I'm putting minimal effort into furthering this case ;) just want to see where it goes!
SpainTrain commentedon Jul 14, 2015
$0.02 💰
In my experience using sourcemaps in node (which does not include a project as large as Sequelify), the source maps support using the module linked by @mbroadst has been fine for any debugging I've needed to do.
The tech for ES6 dev is pretty good, so if I were maintaining a popular ES5 project, I would probably worry most about how it affects the core contributors and community. A few examples:
I love writing in ES6, but for a mature OSS project, I suspect the considerations that have the most gravity are the non-technical ones.
Related: #3840
cusspvz commentedon Sep 15, 2015
In my opinion all node LTS versions should be supported.
Regarding to
0.10and0.12versions support I agree with @mbroadst , babel register seems the only reasonable choice.xpepermint commentedon Sep 20, 2015
+1
overlookmotel commentedon Sep 21, 2015
Now that Node v4 is released and so there are two versions of node (v.0.12 with harmony flag and v4) which support some ES6 features, I think it's worthwhile looking at this again.
@mickhansen has mentioned dynamic object keys and destructuring assignment, but for me the killer feature of ES6 is being able to use co and generators. This makes it so much easier to write async code with is both faster to write and much more comprehensible. I've started using it everywhere and it's revolutionised my coding.
Example code in current Promises style:
With co...
This is available natively in node v0.12 with
--harmonyflag without any transpiling. And also in node v4. To continue support for node v0.10 (which I think Sequelize should), it would require babel.I see 3 options:
--harmony, and transpile with babel for node v0.10 (which would allow for co and generators)Personally, I think option (2) is a good middle way allowing users of modern node to run Sequelize code natively, while still supporting node v0.10. Extra language features could also be brought into use (e.g. destructuring assignment) as node v4 matures and these ES6 features become natively supported.
But that's just my personal opinion...
rickihastings commentedon Nov 12, 2015
Node 4 supports a lot of ES6 functionality now too, including native promises meaning a dependency on bluebird could be removed. This may come with a performance improvement too.
16 remaining items
overlookmotel commentedon Jan 13, 2016
Having switched to co-routines a while back, I really can't sing their praises enough. It makes code so much easier, faster and more pleasurable to write.
I've found I produce less buggy code as you don't have to worry about all the code inside
.then(function() { /* code here */ })constructs having a different scope (andthiscontext) than the next.then()block.It's a beautiful thing man!
mickhansen commentedon Jan 13, 2016
I use them extensively in all my code aswell, i'm just not sure it would be responsible to switch our entire underlying library to use it yet :)
janmeier commentedon Jan 13, 2016
I'd hate having to switch away from CLS, but bluebird has built in support for domains - which also allow you to store values on them, and maintain callback context, see petkaantonov/bluebird#583
mickhansen commentedon Jan 13, 2016
domains have been deprecated forever though: https://nodejs.org/api/domain.html
janmeier commentedon Jan 13, 2016
So basically there is no universally supported method for callback context ...
Edit: nodejs/node#66
overlookmotel commentedon Jan 13, 2016
@janmeier Well CLS should work, but bluebird author has rejected suggestions in the past to include CLS support. The shim of bluebird used in Sequelize to add CLS support is I suspect a little buggy, so that's what's meaning we don't have full bullet-proof CLS support.
But, in theory, CLS is a universal method for callback context. Just got to iron out the bugs of integrating it with bluebird.
verdier commentedon Jan 14, 2016
@overlookmotel @mickhansen there is absolutely no need to use
promisify-anysincePromiseis the way async functions will work tomorrow. If you want to use generators with today Sequelize, you juste have to do something like that:and tomorrow (has said by @mickhansen):
both of the solutions return a
Promise. Evenkoahas drop generators support in favore ofco.wraporasyncused by the library consumer.MarkMurphy commentedon Jan 15, 2016
I'm surprised no one has mentioned async/await here.
becomes:
have a look here.
mickhansen commentedon Jan 15, 2016
@MarkMurphy It has actually been mentioned :) We're not going with it internally since it would require bluebird-coroutines are we're not sure of the perf implications.
However users are as always welcome to us it, and we might update docs to reflect it.
overlookmotel commentedon Jan 15, 2016
@verdier I just suggested using promisify-any as currently Sequelize hooks can be written either as classic node callback functions OR promise-returning functions. promisify-any takes care of that, so handling callback functions could be removed from the Sequelize codebase.
The additional support for generator co-routines is an extra benefit.
overlookmotel commentedon Jan 15, 2016
@verdier There are also some died-in-the-wool callback devotees who like that style of programming and will probably never change. Seems bonkers to me, but different strokes for different folks... our vision of the future isn't necessarily shared by everyone.
verdier commentedon Jan 15, 2016
Yep, @overlookmotel I agree!
mickhansen commentedon Jan 15, 2016
I say we remove callback support though: #5228
sushantdhiman commentedon Jun 21, 2016
Following is the summary for ES6 adoption in Sequelize codebase
[email protected]BabelorTypeScriptwill be used. We want Sequelize to run directly after git clone without any transpilation overheadtemplate strings,Classandarrow functionsco routinesPrepare for coroutines #6116 , if CLS support is guaranteedDiscussion moved to #5898