473,769 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Vector data type (2nd attempt)

VK
A while ago I wrote a "Vector data type" script
using DOM interface to select.options.
That was a (beautiful) mind game :-) rather than
a practical thing to use.

Here is another attempt open for criticism, this
time dead serious. I really need an effective
Vector emulator for a project (as much effective
as something not implemeted in language but
emulated by means of the language itself is: a
productivity impact is imminent, the question
is to minimize it).
<html>
<head>
<title>Vector constructor</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script>
function Vector(arr) {
this.$_$ = arr || new Array();
this.length = this.$_$.length ;
this.add = Vector.$add;
this.remove = Vector.$remove;
this.toString = Vector.$toStrin g;
}

Vector.$add = function(m,i) {
if (('number'!=typ eof(i))||(i<0)| |(i>=this.$_$.l ength)) {
this.$_$.push(m );
}
else {
var tmp = [m];
tmp.push(this.$ _$[i]);
this.$_$.splice (i,1,tmp);
}
this.length = this.$_$.length ;
}

Vector.$remove = function(i) {
var ret = this.$_$.splice (i,1)[0];
this.length = this.$_$.length ;
return ret;
}

Vector.$toStrin g = function() {
return this.$_$.toStri ng();
}

// Create new vector and use it as a wrapper
// over Array argument:
var v = new Vector([1,2,3]);

// add(newElement, atPosition) method
// if no atPosition provided, newElement will
// be added to the top
v.add(4); // add 4 to the top

// Add 3.5 atPosition 3
// The element currently located at v[3] and all elements atop
// of it will be moved one position up
v.add(3.5, 3);

// remove(atPositi on) method
// Elements currently located atop of it will be moved
// one position down
v.remove(1);

// toString method is overloaded so in string
// context it gives comma-separated vector values
alert(v); //1, 3, 3.5, 4
</script>
</head>

<body>

</body>
</html>

Sep 13 '06 #1
28 1952
VK wrote:
A while ago I wrote a "Vector data type" script
using DOM interface to select.options.
That would be the one that eared the accolade: "It uses the most bizarre
and obtuse storage method I've ever witnessed, and it uses it
inconsistently and without any obvious benefits.".
That was a (beautiful) mind game :-)
That would be very much in the eye of the beholder.
rather than a practical thing to use.
No arguments there.
Here is another attempt open for criticism,
It is a trivial script to write and you failed anyway.
this time dead serious.
God help the people who pay you to write scripts for them.
I really need an effective
Vector emulator for a project
Given that what you have implemented (if it worked) would be no more
than a wrapper around an array "really need" seems excessive.
>(as much effective
as something not implemeted in language but
emulated by means of the language itself is: a
productivity impact is imminent, the question
is to minimize it).
When you write "productivi ty" you mean performance (or at lest everyone
else would, what you may mean is another matter). It may be an idea to
write something that works properly first and not let yourself be fooled
into thinking you have achieved something by superficial appearances.
>
<html>
<snip>
alert(v); //1, 3, 3.5, 4
</script>
<snip>

Feeling proud of yourself? Try inserting:-

Array.prototype .toString = function(){
return '['+this.join(', ')+']';
};

- at the beginning of the page as see if you can work out how you f****d
up this time.

Though having demonstrated that you cannot write something as simple as
this and get it right first time I think you should give up all pretence
of being anything like a competent programmer.

Richard.
Sep 13 '06 #2

VK wrote:
<script>
Why aren't you using the type attribute? For as long as you have been
here in the group, you would know most would say something about this.
However, let's not talk about validity since it has been discussed so
many times.
function Vector(arr) {
this.$_$ = arr || new Array();
this.length = this.$_$.length ;
this.add = Vector.$add;
this.remove = Vector.$remove;
this.toString = Vector.$toStrin g;
}
I don't understand your use for the '$' symbols to be used as
identifiers. Just from quick skimming of your project makes it look
like a potential maintenance nightmare.
Vector.$add = function(m,i) {
[snip]

Unless it's just for your own personal educational project, I couldn't
really recommend it to anyone as it doesn't really do anything new that
I can do with just Array itself. It seems you are adding an
unnecessary layer (wrapper) to make things more complicated.

Sep 13 '06 #3
VK wrote:
I really need an effective
Vector emulator for a project
I assume you are trying to emulate Java's Vector.
Seeing as how a Vector is synchronized, and javascript is not
multi-threaded, why would you event want to emulate a Vector?
(hint: you don't)

All you really want is an interface to the Array object that you find more
familiar. This wasn't obvious to you, seeing as how you're just messing
around with an internally-held Array?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 13 '06 #4
Ray
VK wrote:
Here is another attempt open for criticism, this
time dead serious. I really need an effective
Vector emulator for a project (as much effective
as something not implemeted in language but
emulated by means of the language itself is: a
productivity impact is imminent, the question
is to minimize it).
<snip>

As a long time Java programmer and newbie in JavaScript--I wonder--what
kind of value does your Vector add on top of JavaScript's existing
Array? Vector was created in Java because Java's Array is nowhere as
flexible as JavaScript's. Not so with JS's Array.

The methods exposed by your Vector class don't add value to what one
does with JS Array--if you think I'm wrong, I'll be glad to be
corrected.

(and what is with the $add and stuff? They're weird.)

Sep 14 '06 #5
Ray said the following on 9/14/2006 12:56 AM:
VK wrote:
>Here is another attempt open for criticism, this
time dead serious. I really need an effective
Vector emulator for a project (as much effective
as something not implemeted in language but
emulated by means of the language itself is: a
productivity impact is imminent, the question
is to minimize it).
<snip>

As a long time Java programmer and newbie in JavaScript--I wonder--what
kind of value does your Vector add on top of JavaScript's existing
Array?
None.

Vector was created in Java because Java's Array is nowhere as
flexible as JavaScript's. Not so with JS's Array.

The methods exposed by your Vector class don't add value to what one
does with JS Array--if you think I'm wrong, I'll be glad to be
corrected.
You aren't wrong.
(and what is with the $add and stuff? They're weird.)
Figments of VK's imagination where he thinks that adds something to his
convoluted code.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 14 '06 #6
Ray wrote:
VK wrote:
Here is another attempt open for criticism, this
time dead serious. I really need an effective
Vector emulator for a project (as much effective
as something not implemeted in language but
emulated by means of the language itself is: a
productivity impact is imminent, the question
is to minimize it).
<snip>

As a long time Java programmer and newbie in JavaScript--I wonder--what
kind of value does your Vector add on top of JavaScript's existing
Array? Vector was created in Java because Java's Array is nowhere as
flexible as JavaScript's. Not so with JS's Array.

The methods exposed by your Vector class don't add value to what one
does with JS Array--if you think I'm wrong, I'll be glad to be
corrected.

(and what is with the $add and stuff? They're weird.)
Consider that when he posted the code here VK could be guaranteed to be
subject to criticism for any technical faults it may have. Most people,
under similar circumstances, would post the very best code they could
write and seriously verify that it worked properly. That would then
only leave questions of style, efficiency, clarity etc. But what VK
posted doesn't actually work at all, and his testing did not expose
that (which doesn't stop it from being the best he is capable of). The
reason for that is simply that VK does not understand the code he
writes himself and so cannot tell what it is supposed to do or identify
what it actually is dong.

The result of this is that there is no point in asking for him to
explain or justify anything he does because when he doesn't know what
he is doing he cannot know why he is doing it.

However, VK has demonstrated a tendency to gravitate towards the worst
available approach to everything he does (some sort of unconscious
imperative), which is what you observer here.

Richard.

Sep 14 '06 #7
VK

Matt Kruse wrote:
VK wrote:
I really need an effective
Vector emulator for a project

I assume you are trying to emulate Java's Vector.
Seeing as how a Vector is synchronized, and javascript is not
multi-threaded, why would you event want to emulate a Vector?
That is the perception of the reality you've been taught a couple of
years ago while starting to learn JavaScript out of c.l.j. ("whatever
is not documented is not necessary and most probably wrong") As I felt
myself not in full power to comment on your educational process, I have
only to admit that it is fully whithin the expected frame of a clj'ed
person (with a nuked demand to do anything above the allowed borders).
>why would you event want to emulate a Vector?
Because outside of the no-threads JavaScript environment there is a
whole new world they thaugt you to be not existing.
Or, as practical as it is: I need for my project an array to add/remove
some references while having an exact number of involved objects and
while avoiding any "gaps" in the continuum: so Vector seems as the best
solution - but possibly not.

Sep 14 '06 #8
VK

Ray wrote:
As a long time Java programmer and newbie in JavaScript--I wonder--what
kind of value does your Vector add on top of JavaScript's existing
Array?
var arr = [0,1,2,3];

delete arr[1];

for (var i=0; i<arr.length; ++i) {
alert(arr[i]);
}

So what kind of functionality is missng? An ability to add/remove w/o
overriding or creating gaps in the involved array. I thought it was it
was pretty obvious, but it could be a mistake (the simplicity).

Sep 14 '06 #9
VK wrote:
Matt Kruse wrote:
VK wrote:
I really need an effective
Vector emulator for a project
I assume you are trying to emulate Java's Vector.
Seeing as how a Vector is synchronized, and javascript is not
multi-threaded, why would you event want to emulate a Vector?

That is the perception of the reality you've been taught a couple of
years ago while starting to learn JavaScript out of c.l.j. ("whatever
is not documented is not necessary and most probably wrong")
Halfwit.
As I felt myself not in full power to comment on your educational
process, I have only to admit that it is fully whithin the expected
frame of a clj'ed person (with a nuked demand to do anything
above the allowed borders).
Are you ' doing something above the allowed borders'? Is that what you
call writing code that doesn't actually work while not being aware that
it doesn't work?

All claims form you of 'I will ignore all advice because what I do is
practical' sounds pretty hollow posted below a demonstration that your
best effort doesn't produce code that works, and you cannot see that it
doesn't work.

Do you think Matt, or any that point out your faults on such a regular
basis, would have failed so completely at such a trivial task?
>>why would you event want to emulate a Vector?
Because outside of the no-threads JavaScript environment there
is a whole new world they thaugt you to be not existing.
This would be the fantasy world of VKScript then, where 'real
programmers' cannot even tell when the code they write does not do
anything close to what it is intended to do?
Or, as practical as it is:
LOL
I need for my project an array to add/remove some references
while having an exact number of involved objects and while
avoiding any "gaps" in the continuum: so Vector seems as
the best solution - but possibly not.
Oh dear, you need something that you cannot write yourself. Perhaps you
had better go out and hire a programmer.

Richard.

Sep 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2270
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3 items from the database. I then get a count of the return, which correctly tells me that I've got 3 items. I then go into a for loop which I expect to loop 3 times and print out the 3 items. Here is where things get strange: it loops 3 times and...
0
1367
by: Row | last post by:
HI, I would first like to say its been about 3 years since looking at java im very rusty! I have to write a post it notes type applet which will function online. (reading from a flat text file) My main problem is: getting each paragraph into my vector array - so that each paragraph sits in a new array element. Eg: when i referance array elemant 2 it will give me paragraph which is in that element and not all paragraphs in the text file...
12
5717
by: arnuld | last post by:
in C++ Primer 4/3 Lippman says in chapter 3, section 3.3.1: vector<stringsvec(10); // 10 elements, each an empty string here is the the code output & output from my Debian box running "gcc 3.3.5": #include <iostream> #include <vector>
4
1508
by: Brian C | last post by:
Hello all, I was playing around (don't know why, perhaps bored at work) with the vector class. This was on an AIX machine using IBM's xlC compiler. Anyway, I wrote a simple class, and inserted it a couple of times into a vector. What I found odd was that when I inserted the 2nd item, I saw that it called my copy constructor for the 1st item and the 2nd item. When I inserted the 3rd object, it called the copy constructor for the...
0
2400
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile View I want the form populated from there profile on the sql server. The code to save the profile works fine. But when the user logs back in they data doesn't load back to the form. The multiview is located inside the LoginView's Logged-In View ....
3
1587
by: Rob | last post by:
I have these classes (elided methods): class Base { public: Base(string name) {...} }; class Derived : public Base {
19
1527
by: Ramon F Herrera | last post by:
Newbie alert: I come from the C side, struggling to learn C++. I need a two-dimensional data structure. I first tried a regular vector and added the 2nd dimension with my own structs and pointers. I couldn't make it work. Too many illegal assignments. My next attempt was to create a vector of vector (or list of vector, etc.). The compiler (MSVC++) doesn't seem to like such structure. I guess I could try gcc, but let's hear the experts'...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.