473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Maxmimum length of a line?

Short question: Is there any limit to the length of a single line in
javascript?

(Not in the FAQ; came up short in google, and haven't found the really good
references yet.)

Long question: I'm writing a n-depth hierarchical select function and I
need to seed the options data. I could do something like:

1)
data = new Array(1, 2, 3);
data_0 = new Array(11, 12, 13);
data_0_0 = new Array(111, 112, 113);
etc

Or 2)
data = new Array(1, new Array(11, new Array(111, 112, 113), 12, 13), 2, 3);

This is going to be auto-generated stuff, so the unreadability of the 2nd
approach doesn't bother me. So my prime concern is which is the
better/faster approach. I'd benchmark the two, but I first want to make
sure the 2nd approach is ok. If the options are lengthy, then the line in
the 2nd approach could be very long.

I'm sure this is old hat for many/most. I'm an experienced smalltalk/java
programmer but I'm still getting on my feet in javascript. If you have
comments on the alternatives, I'd love to hear them. For example, how do
most javascript implementations implement object attributes and arrays.
With HashMaps and Arrays? IOW, what are performance underpinnings of
javascript that I should know and understand? And can anyone provide refs
to this knowhow? TIA.

P.S. An answer such as: "javascript is fast enough on the client that this
is a silly issue to worry about" is a good one, if its true.
Jul 23 '05 #1
3 1119
Rich MacDonald wrote:
Short question: Is there any limit to the length of a single line in
javascript?
Hmmmm, good question.
(Not in the FAQ; came up short in google, and haven't found the really good
references yet.)

Long question: I'm writing a n-depth hierarchical select function and I
need to seed the options data. I could do something like:

1)
data = new Array(1, 2, 3);
data_0 = new Array(11, 12, 13);
data_0_0 = new Array(111, 112, 113);
etc
use an Object instead.

var data = new Object();
data.1 = new Object(11,12,13);
data.1.11 = new Object(111,112,113);

And so on. There are better constructs for doing that, such as the one
below, but it hinders readability when debugging.
Or 2)
data = new Array(1, new Array(11, new Array(111, 112, 113), 12, 13), 2, 3);

This is going to be auto-generated stuff, so the unreadability of the 2nd
approach doesn't bother me. So my prime concern is which is the
better/faster approach. I'd benchmark the two, but I first want to make
sure the 2nd approach is ok. If the options are lengthy, then the line in
the 2nd approach could be very long.
Do it the first way. Even if no other reason than readability to debug
any errors until its error free. It also remedies 99% of the problem
with line/variable lengths.
P.S. An answer such as: "javascript is fast enough on the client that this
is a silly issue to worry about" is a good one, if its true.


Javascript speed is directly dependent on the code though :)
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2
Lee
Rich MacDonald said:

Short question: Is there any limit to the length of a single line in
javascript?

(Not in the FAQ; came up short in google, and haven't found the really good
references yet.)

Long question: I'm writing a n-depth hierarchical select function and I
need to seed the options data. I could do something like:

1)
data = new Array(1, 2, 3);
data_0 = new Array(11, 12, 13);
data_0_0 = new Array(111, 112, 113);
etc

Or 2)
data = new Array(1, new Array(11, new Array(111, 112, 113), 12, 13), 2, 3);

This is going to be auto-generated stuff, so the unreadability of the 2nd
approach doesn't bother me. So my prime concern is which is the
better/faster approach. I'd benchmark the two, but I first want to make
sure the 2nd approach is ok. If the options are lengthy, then the line in
the 2nd approach could be very long.


The simplest, and probably most efficient approach is:

data = [ 1, [ 11, [ 111, 112, 113 ] ],
2, [ 21, 22, 23, [ 231, 232 ] ]
];

You shouldn't have any problem with line length, but if you want it to be
readable at all, insert line breaks.

Jul 23 '05 #3
VK
# 2 is better

ECMA specs do not impose any limits on literal length. Maximum array
length is 2^32. Two points to pay attention though:

1) ECMA specs is often kind of Pirats' code: "not a rule, but rather a
guideline" for browser producers (you know to who the biggest stone
flies).

2) Your script will work not on some abstract Babbidge machine, but on
a real computer with some limits on memory and stack depth (specially
it's true for thin clients like PDA and phones). So where and when your
n-sized array will reach these limits - it can be answered only during
experiments.

Jul 23 '05 #4

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

Similar topics

1
by: Hozi | last post by:
I am getting the below error when asp.net tries to parse the .aspx file. The funny part is that the error only seems to be happening when viewing the page throuh IE 6 and not Netscape browsers. I...
6
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
15
by: Spiros Bousbouras | last post by:
I'm thinking of adding a command to vim for removing white space from the end of each line of a C source file. Can anyone think of a situation where such white space might be useful ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.