On Dec 25, 6:36 pm, fernando trasvina <[email protected]> wrote:
[...]
> so you always check your types in your factories?
> and always check for the interface on your apis?
> is this efficient?

I always typecheck the arguments passed to functions:

function sq(x){
    if(typeof x != "number")
        throw new Error("Invalid argument, number expected.");
    return x * x;
}

> so the draw method should draw anything that complies with the interface?

My point to Garret was that even if the proper method names were
present, it would not necessarily mean that they are appropriate
implementations. Checking for the existence of a field/method is not
enough and that it is more robust to enforce the categorization of the
objects by their inheritance relationships:

function draw(s){
    if(!(s instanceof Shape))
        throw new Error("Shape expected");
    //call methods of the Shape instance
}

> how many mutations of objects do you have that could not be written as 
> extensions or objects?

The point is to develop code so that it won't matter. If you build a
code base large enough that it won;t all fit in your head, or if you
expose it to the world to use it is important to enforce certain rules
and not fly by the seat of your pants.

> is this mutations so big to check the interface every time (this will mean 
> that you don't even know how your code is behaving to check the api of the 
> object)?

using the instanceof operator is much faster than manually checking
individual methods for their existence.

> how about check for drawable type.

if(element instanceof Drawable) ...

> do you really code like you code in the emails? or can you send a real code 
> when the examples you provide are necessary?

Do I code with contrived examples? Of course not, but I don't have the
patience necessary to compress and present the semantics of a problem
in a syntactic way that is consumable by an unknown number of people
of varying levels of ability.

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to