Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 04 19:02

    RIAEvangelist on master

    ignoring coverage for language … (compare)

  • Jul 04 02:07
    RIAEvangelist commented #2
  • Jul 03 15:05
    abhyuday-tripathi commented #2
  • Jul 03 04:26
    rishabhkeshan commented #2
  • Jul 02 20:56
    RIAEvangelist commented #2
  • Jul 02 17:59
    gems2000 commented #2
  • Jul 02 17:56
    bucharitesh commented #2
  • Jul 02 15:37
    RIAEvangelist commented #120
  • Jul 02 15:34
    RIAEvangelist commented #118
  • Jul 02 15:34
    RIAEvangelist commented #118
  • Jul 02 15:33
    RIAEvangelist commented #120
  • Jul 02 14:50
    RIAEvangelist commented #2
  • Jun 23 23:21
    RIAEvangelist commented #2
  • Jun 23 11:56
    rishabhkeshan commented #2
  • Jun 18 22:09
    RIAEvangelist commented #2
  • Jun 18 22:08
    RIAEvangelist commented #2
  • Jun 18 21:46
    bucharitesh commented #2
  • May 30 14:50
    mattcroat edited #120
  • May 30 14:46
    mattcroat opened #120
  • May 26 14:17
    madelinecameron commented #114
Brandon Nozaki Miller
@RIAEvangelist
That cool with you?
Madeline Cameron
@madelinecameron
Besides not using prototype.
Uhh, I hope this isn't a dumb question but isn't prototype + function basically oop. I looked in 'oop javascript' and prototypes seemed like the way to go. What I am asking is what will be the difference?
And my message is going to be weirdly ordered, I think.
Yeppp
'function'
Brandon Nozaki Miller
@RIAEvangelist
I'm not a big fan of prototype, its only one way to do oop, but it can obfuscate the shit out of stuff for jr devs. especially with inheritance.
I'll just do one Class and then we can discuss
I'll do it in one commit so if you don't like it we can revert.
Madeline Cameron
@madelinecameron
Yeah definitely. I am interested. I wasn't entirely aware that Javascript had inheritance. I was under the impression that Javascript was sort of faux oop. That a lot of traditional oop things weren't actually present in Javascript.
Brandon Nozaki Miller
@RIAEvangelist
Pretty much thats correct. Primary reason for doing this is that the way the prototypical objects are set up now is fucking with the scope of 'this'
Madeline Cameron
@madelinecameron
Ahh okay. Yeah, change away. I am interested to see if it can make things a bit more sane, especially as additional features get added.
Brandon Nozaki Miller
@RIAEvangelist
Pretty sane, though I don't know many other devs who have gone this route. I LOVE it. it defines stuff clearly.
Madeline Cameron
@madelinecameron
oop in general or the new method we might change to?
Brandon Nozaki Miller
@RIAEvangelist
new method
Madeline Cameron
@madelinecameron
Oh okay
Brandon Nozaki Miller
@RIAEvangelist
K if you do a git pull on the PI branch you will see the new Address Class.
Tell me what you think.
I feel it makes the Class very transparent right off the bat for anytone who looks at it.
They know what they can edit, use etc.
also, if they use this in the browser or say nw.js, it makes the console, very clear.
Everything is now passing accept Price
Madeline Cameron
@madelinecameron

Yeah, that is the one I am having trouble with as well. The build I have for PizzaGiver is still working so that's why I haven't updated the module since something broke between then and now.

I am thinking it might be a difference on Domino's side but I haven't been able to spot anything different.

Madeline Cameron
@madelinecameron
I looked at the new Address and I don't think this makes it make more sense for less experienced dev. I notice that there is an init function now which is quite nice but personally I don't think it makes the code clearer or is there a performance / other boost that this technique benefits from. I don't mean to be rude, just wondering.
Also, I was under the impression enumerable meant iterable (basically) so I am kind of lost on what that does. I can't find any references for that on Google.
Brandon Nozaki Miller
@RIAEvangelist

Primary benefits are that all Class methods are defined up front in a single location, made writable or not, enumerable or not, all share the same scope, and have somewhat private features. Biggest thing is easily maintained scope.

Also, I suppose it stands to say that defining like this is as close to an oop class as you can get, while prototype is well, prototypical. You can extend a single child, or all future children this way without having cowboy coding.

Prototype gets a lot of jr devs in trouble hiding, mutating and confusing objects and methods in complex situations.

Thern again, that's just my experience.
I havent looked at the pricing yet, only Address incase you were working on any of the others.
Once Harmony is officially supported should be easy to port over to the new ECMA Script 6 Class too
Brandon Nozaki Miller
@RIAEvangelist
Also gives control over enumerable methods etc. for lik for in loops Object.keys etc.
Brandon Nozaki Miller
@RIAEvangelist
Also, I was thinking maybe we should make the delivery method a var instead of always needing to pass a string. What do you think? This way users don't have to worry about capitalization etc? not sure if it makes a difference though.
Brandon Nozaki Miller
@RIAEvangelist

was curious about performance so I ran a test. Seems that over thousands of iterations the Object.define is always just slightly faster, like so minimally it may as well be no difference slightly.

console.time('prototype');
var objects=[];

var MyClass=function(paramaters){
    this.ID=paramaters.ID
}

MyClass.prototype.getInfo=function(callback) {
    if( !this.ID || !callback){
        if(callback)
            callback(
                {
                    success: false,
                    message: 'A callback is required to get store info'
                }
            );
        return;
    }
    callback(
        {
            success: true,
            message: this.ID
        }
    );
}

for(var i=0;i<2000;i++){
    objects.push(new MyClass({ID:i+1}));
    var current=objects[objects.length-1];
    for(var j=0; j<5000; j++){
        current.getInfo(
            function(data){
                if(!data.success){console.log(data)}
            }
        )
    }
}

objects=[];

console.timeEnd('prototype');

//case sensitive differences

console.time('class');
var oBjects=[];

function Myclass(paramaters){
    Object.defineProperties(
        this,
        {
            ID:{
                value:paramaters.ID
            },
            getInfo:{
                value:getInfo
            }
        }
    );

    function getInfo(callback){
        if( !this.ID || !callback){
            if(callback)
                callback(
                    {
                        success: false,
                        message: 'A callback is required to get store info'
                    }
                );
            return;
        }
        callback(
            {
                success: true,
                message: this.ID
            }
        ); 
    }
}

for(var i=0;i<2000;i++){
    oBjects.push(new Myclass({ID:i+1}));
    var current=oBjects[oBjects.length-1];
    for(var j=0; j<5000; j++){
        current.getInfo(
            function(data){
                if(!data.success){console.log(data)}
            }
        )
    }
}

oBjects=[];

console.timeEnd('class');

I ran it several times to check.

VM122:43 prototype: 7084.202ms
VM122:97 class: 6936.807ms

VM123:43 prototype: 7205.583ms
VM123:97 class: 7152.946ms

VM125:43 prototype: 7193.067ms
VM125:97 class: 7158.549ms

VM127:43 prototype: 7342.147ms
VM127:97 class: 7233.754ms

VM126:42 prototype: 7185.525ms
VM126:96 class: 7164.016ms

When I removed the calls to methods, and ONLY initialized the Class and prototype, prototype was faster.

console.time('prototype');
var objects=[];

var MyClass=function(paramaters){
    this.ID=paramaters.ID
}

MyClass.prototype.getInfo=function(callback) {
    if( !this.ID || !callback){
        if(callback)
            callback(
                {
                    success: false,
                    message: 'A callback is required to get store info'
                }
            );
        return;
    }
    callback(
        {
            success: true,
            message: this.ID
        }
    );
}

for(var i=0;i<2000;i++){
    objects.push(new MyClass({ID:i+1}));

}

objects=[];

console.timeEnd('prototype');

//case sensitive differences

console.time('class');
var oBjects=[];

function Myclass(paramaters){
    Object.defineProperties(
        this,
        {
            ID:{
                value:paramaters.ID
            },
            getInfo:{
                value:getInfo
            }
        }
    );

    function getInfo(callback){
        if( !this.ID || !callback){
            if(callback)
                callback(
                    {
                        success: false,
                        message: 'A callback is required to get store info'
                    }
                );
            return;
        }
        callback(
            {
                success: true,
                message: this.ID
            }
        ); 
    }
}

for(var i=0;i<2000;i++){
    oBjects.push(new Myclass({ID:i+1}));

}

oBjects=[];

console.timeEnd('class');

VM143:35 prototype: 8.667ms
VM143:82 class: 10.209ms

VM358:35 prototype: 6.140ms
VM358:82 class: 18.715ms

VM361:35 prototype: 3.849ms
VM361:82 class: 9.515ms

But I think the more important thing is when calling the identical methods.

After all, the point is to use the things, not just create them :smile:

Brandon Nozaki Miller
@RIAEvangelist

Even when I reduced the method calls from 5000 to just 500 per object it seems to show the same trend. Basically negligible still.

prototype: 723.964ms
VM58:96 class: 712.170ms

VM63:42 prototype: 711.407ms
VM63:96 class: 700.059ms

VM64:42 prototype: 727.078ms
VM64:96 class: 712.857ms

Madeline Cameron
@madelinecameron

Yeah, I knew that prototype tends to outperform other methods. Wasn't sure if they would be negligible differences (I couldn't have imagined that the new method would not perform as well as prototypes, just wasn't sure if it would outperform prototype).

And I do agree it is nice that all of the functions are declared outright first so at least it lays out a map a bit. I do still contest it is a little intimidating but I am sure that's just me. Did you mention ES6 moves closer to this kind of thinking rather than valuing / teaching prototypes over all.

And the delivery method var is something I had added but it is an easy change so I agree. :)

Also, your comment about prototypes messing with the object and not making it behave correctly, I haven't tested it correctly but if my thinking is correct, this new method could solve an issue with Validate and Price. As it stands currently, if you want to run validate and then update the object, you have to init a new Order object which is craziness. I assume your mention of cowboy coding with prototypes is a response to the ever lovely Order 'initializor' and the insanity of the entire Order object. ;) I will admit that has grown out of control and will take my lumps for it, haha.

Ugh. That last paragraph got jumbled. Basically if you want to run validate and then run purchase, you have to init a new Object variable because prototypes can't modify it's own object (Which I assume is what you were meaning by prototypes messing with this and other scoping issues)
price, not purchase D:
Brandon Nozaki Miller
@RIAEvangelist
:D
hey I just got back, was competing at Pikes Peak International Hill Climb.
Glad to see all the tests are working now. Looks like we don't have too much to do to get v1.0.0 out the door. woot!
race photo
Brandon Nozaki Miller
@RIAEvangelist
took third
Madeline Cameron
@madelinecameron
Oh cool, looks fun!
Brandon Nozaki Miller
@RIAEvangelist
Yeah most dangerous race in America. Sadly another person died this year.
Just finished up with the media stuff for it so I'll be back to work on this now.
Madeline Cameron
@madelinecameron
Oh my gosh D: That totally sucks.
Awesome, I haven't worked a bunch on it. I only fixed that one bug, writing a few more tests and then working on the menu mapping feature.