By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,367 Members | 946 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,367 IT Pros & Developers. It's quick & easy.

Vector data type for thread management

P: n/a
VK
While working on JSONet project
<http://groups.google.com/group/comp.lang.javascript/browse_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[i].value;
}
function VK_VectorRemove(i) {
this.$_vector.options[i] = 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>

Jan 14 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a
VK wrote:
<snip>
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).
<html>


<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.
Jan 15 '06 #2

P: n/a
VK

Richard Cornford wrote:
LOL
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.

Jan 15 '06 #3

P: n/a
In article <11*********************@o13g2000cwo.googlegroups. com>, VK
<sc**********@yahoo.com> writes
While working on JSONet project
<http://groups.google.com/group/comp....se_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.

<snip>

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

John
--
John Harris
Jan 15 '06 #4

P: n/a
VK

John G Harris wrote:
In article <11*********************@o13g2000cwo.googlegroups. com>, VK
<sc**********@yahoo.com> writes
While working on JSONet project
<http://groups.google.com/group/comp....se_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.

<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.

Jan 15 '06 #5

P: n/a
On 15/01/2006 16:32, VK wrote:
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]
The worst example of a Vector-like storage object posted to this
group in the last 3 years.


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

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 15 '06 #6

P: n/a
In article <11**********************@g43g2000cwa.googlegroups .com>, VK
<sc**********@yahoo.com> writes

<snip>
Actually why it's not a vector?

<snip>

A higher Level of Understanding is needed to know that.

John
--
John Harris
Jan 16 '06 #7

P: n/a
VK

John G Harris wrote:
<snip>
Actually why it's not a vector?

<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>

:-)

Jan 16 '06 #8

P: n/a
VK wrote:
John G Harris wrote:
<snip>
>Actually why it's not a vector?

<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 ...

<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.
Jan 16 '06 #9

P: n/a
VK wrote:
Richard Cornford wrote: <snip>
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.


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!
The worst example of a Vector-like storage object posted to
this group in the last 3 years.


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.
Jan 17 '06 #10

P: n/a
VK

Richard Cornford wrote:
Are your tying to be patronising?


In the relevant Message-ID:
<11*********************@f14g2000cwb.googlegroups. com> 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?"

Jan 17 '06 #11

P: n/a
In article <11*********************@f14g2000cwb.googlegroups. com>, VK
<sc**********@yahoo.com> writes

John G Harris wrote:
<snip>
>Actually why it's not a vector?

<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>

:-)


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

John
--
John Harris
Jan 17 '06 #12

P: n/a
VK

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


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

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

Jan 17 '06 #13

P: n/a
In article <11**********************@g47g2000cwa.googlegroups .com>, VK
<sc**********@yahoo.com> writes

John G Harris wrote:
A better reference is
<URL:http://en.wikipedia.org/wiki/Vector>
and in particular
<URL:http://en.wikipedia.org/wiki/Vector_space>
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
--
John Harris
Jan 18 '06 #14

P: n/a
JRS: In article <fP**************@jgharris.demon.co.uk>, dated Wed, 18
Jan 2006 20:49:28 remote, seen in news:comp.lang.javascript, John G
Harris <jo**@nospam.demon.co.uk> posted :

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


Never presume literacy, Dutch and Danes excepted.

--
John Stockton, Surrey, UK. *@merlyn.demon.co.uk / ??*********@physics.org
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Correct <= 4-line sig. separator as above, a line precisely "-- " (SoRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)
Jan 19 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.