Vector data type for thread management

V

VK

While working on JSONet project
<http://groups.google.com/group/comp..._frm/thread/f083e3925a345f31/bc987f7013afde92>

I came to the conclusion (possibly wrongly) that Vector data type is
much more convenient than Array or Hashtable to keep threads count.
Major benefits: i) "real" length at any given time, ii) auto
shrink/expand on adding/removing new items. Overall it seems to give as
given a lot of things you have to emulate by multiple pass over
Array/Hashtable elements.

The code below is quick'n'durty version of what I'm thinking to
implement. Is it total b.s.? (the idea, not the code).

Also please note that in this code I used my PGO (Pretty Good
Objecting) coding style which wollows the OOP style and namespace
security while let you relax about the infamous "this" issue.


<html>
<head>
<title>Vector</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">


function VK_VectorAdd(v) {
var i = document.createElement('OPTION');
if (typeof v == 'object') {
i.value = v.id || v.toString();
}
else {
i.value = v;
}
this.$_vector.appendChild(i);
}


function VK_VectorItem(i) {
return this.$_vector.options.value;
}


function VK_VectorRemove(i) {
this.$_vector.options = null;
}


function VK_VectorClear() {
this.$_vector.options.length = 0;
}


function VK_VectorSize() {
return this.$_vector.options.length;
}


function Vector() {
if (!(document.createElement)) {return null;}
this.$_vector = document.createElement('SELECT');
this.add = VK_VectorAdd;
this.item = VK_VectorItem;
this.remove = VK_VectorRemove;
this.clear = VK_VectorClear;
this.size = VK_VectorSize;
}


function demo() {
var v = new Vector();
v.add(1);
v.add('foo');
alert(v.size());
v.remove(0);
alert(v.size());
alert(v.item(0));
}


window.onload = demo;
</script>
</head>

<body>

</body>
</html>
 
R

Richard Cornford

VK wrote:
Also please note that in this code I used my PGO (Pretty
Good Objecting) coding style which wollows the OOP style
LOL

and namespace security while let you relax about the
infamous "this" issue.

You keep banging on about this 'infamous "this" issue' that you
perceive. If you would explain what it is you are talking about someone
may be able to correct whichever of your many misconceptions about
javascript is resulting in you perceiving an issue where there really
isn't one. (Though your tendency to disregard previously given
corrections to some of your legion of misconceptions may put people off
making what may be a pointless effort).

<snip - The worst example of a Vector-like storage object posted to this
group in the last 3 years. More a demonstration of how not to write
javascript than anything else, but not surprisingly so as VK wrote it.>

</html>

Posting examples that are significantly inferior to previous examples
does not represent a contribution to the group, no matter how much the
effort it takes you to create such pedestrian code leaves you with a
personal sense of achievement and pride.

Richard.
 
V

VK

Richard said:

Well, at least I cheared up someone, so the post already was not
completely useless ;-)
You keep banging on about this 'infamous "this" issue' that you
perceive. If you would explain what it is you are talking about someone
may be able to correct whichever of your many misconceptions about
javascript is resulting in you perceiving an issue where there really
isn't one.

That means that "this" doesn't point on what you would expect. That is
a really strange question from someone who's own code samples are full
of:
....
var self = this;
....

Again I would like to stress out that I'm *not* denying at all the
(anonymous){curling} as a way to program in JavaScript. But I'm
questionning if it as the only one acceptable way.
The worst example of a Vector-like storage object posted to this
group in the last 3 years.

Could you collaborate on it? This does what expected with the minimum
coding. A "bad" would be: i) non cross-browser or ii) runtime
instability or iii) productivity impact.
The first was already checked before posting, but ii) and iii) are
still under test.
 
V

VK

John said:
<snip>

Why do you call it a vector when it isn't a vector ?

Because it implements the same "ribbon band" functionality I'm looking
for.
Actually why it's not a vector? Going by Java it's a perfect vector
(lesser of course current features set and usual JavaScript memory
management free benefits/drawbacks). Otherwise it is the same perfect
Vector as say Java's ArrayList.
 
M

Michael Winter

Richard Cornford wrote:
[snip]
You keep banging on about this 'infamous "this" issue' that you
perceive.

Well, there is one issue with the this operator, though it isn't the one
VK is referring to: IE and attachEvent. That's a rather annoying
problem, but manageable. :)

[snip]
That means that "this" doesn't point on what you would expect.

I would be quite amazed if you don't understand how the this operator
value changes predictably. Looking briefly at the archives, I alone have
explained it on at least three separate occasions within the last twelve
months, the most recent of which was thirteen days ago. I'm sure others
have described it during that time, too.

[snip]
Could you collaborate on it?

Collaborate, or elaborate? I assume you mean for Richard to elaborate on
the reasons for his negative opinion.

It uses the most bizarre and obtuse storage method I've ever witnessed,
and it uses it inconsistently and without any obvious benefits. You
choose not to use the prototype object - polluting the global object in
the process - despite that being the most obvious choice if your data is
going to be referenced through a public property (and that, in itself,
is an odd decision). Finally, for now, your 'Vector' destroys data
types, with a rather useless approach to dealing with objects.
This does what expected with the minimum coding.

I should think that wrapping an Array object would require the least
effort, or just /using/ an Array object for that matter. Vectors are,
after all, just growable array-like lists (which is what ECMAScript
already provides).
A "bad" would be: i) non cross-browser [...]

So it /is/ bad then. Since when was the document.createElement method
universally implemented?
The first was already checked before posting [...]

Quite a shoddy job you did, then.

Now, what exactly has this got to do with thread management and,
assuming you're referring to the multitasking kind, why is it even
relevant to Javascript (which exposes no threading mechanisms)?

Mike
 
V

VK

John said:
<snip>

A higher Level of Understanding is needed to know that.

I am terribly sorry but I'm not currently ready to open another class.
My previous student was really hard (though interesting and promising)
case. I promise to keep you in the hold list. For the time being you
can warm up with the self education. Some interesting startup reading
can be found at:
<http://java.sun.com/j2se/1.3/docs/api/java/util/Vector.html>
and
<http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html>

:)
 
R

Richard Cornford

VK said:
I am terribly sorry but I'm not currently ready to open
another class. My previous student was really hard ...
<snip>

Are your tying to be patronising? There is little point as it is
ineffective to patronise people once they already regard you with
contempt. You will just look like an arrogant fool instead of just a
fool.

Richard.
 
R

Richard Cornford

VK said:
Richard Cornford wrote:

That means that "this" doesn't point on what you would
expect.

So your issue is that regardless of the fact that it has been explained
to you in considerable details on numerous occasions you still don't
understand that the value of the - this - keyword is determined always,
and only, by the way in which a function is called, following well
defined rules.

There is no 'infamous "this" issue' outside of the limitations of your
own perception.
That is a really strange question from someone who's own
code samples are full of:
...
var self = this;
...

Using the above expression does not indicate that there is any "issue".
If it was not possible to precisely determine what value - this - has
then it would also not be possible to determine what value - self - has.
Again I would like to stress out that I'm *not* denying at
all the (anonymous){curling} as a way to program in JavaScript.
But I'm questionning if it as the only one acceptable way.
Gibberish!


Could you collaborate on it?
Halfwit.

This does what expected with the minimum coding.

"Does what expected"? What exactly did you expect the - return null; -
statement in your constructor to do? The fact that it is there at all
suggests that whatever it is you are expecting differs considerably from
what it will actually do.
A "bad" would be: i) non cross-browser

It certainly isn't cross-browser, it is barely 'both browsers', and
where it fails it will fail in a wide spectrum of different ways.
or ii) runtime instability

How would you define "runtime instability"? Code that has such a wide
range of uncertain outcomes depending on the environment sounds pretty
unstable to me.
or iii) productivity impact.

Code maintenance has a significant impact upon overall productivity. And
code this bad is going to bring considerable maintenance issues. That
may not change your situation but it would be significant in any
collaborative endeavour, but you would be an absolute liability in any
collaborative endeavour.
The first was already checked before posting,

In how many browsers? Two, three? As previous examples have
demonstrated, implementing this type of object can easily be done with
pure language constructs and so work in any javascript environment,
including non-web browsers.
but ii) and iii) are
still under test.

You have demonstrated negligible skill in testing and analyses so I am
sure your results will act to re-enforce you misplaced confidence.

Richard.
 
V

VK

Richard said:
Are your tying to be patronising?

In the relevant Message-ID:
<[email protected]> there was a
*smily* at the bottom which one still may observe. It renders the
response into a humouristic (I still hope) way to say "I believe I
understand what Vector is. Do you? How about reading Java Sun docs?"
 
J

John G Harris

VK said:
I am terribly sorry but I'm not currently ready to open another class.
My previous student was really hard (though interesting and promising)
case. I promise to keep you in the hold list. For the time being you
can warm up with the self education. Some interesting startup reading
can be found at:
<http://java.sun.com/j2se/1.3/docs/api/java/util/Vector.html>
and
<http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html>

:)

A better reference is
<URL:http://en.wikipedia.org/wiki/Vector>
and in particular
<URL:http://en.wikipedia.org/wiki/Vector_space>

John
 
J

John G Harris

VK said:
It's the geometry meaning of this term, and obviously me and Sun
Microsystems are talking about the programming meaning so what's the
point? :-0

Where on earth do you think programmers got the word vector from ?

Why are you quoting Sun? What have Java's class names got to do with
javascript?

If one says "scope visibility" in this group do you think first about
the microscope resolution?

No, because scope would be written 'scope if it was to do with
microscopes.

John
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top