Named arguments and inheritance

V

VK

Richard said:
And once again you post code without stating what it is supposed to
demonstrate.

The flexibility of JavaScript and its readiness to become an antique
vase, a Picasso sculpture or an ugly pot depending on your hands and
your mind. Whoever gets scared of this flexibility she's better run
away calling mommy (drop stupid JavaScript and use some Real Serious
Language like say PHP, C++, Java etc.)
That is not in relation of anyone's post in this thread, just an
overall statement.
 
V

VK

VK said:
The flexibility of JavaScript and its readiness to become an antique
vase, a Picasso sculpture or an ugly pot depending on your hands and
your mind. Whoever gets scared of this flexibility she's better run
away calling mommy (drop stupid JavaScript and use some Real Serious
Language like say PHP, C++, Java etc.)
That is not in relation of anyone's post in this thread, just an
overall statement.

Just got scared to be taken for a regular who managed to learn one
thing only and now considers that thing as the best one just by the
fact of knowing nothing but that.

I speak freely Perl, classical Java (Swing slang is not my cup of tea),
C, VBA. With some minor translation help I speak C++ and C#.
Loose-typed languages are hugely ineffective in comparison with
strictly typed ones by memory usage and run-time code productivity. At
the same time strictly typed languages with encapsulation are deadly
boring and templated. This is the price they had to pay to be the core
of some extremely complicated systems like say computer OS. JavaScript
did not have to pay this price. From one side: doubtfully we'll ever
see a computer OS written on JavaScript; from the other side: relax and
enjoy, guys :)
 
R

Richard Cornford

VK wrote:
I speak freely Perl, classical Java (Swing slang is not my
cup of tea), C, VBA. With some minor translation help I
speak C++ and C#.
<snip>

There is no point in trying to bullshit us here. We know you are not a
programmer at all, you just aren't rational enough for that.

Richard.
 
R

Richard Cornford

VK said:
The flexibility of JavaScript ...
<snip>

There are no programming languages that are not flexible enough to allow
people to write stupid, inefficient, inept code out of ignorance of what
the code they are writing is doing. Demonstrating you ability to do that
is of no value.

Richard.
 
V

VK

There is no point in trying to bullshit us here. We know you are not a
programmer at all, you just aren't rational enough for that.

There is no point in trying to bullshit us here. We know you did not
make
any real money from your knowledge. You are just too rational for that.

That was harsh actually. W-2 for the last year mutual exchange maybe?
 
V

VK

VK said:
That was harsh actually.

Or did you take
http://message-id.net/<[email protected]>

and in the particular
Just got scared to be taken for a regular who managed to learn one
thing only and now considers that thing as the best one just by the
fact of knowing nothing but that.

as something addressed to you? In such case damn on you Brits: from all
possible sentence interpretations you will always choose the least
expected one (something in common with Germans btw). I meant myself and
my own words: and nothing else.
 
P

Pacific Fox

Dear Richard,

You should really learn some manors, the way you respond is just not
correct, you talk like you know everything. And assume everyone is
stupid. FYI I've been working with JavaScript for over 8 years now,
just getting into trying to make it work like some OOP languages.

Now let me see if maybe VK has been able to help me out, it looks like
he is making more sense..
 
J

John G Harris

Dear Richard,

You should really learn some manors, the way you respond is just not
correct, you talk like you know everything. And assume everyone is
stupid. FYI I've been working with JavaScript for over 8 years now,
just getting into trying to make it work like some OOP languages.

Now let me see if maybe VK has been able to help me out, it looks like
he is making more sense..
<snip>

VK has a habit of saying things that are misleading or plain wrong.
That's what we object to. There are too many confused programmers
already. The world can't afford even more of them.

For instance, there are some nasty traps for the unwary when using
'with'. Did you understand what they are after reading VK's writings on
the subject ?

John
 
M

Matt Kruse

Pacific said:
Dear Richard,
You should really learn some manors, the way you respond is just not
correct, you talk like you know everything. And assume everyone is
stupid.

While Richard does lack social grace and can come across quite abrasively,
he is one of the most technically knowledgeable people in this group. It's
best to read his postings and learn from his technical insights while
ignoring his "know it all" attitude and simply scanning through his more
verbose ramblings.
Now let me see if maybe VK has been able to help me out, it looks like
he is making more sense..

Doubtful. VK posts here a lot, and does so with wild abandon for technical
accuracy. His errors are often corrected, but he continues to spread the
same ignorance repeatedly. I don't think that he can realistically offer any
value to someone asking for assistance here, and more than likely will do
more harm than good.
 
V

VK

John said:
VK has a habit of saying things that are misleading or plain wrong.
That's what we object to. There are too many confused programmers
already. The world can't afford even more of them.

So has to leave among two of us? :) - just kidding...

Truthfully I don't see how my original post could help to OP. I was
going strictly by his original post and I was too concentrated on
private vars and their retrieval in his samples. So I thought he wanted
to implement some kind of inheritable private properties factory.

Later I found his additional post stating:
Whatever you want to call it, however you want to see it, it allows to
me to call functions without having to specify every parameter, i.e.
someMethod( "some value", null, null, null, null, null, null, null,
null, null, "and another value" )

So if I get it right this time, private scope methods were irrelevant
to the case and they just were used as "Lorem ipsum" in the sample. If
OP simply wanted to implement VB-like named arguments, it can be done
right in the constructor w/o any extra functions:

<script type="text/javascript">
function MyObject() {
var i;
var p;
for (i=0; i<arguments.length; ++i) {
for (p in arguments) {
this[p] = arguments[p];
}
}
}

var obj1 = new MyObject({'foo':'bar'});
var obj2 = new MyObject({'foo':'bar'},{'bar':'foo'});
alert(obj1.foo);
alert(obj2.bar);
</script>
 
V

VK

VK said:
So if I get it right this time, private scope methods were irrelevant
to the case and they just were used as "Lorem ipsum" in the sample. If
OP simply wanted to implement VB-like named arguments, it can be done
right in the constructor w/o any extra functions:
<snip code>

It can be even further adjusted so it would use provided named
arguments and default values for missing arguments. That gets a bit
consuming but it's a regular price to pay: lesser thinking for a user -
more thinking for the engine :)

<script type="text/javascript">

function MyObject() {
var DEFAULT = {
'prop1' : 1
, 'prop2' : 2
, 'prop3' : 3
};

var i;
var p;
for (i=0; i<arguments.length; ++i) {
// only for objects
if (typeof arguments == 'object') {
for (p in arguments) {
// one name : one value
this[p] = arguments[p]; break;
}
}
}
for (p in DEFAULT) {
// default values for missing arguments
if (!(p in this)) {
this[p] = DEFAULT[p];
}
}
}

var obj = new MyObject({'prop2':'foo'},{'prop3':'bar'});

alert(obj.prop1); // 1
alert(obj.prop2); // foo
alert(obj.prop3); // bar
</script>
 
R

Richard Cornford

VK said:
<snip code>

I see your analysis is up to its usual standard. The OP's question was
about an error produced by trying to call a constructor that required an
object as its argument (because it was interacting which that object
without verifying its existence) without an object as its argument.

That questions has substantially been answered because the various
solutions are: verifying that an object was passed as an argument prior
to treating it as one, or: never calling the constructor without an
object as its argument (and in the case of the posted code not calling
the constructor without an object as its argument by not calling the
constructor to assign a value to another constructor's prototype from
within that second constructor as doing so would not have the desired
result at all if inheritance from the prototype was desired, is
needlessly inefficient and was worthless in this case a no properties of
the resulting object existed that would not be masked by properties
assigned directly to the object).

What you are posting here is irrelevant (though that is normal for you),
and it represents a very dubious notion in the context of implementing
class-style inheritance in javascript as it means that the properties of
the resulting object (rather than just the values of those properties)
depend directly on the arguments passed to the constructor. The result
is a constructor that does not create objects of any single 'type' or
'class' (as conceptually objects of a single class will have the same
properties and methods and just their values will vary between
instances), but instead create an object who's 'class' depends on the
arguments used.
It can be even further adjusted so it would use provided
named arguments and default values for missing arguments.
That gets a bit consuming but it's a regular price to pay:
lesser thinking for a user - more thinking for the engine :)

One of the consequences of your not comprehending the role of prototypes
in javascript (as was manifest in your bizarre assertion that using
the - new - operator on a constructor and assigning to that
constructor's prototype in the same code was like "trying to speak
French and German at once") is that it leaves you writing the most
phenomenally stupid code:-
<script type="text/javascript">

function MyObject() {
var DEFAULT = {
'prop1' : 1
, 'prop2' : 2
, 'prop3' : 3
};

You realise that that the evaluation of this object literal will result
in the creation of a new, and unique, object with each execution of this
constructor, when each of those objects has the same properties with the
same values? Any strategy that only required one instance of this object
to be created would be superior, and understanding the role of
prototypes in javascript would have allowed you to see a very obvious
strategy for achieving that.
var i;
var p;
for (i=0; i<arguments.length; ++i) {
// only for objects
if (typeof arguments == 'object') {
for (p in arguments) {
// one name : one value
this[p] = arguments[p]; break;


Why the break here? Doesn't that mean that each object that appears in
the argument's list can only contribute a single named property, and so
that a distinct object would be needed to pass each and every named
property to the object? It is bad enough to be creating a new object for
each function call, but not letting a single object contribute multiple
named arguments really is daft.

Though passing multiple objects with multiple properties highlights the
issue of whether properties of a later object should be replacing
properties provided on earlier ones, or vica verca. But even if each
argument object can only contribute the first of its properties
enumerated (enumeration sequences is not guaranteed to be consistent in
javascript, either within the same implementation or across
implementations) there is still a possibility that more than one object
may attempt to contribute a value for the same property of the object
being constructed.
}
}
}
for (p in DEFAULT) {
// default values for missing arguments
if (!(p in this)) {
this[p] = DEFAULT[p];
}
}
}

var obj = new MyObject({'prop2':'foo'},{'prop3':'bar'});

alert(obj.prop1); // 1
alert(obj.prop2); // foo
alert(obj.prop3); // bar
</script>

Apart from allowing constructed object instances to share single
instances of function objects as their methods, prototype inheritance
allows for the defaulting of the values of the properties of constructed
objects. This works because, when a property name is resolved against an
object, if the object has a property of the given name itself it is the
value of that property that is the result, but when the object does not
have the property its prototype chain is examined and the value of the
first property on the prototype chain with the corresponding property is
the result (else it is undefined if no objects on the chain have the
named property).

In the same way as all instances of an object share the instances of
function objects on their prototypes they also share the vales of the
other named properties on their prototypes. This becomes the
standard/natural method of defaulting the vales of object properties in
javascript, and is considerably more efficient than the stupid strategy
you use above as it is achieved passively rather than by actively
enumerating the properties of an object and then testing the results:-

function AnObject() {
var i, p, a, len = arguments.length;
for(i = 0;i < len;++i){
if(typeof (a = arguments) == 'object'){
for (p in a) {
this[p] = a[p];
}
}
}
}
/* With:- */
AnObject.prototype = {
prop1:1,
prop2:2,
prop3:3
};
/* OR:-

AnObject.prototype.prop1 = 1;
AnObject.prototype.prop2 = 2;
AnObject.prototype.prop3 = 3;

- depending on whether the value of the prototype's -
constructor - property is needed to remain a reference
to - AnObject -(which generally does not matter).
*/

var obj = new AnObject({'prop2':'foo'},{'prop3':'bar'});

alert('obj.prop1 = '+obj.prop1);
alert('obj.prop2 = '+obj.prop2);
alert('obj.prop3 = '+obj.prop3);

So that is the same outcome with about half the code and no creating of
a new 'defaulting' object with each execution of the constructor and no
need to loop through the properties of that object in the constructor
either. The arguments either contribute a value that is assigned to a
property of the object itself (masking any default value on the
prototype under the same property name) or it does not and any values
already set on the prototype act as the defaults.

You may assert that javascript is flexible enough to let you get away
with stupid implementations, but knowing how javascript works gives you
the opportunity to do things well, and save much time writing pointless
code along the way.

Richard.
 
V

VK

Richard said:
I see your analysis is up to its usual standard. The OP's question was
about an error produced by trying to call a constructor that required an
object as its argument (because it was interacting which that object
without verifying its existence) without an object as its argument.

Until OP explains *what exactly* his aim was (if he still kept any
desire to discuss his problems on c.l.j. :) I consider futile to keep
guessing.
 
G

Gary Stephenson

Has anyone ever seen Richard Cornford and VK in the same room together?

My thesis is that they are one and the same person, and VK is just an alter
ego that Richard invented as a endless source of stupidities in need of
correction. Or perhaps Richard has a true split personality and doesn't
even _know_ that VK is in fact an alter ego ...

In any case, I will definitely rue the day when one or other of these two
stop posting (although I only ever actually read Richard's posts) as I
suspect my learning curve will flatten out considerably as a result.

<0.5wink>'ly yrs,

gary

http://www.oxide.net.au
 
V

VK

Gary said:
In any case, I will definitely rue the day when one or other of these two
stop posting (although I only ever actually read Richard's posts) as I
suspect my learning curve will flatten out considerably as a result.

In such case did you consider to move on reading another newsgroup more
suitable to your learning curve? The Usenet is very big and no one will
get upset (nor notice) if you leave.

If you have a question but you are interested in answer from only one
(two, three) person(s) you know by names then the Usenet is not really
a suitable media for that. Personal e-mail (mailing list) or blog
comments are the right tools for that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top