473,320 Members | 1,936 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,320 software developers and data experts.

Yet another inexplicable js error!

Here's a reason why javascript sucks so bad. The following *SIMPLE*
piece of code will not work properly. Jesus, how I yearn for the day
when a real programming language can be substituted for this patched
together scripting horror. I suspect the string object's methods are
simply not robust enough for this because neither of the strings
appear to have the value they should when this loop runs. Perl would
handle this kind of thing with no problem. Javascript definitely needs
to catch up. (Sorry about the rant, but for a long-time programmer
this is terribly frustrating!)

-----------------

for (x=0; x<=theStr.length; x++);
{
theNewStr += theStr.charAt(x);
}

-----------------

--pstone
Jul 20 '05 #1
5 2229
> Here's a reason why javascript sucks so bad. The following *SIMPLE*
piece of code will not work properly. Jesus, how I yearn for the day
when a real programming language can be substituted for this patched
together scripting horror. I suspect the string object's methods are
simply not robust enough for this because neither of the strings
appear to have the value they should when this loop runs. Perl would
handle this kind of thing with no problem. Javascript definitely needs
to catch up. (Sorry about the rant, but for a long-time programmer
this is terribly frustrating!)

for (x=0; x<=theStr.length; x++);
{
theNewStr += theStr.charAt(x);
}


Notice that there's a semi-colon after the for statement? I hope it's a
typing error when you're posting...
KC
Jul 20 '05 #2
Lee
Patrick Stone said:

Here's a reason why javascript sucks so bad. The following *SIMPLE*
piece of code will not work properly. Jesus, how I yearn for the day
when a real programming language can be substituted for this patched
together scripting horror. I suspect the string object's methods are
simply not robust enough for this because neither of the strings
appear to have the value they should when this loop runs. Perl would
handle this kind of thing with no problem. Javascript definitely needs
to catch up. (Sorry about the rant, but for a long-time programmer
this is terribly frustrating!)

-----------------

for (x=0; x<=theStr.length; x++);
{
theNewStr += theStr.charAt(x);
}


It's interesting that the more a person rants about the lousy
programming language, the more obvious the coding errors are.
There are two pretty obvious errors in those few lines. We
can only guess what you've done wrong in your other code.

for (x=0; x<theStr.length; x++)
{
theNewStr += theStr.charAt(x);
}

I don't want to know why you would ever copy a string one
character at a time.

Jul 20 '05 #3
In article <f2**************************@posting.google.com >, Patrick Stone wrote:
Perl would handle this kind of thing with no problem.
No it wouldn't.

Perl would require the for loop to have a bracket expression
before terminating:

for (x=0; x<=theStr.length; x++){};

instead of your

for (x=0; x<=theStr.length; x++);

(if you want to terminate the for loop before
doing anything, as you are doing)
-----------------

for (x=0; x<=theStr.length; x++);
{
theNewStr += theStr.charAt(x);
}

-----------------

--pstone

Jul 20 '05 #4
Patrick Stone wrote:
Here's a reason why javascript sucks so bad. The following *SIMPLE*
piece of code will not work properly. Jesus, how I yearn for the day
when a real programming language can be substituted for this patched
together scripting horror. I suspect the string object's methods are
simply not robust enough for this because neither of the strings
appear to have the value they should when this loop runs. Perl would
handle this kind of thing with no problem. Javascript definitely needs
to catch up. (Sorry about the rant, but for a long-time programmer
this is terribly frustrating!)

-----------------

for (x=0; x<=theStr.length; x++);
{
theNewStr += theStr.charAt(x);
}

-----------------

--pstone


In addition to everything everyone else has said, I'd like to point out
that JavaScript is hardly a "patched together scripting horror", and if it
*were*, this is certainly not evidence of it. The loop as written above
would do precisely the same thing in C, C++, C# and Java (assuming you
modified the code to conform to the particular nuances of the language you
choose), and none of those languages are "patched together scripting
horrors".

As for your suspicion that it has to do with some "lack of robustness" in
the String objects methods, try again. The String object has a
full-featured set of methods which do a fine job of even extremely complex
string manipulations.

By the way, your code, as written above, is equivilent to:

theNewStr = theStr;

If you are processing the string one character at a time in order to
identify and manipulate specific characters, there's probably a myriad of
better ways of doing it then by chugging through the string one character
at a time. Want to capitalize the first character of every word?

String.prototype.toMixedCase = function() {
function toUpper(sChar) { return sChar.toUpperCase(); }

return this.toLowerCase().replace(/\b(.)/g, toUpper);
}

theNewStr = theStr.toMixedCase();

Want to remove all the spaces from the string?

theNewStr = theStr.split(' ').join('');

// or

theNewStr = theStr.replace(/ /g, '');

Want to identify the '#' character and everything that comes after it, but
only if you find it in the string?

if (/#(.*)/.test(theStr)) {
alert('theStr contained a # and ' + RegExp.$1 + ' came after it');
}

So yeah, I guess you're right, JavaScript is just a non-functional mess
that can't do anything. Better go back to Perl where you can loop through
every character in a string to accomplish the same goals.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #5
Grant Wagner wrote:
Patrick Stone wrote:

Here's a reason why javascript sucks so bad. [snippy-snip]


So yeah, I guess you're right, JavaScript is just a non-functional mess
that can't do anything. Better go back to Perl where you can loop through
every character in a string to accomplish the same goals.


The irony here is that Perl is built around complex string manipulation
and has a lot more string methods than JavaScript. Why he would ever
try to evaluate a string one character at a time in Perl is something
far beyond the grasp of any mortal programmer. Your arguments
supporting JavaScript apply to Perl in every way. In Perl, he should be
using:

$TheNewString = $TheString;

I've even found it more combersome to switch back to C-style string
manipulation (one character at a time) in Perl than to just RTM and find
out how to use one of the hundreds of string manipulation features.

I know how it feels to do everything the hard way for a while until I
crack open a book and say, "Oh, so that's how you do it..." I would
suggest to the OP a trip to the nearest bookstore that sells any
O'Reilly and Associates books. (Maybe "Programming Perl" would also be
a good buy alongside the venerable "javascript: The Definitive Guide.")

Happy reading,
Zac

Jul 20 '05 #6

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
13
by: Dave | last post by:
Can anybody tell me why the code below should produce the error below? I'm going nuts here! Am I missing something incredibly obvious and simple? std::string::size_type idx; std::string...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
8
by: johnmmcparland | last post by:
Hi all, my program is trying to add group boxes with radio buttons at run time. While at one point it was able to draw the group boxes without the radio buttons, now it encounters problems just...
1
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled...
0
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.