You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by Chris Brody <ch...@gmail.com> on 2018/11/30 02:20:09 UTC

[dev] Introduce ES6 classes or not?

I was wondering what our sentiment should be about using ES6 classes?

My own opinion in coming in a response email.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Re: [dev] Introduce ES6 classes or not?

Posted by Shazron <sh...@gmail.com>.
I'm in favor of whatever makes it easier to contribute, and if a
contributor uses classes and it was appropriate (like there could be
more than one instance of it), should be fine
On Sat, Dec 1, 2018 at 12:28 AM GearĂ³id M <de...@gearoid.me> wrote:
>
> I'm definitely in favour of using classes. Personally I find them easier to read and write. We are already using them in at least one place, the ProjectBuilder in cordova-android.[1] This came about from a refactor I did a few months ago, and since we dropped support for Node 6, it made sense to me to use a class. I don't think we need to go refactoring everything, but if there are new features to be added, I would strongly favour using classes in those cases.
>
> [1] https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib/builders/ProjectBuilder.js
>
> On Fri, 30 Nov 2018, at 15:49, Oliver Salzburg wrote:
> > I'm in favor of ES6 classes.
> >
> > But that doesn't mean that everything that _can_ be written with classes
> > should. Pick the right tool for the job.
> >
> > While you can achieve the same object structure by just extending the
> > prototype, classes have the benefit of keeping related code parts close
> > to each other. A class is usually defined in a single `class {}` block.
> > With prototype extensions that is not required and it can be a lot
> > harder to determine how an object is constructed.
> >
> > So, as a language feature, they might not provide any benefits, but from
> > a code point of view, I think there are several. I'd put some of that
> > syntactic sugar in my tea.
> >
> > On 2018-11-30 03:20, Chris Brody wrote:
> > > I was wondering what our sentiment should be about using ES6 classes?
> > >
> > > My own opinion in coming in a response email.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> > > For additional commands, e-mail: dev-help@cordova.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> > For additional commands, e-mail: dev-help@cordova.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> For additional commands, e-mail: dev-help@cordova.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Re: [dev] Introduce ES6 classes or not?

Posted by GearĂ³id M <de...@gearoid.me>.
I'm definitely in favour of using classes. Personally I find them easier to read and write. We are already using them in at least one place, the ProjectBuilder in cordova-android.[1] This came about from a refactor I did a few months ago, and since we dropped support for Node 6, it made sense to me to use a class. I don't think we need to go refactoring everything, but if there are new features to be added, I would strongly favour using classes in those cases.

[1] https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib/builders/ProjectBuilder.js

On Fri, 30 Nov 2018, at 15:49, Oliver Salzburg wrote:
> I'm in favor of ES6 classes.
> 
> But that doesn't mean that everything that _can_ be written with classes 
> should. Pick the right tool for the job.
> 
> While you can achieve the same object structure by just extending the 
> prototype, classes have the benefit of keeping related code parts close 
> to each other. A class is usually defined in a single `class {}` block. 
> With prototype extensions that is not required and it can be a lot 
> harder to determine how an object is constructed.
> 
> So, as a language feature, they might not provide any benefits, but from 
> a code point of view, I think there are several. I'd put some of that 
> syntactic sugar in my tea.
> 
> On 2018-11-30 03:20, Chris Brody wrote:
> > I was wondering what our sentiment should be about using ES6 classes?
> >
> > My own opinion in coming in a response email.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> > For additional commands, e-mail: dev-help@cordova.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> For additional commands, e-mail: dev-help@cordova.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Re: [dev] Introduce ES6 classes or not?

Posted by Oliver Salzburg <ol...@gmail.com>.
I'm in favor of ES6 classes.

But that doesn't mean that everything that _can_ be written with classes 
should. Pick the right tool for the job.

While you can achieve the same object structure by just extending the 
prototype, classes have the benefit of keeping related code parts close 
to each other. A class is usually defined in a single `class {}` block. 
With prototype extensions that is not required and it can be a lot 
harder to determine how an object is constructed.

So, as a language feature, they might not provide any benefits, but from 
a code point of view, I think there are several. I'd put some of that 
syntactic sugar in my tea.

On 2018-11-30 03:20, Chris Brody wrote:
> I was wondering what our sentiment should be about using ES6 classes?
>
> My own opinion in coming in a response email.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> For additional commands, e-mail: dev-help@cordova.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Re: [dev] Introduce ES6 classes or not?

Posted by ra...@gmail.com.
+1 for using modern JS wherever applicable.

Am Fr., 30. Nov. 2018, 06:55 hat Darryl Pogue <dv...@gmail.com>
geschrieben:

> I both agree and disagree with your points :P
>
> To your first point, yes ES6 classes are just syntactic sugar around
> prototypes, but that sugar exists for a reason and it's extremely
> popular now. Personally, I've been using class syntax at work for
> going on three years now, and looking at some parts of the Cordova
> code that are obviously implementing a class pattern with ES5 syntax
> just makes it feel like nobody has touched or dusted off the code
> since the pre-ES6 days. This is the modern style of JavaScript, and I
> find it much easier to glance at a class and see easily which things
> belong to the instance vs the class compared to needing to check
> whether something was declared on the prototype or not. For better or
> worse, there are people coming to JavaScript today who will be much
> more comfortable with ES6 classes than with the ES5 style of
> prototypical declarations, and I think that using ES6 classes makes
> the code clearer, more readable, and more maintainable.
>
> But only where it makes sense to use classes. We should only use
> classes where it makes sense, where we have some sort of instance of
> something and it's encapsulating data and providing methods to
> interact with/manipulate that data.
>
> I definitely feel like the majority of Cordova can and should be set
> up in a functional programming-inspired style, where it's just
> functions that do one task, and they get chained together.
>
>
> On Thu, Nov 29, 2018 at 6:22 PM Chris Brody <ch...@gmail.com> wrote:
> >
> > I would not personally favor using ES6 classes, here are my main reasons:
> > * ES6 class is really sugar around prototypal inheritance, unlike many
> > other languages
> > * In many cases it is better to use functional programming and factory
> > functions than classes
> >
> > Some reading:
> > *
> https://artem.today/what-is-behind-syntactical-sugar-in-es6-classes-6dfa4ab4d6a2
> > *
> https://medium.com/javascript-scene/the-two-pillars-of-javascript-ee6f3281e7f3
> > *
> https://medium.com/javascript-scene/why-composition-is-harder-with-classes-c3e627dcd0aa
> > *
> https://hackernoon.com/favor-object-composition-over-class-inheritance-they-said-9f769659b6e
> > On Thu, Nov 29, 2018 at 9:20 PM Chris Brody <ch...@gmail.com>
> wrote:
> > >
> > > I was wondering what our sentiment should be about using ES6 classes?
> > >
> > > My own opinion in coming in a response email.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> > For additional commands, e-mail: dev-help@cordova.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> For additional commands, e-mail: dev-help@cordova.apache.org
>
>

Re: [dev] Introduce ES6 classes or not?

Posted by Darryl Pogue <dv...@gmail.com>.
I both agree and disagree with your points :P

To your first point, yes ES6 classes are just syntactic sugar around
prototypes, but that sugar exists for a reason and it's extremely
popular now. Personally, I've been using class syntax at work for
going on three years now, and looking at some parts of the Cordova
code that are obviously implementing a class pattern with ES5 syntax
just makes it feel like nobody has touched or dusted off the code
since the pre-ES6 days. This is the modern style of JavaScript, and I
find it much easier to glance at a class and see easily which things
belong to the instance vs the class compared to needing to check
whether something was declared on the prototype or not. For better or
worse, there are people coming to JavaScript today who will be much
more comfortable with ES6 classes than with the ES5 style of
prototypical declarations, and I think that using ES6 classes makes
the code clearer, more readable, and more maintainable.

But only where it makes sense to use classes. We should only use
classes where it makes sense, where we have some sort of instance of
something and it's encapsulating data and providing methods to
interact with/manipulate that data.

I definitely feel like the majority of Cordova can and should be set
up in a functional programming-inspired style, where it's just
functions that do one task, and they get chained together.


On Thu, Nov 29, 2018 at 6:22 PM Chris Brody <ch...@gmail.com> wrote:
>
> I would not personally favor using ES6 classes, here are my main reasons:
> * ES6 class is really sugar around prototypal inheritance, unlike many
> other languages
> * In many cases it is better to use functional programming and factory
> functions than classes
>
> Some reading:
> * https://artem.today/what-is-behind-syntactical-sugar-in-es6-classes-6dfa4ab4d6a2
> * https://medium.com/javascript-scene/the-two-pillars-of-javascript-ee6f3281e7f3
> * https://medium.com/javascript-scene/why-composition-is-harder-with-classes-c3e627dcd0aa
> * https://hackernoon.com/favor-object-composition-over-class-inheritance-they-said-9f769659b6e
> On Thu, Nov 29, 2018 at 9:20 PM Chris Brody <ch...@gmail.com> wrote:
> >
> > I was wondering what our sentiment should be about using ES6 classes?
> >
> > My own opinion in coming in a response email.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
> For additional commands, e-mail: dev-help@cordova.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Re: [dev] Introduce ES6 classes or not?

Posted by Chris Brody <ch...@gmail.com>.
I would not personally favor using ES6 classes, here are my main reasons:
* ES6 class is really sugar around prototypal inheritance, unlike many
other languages
* In many cases it is better to use functional programming and factory
functions than classes

Some reading:
* https://artem.today/what-is-behind-syntactical-sugar-in-es6-classes-6dfa4ab4d6a2
* https://medium.com/javascript-scene/the-two-pillars-of-javascript-ee6f3281e7f3
* https://medium.com/javascript-scene/why-composition-is-harder-with-classes-c3e627dcd0aa
* https://hackernoon.com/favor-object-composition-over-class-inheritance-they-said-9f769659b6e
On Thu, Nov 29, 2018 at 9:20 PM Chris Brody <ch...@gmail.com> wrote:
>
> I was wondering what our sentiment should be about using ES6 classes?
>
> My own opinion in coming in a response email.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org