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

Removing text from strings

P: n/a
I'm writing a program to emulate nuerons (can't spell for my life
sorry) and am using an array of "mailboxes" to propagate messages
through the network, but I need to be able to remove the request from
everybody's mailbox after the response is returned. The source can be
found at www.birchile.com/webbomb/brain.htm , the source is in the only
script tag there. To be specific I want to delete text from the mb
array using the look() method of the n object.

--Thanks for listening,
mouseit

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


P: n/a
mo********@gmail.com wrote:
I'm writing a program to emulate nuerons (can't spell for my life
sorry)
Do you mean "neurons", as in "cortex"? (BTW, spell checkers exist.)
[...] To be specific I want to delete text from the mb
array using the look() method of the n object.


Sorry, your code lacks any sign of code style, particularly indentation, and
there is no inline documentation whatsoever. Fix that and come back again
if you want advice _for free_.
PointedEars
Jan 14 '06 #2

P: n/a
Yeah I dont really bother with comments or the like, dont need it, and
I'm waaay to lazy to find a spell checker (Microsoft Word takes
forever).

Jan 15 '06 #3

P: n/a
Thanks anyways I think.

Jan 15 '06 #4

P: n/a
"mo********@gmail.com" <mo********@gmail.com> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
Yeah I dont really bother with comments or the like, dont need it, and
I'm waaay to lazy to find a spell checker (Microsoft Word takes
forever).


It is difficult to read unindented code and especially make sense of it
when you don't use semicolons to end statements, a really bad practice.
You probably never learned C or any of its object-oriented descendants, but
ending statements in a semicolon is NOT an option in those languages, and
why Javascript made it an option is anyone's guess, except maybe to please
those who lack any sort of discipline such as barely commenting their code.

It would also help if you use more descriptive identifier names for
variables and functions/methods/properties. Functions that are declared as
'sd' could actually be named 'sendDirectMail' if that's what they in fact
do. It makes code more easily debuggable by others----something you are
requesting here. Moreover, the Javacript language designers encourage the
use of descriptive identifiers.

The only way of debugging your problem is to load it up into a debugger to
track execution, and you don't even suggest inputs to your form to attempt
to help us reproduce the problem you are having.

Give that original post of yours and your source code some more thought.
Jan 15 '06 #5

P: n/a
Actually C and C++ were the first two languges I learned, Processing
does it and I do a lot in that so im used to it. As for indented code
I just don't see the point... I can read it fine sans indents. Also
sorry about the comments I guess I dont really have an exuse for that.

Jan 15 '06 #6

P: n/a
Patient Guy said the following on 1/15/2006 4:26 AM:
"mo********@gmail.com" <mo********@gmail.com> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:

Yeah I dont really bother with comments or the like, dont need it, and
I'm waaay to lazy to find a spell checker (Microsoft Word takes
forever).

It is difficult to read unindented code and especially make sense of it
when you don't use semicolons to end statements, a really bad practice.


Using semicolons to end statements is optional so I am not sure how you
can say that something that isn't required is "bad practice" per se in
Javascript itself. Is it a bad practice when moving to other languages?
Absolutely.

I have yet to see code (and am interested in a *real world example*)
where leaving the semicolon off breaks the code but inserting it fixes
the code.

When I say "real world example" I am not asking for a theoretical
situation where the code would never be used for any purpose other than
showing the lack of ; causes an error but adding it removes the error.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 15 '06 #7

P: n/a
Zif
mo********@gmail.com wrote:
Actually C and C++ were the first two languges I learned, Processing
does it and I do a lot in that so im used to it. As for indented code
I just don't see the point... I can read it fine sans indents. Also
sorry about the comments I guess I dont really have an exuse for that.


Stuff 'em - if it was hard to write, it /should/ be hard to read. If
they can't read it, they don't know enough to help, right?
--
Zif
Jan 16 '06 #8

P: n/a
Zif said the following on 1/15/2006 7:58 PM:
mo********@gmail.com wrote:
Actually C and C++ were the first two languges I learned, Processing
does it and I do a lot in that so im used to it. As for indented code
I just don't see the point... I can read it fine sans indents. Also
sorry about the comments I guess I dont really have an exuse for that.

Stuff 'em - if it was hard to write, it /should/ be hard to read.


That's not true. The easier code is to read the easier it is to maintain.
If they can't read it, they don't know enough to help, right?


If you want to believe that, then go ahead. It is very far from the
truth though. Many people, myself included, simply don't care to sit and
make code readable to be able to help a person who is asking for *free*
help. If you want free help, then you should endeavor to please the
people you are asking for help from.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 16 '06 #9

P: n/a
Randy Webb <Hi************@aol.com> wrote in news:c6Gdnb83xaBKPVfeRVn-
uQ@comcast.com:
Patient Guy said the following on 1/15/2006 4:26 AM:
"mo********@gmail.com" <mo********@gmail.com> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:

Yeah I dont really bother with comments or the like, dont need it, and
I'm waaay to lazy to find a spell checker (Microsoft Word takes
forever).

It is difficult to read unindented code and especially make sense of it
when you don't use semicolons to end statements, a really bad practice.


Using semicolons to end statements is optional so I am not sure how you
can say that something that isn't required is "bad practice" per se in
Javascript itself. Is it a bad practice when moving to other languages?
Absolutely.

I have yet to see code (and am interested in a *real world example*)
where leaving the semicolon off breaks the code but inserting it fixes
the code.

When I say "real world example" I am not asking for a theoretical
situation where the code would never be used for any purpose other than
showing the lack of ; causes an error but adding it removes the error.


http://groups.google.com/groups?q=se...vascript&hl=en

The 1st, 2nd, and 4th links in that results page show good threads
containing posts from individuals who urge the use of semicolons in
Javascript, and those who shrug their shoulders about whether they should
be required.

I write Javascript pretty much the same way I used to style C, from which
Javascript ultimately derives. The inclusion of semicolons makes code
readable and maintainable by others, even if the interpreter can whiz
through it and insert the end-of-statement tokens itself.

Jan 16 '06 #10

P: n/a
Patient Guy said the following on 1/16/2006 1:05 AM:
Randy Webb <Hi************@aol.com> wrote in news:c6Gdnb83xaBKPVfeRVn-
uQ@comcast.com:

Patient Guy said the following on 1/15/2006 4:26 AM:
"mo********@gmail.com" <mo********@gmail.com> wrote in
news:11**********************@o13g2000cwo.googl egroups.com:

Yeah I dont really bother with comments or the like, dont need it, and
I'm waaay to lazy to find a spell checker (Microsoft Word takes
forever).
It is difficult to read unindented code and especially make sense of it
when you don't use semicolons to end statements, a really bad practice.
Using semicolons to end statements is optional so I am not sure how you
can say that something that isn't required is "bad practice" per se in
Javascript itself. Is it a bad practice when moving to other languages?
Absolutely.

I have yet to see code (and am interested in a *real world example*)
where leaving the semicolon off breaks the code but inserting it fixes
the code.

When I say "real world example" I am not asking for a theoretical
situation where the code would never be used for any purpose other than
showing the lack of ; causes an error but adding it removes the error.

http://groups.google.com/groups?q=se...vascript&hl=en

The 1st, 2nd, and 4th links in that results page show good threads
containing posts from individuals who urge the use of semicolons in
Javascript, and those who shrug their shoulders about whether they should
be required.


Let me take a guess, off the top of my head, of people who might be in
those 4 threads, in no particular order. You will have to trust my
integrity when I tell you I am making this list prior to looking at that
URL:

Richard Cornford
Douglas Crockford
Lasse Reichstein Nielsen
Thomas Lahn
RobG
Michael Winter

Not sure about Martin Honnen and Jim Ley, my memory fades with them.

People who I *know* have shrugged his shoulders at ; at the end of a
line prior to the CR/LF:

Randy Webb

But alas, I didn't ask for a list of people who "urge the use". I asked
for a real world code example where the lack of a ; prior to the CR/LF
would introduce a syntax error where adding it would prevent the error.
And to get started, I will give you three examples where adding the ;
will introduce errors and/or change the meaning of the code:

Example 1:

var j = 0;
for (i=0;i<10;i++);
{j++}
alert(j)

What does j equal? The ; changes the meaning of the code when it isn't
there:

var j = 0;
for (i=0;i<10;i++)
{j++}
alert(j)
Example 2:

function myFunction();
//syntax error, expected {
{
var j = 0;
for (i=0;i<10;i++)
{j++}
alert(j)
}

Example 3:

var myVar =
"Some text that will stretch on and on and on and in order" +
"to make code readable when viewed in an editor it is broken" +
"up across lines like I have it now."

Perfectly error-free lines of code. Now, introduce ; prior to the CR/LF:

var myVar =
"Some text that will stretch on and on and on and in order" + ;
"to make code readable when viewed in an editor it is broken" + ;
"up across lines like I have it now.";

Syntax Error.

There are three *real world examples* of code that when the line is
ended in a semi-colon it introduces a syntax error and/or changes the
meaning of the code.

What I am asking for is the reverse. An example of *real world code*
that when the ; is left off then it causes a syntax error but adding
fixes that error.

Now, I will go look at those threads.

Thread 1:

Dated from October 2001 and Jim Ley is saying:
<quote>
No it shouldn't, the compiler should insert them if need be based on
the rules of "Automatic Semi-Colon Insertion" (ECMAScript section 7.9)
</quote>
In reply to the statement:
<quote>JavaScript in the standardised version *should* have them.</quote>

Thread 2: Eric Lippert in 1998 quoting ECMA 262 and showing examples of
where the semi colon being present or not changes the meaning of the code.

He also says in that thread:

<quote>
there is no appreciable perf hit or gain for leaving out
semicolons.
</quote>

That was one thing I was curious about testing was whether having them
there made any speed difference and it doesn't seem to.

Thread 4:
Once again, Jim Ley had something to say about it:

<quote>
Automatic semi-colon insertion is a feature of the language, they will
be added in most circumstances where you would go ;<newline>,
therefore you can leave them out.
</quote>

And if I were to have to chose who to listen to: Jim Ley or Eric
Lippert, well, Eric loses.

I write Javascript pretty much the same way I used to style C, from which
Javascript ultimately derives.
Many people do write Javascript that way. And many people use JS as a
learning language to get to other languages.
The inclusion of semicolons makes code readable and maintainable by others,


maintainable? Yes, I agree with that.
more readable? No.

You are saying that this:

var myVar= myVar1 + myVar2 + myVar3;

is easier to read than this:

var myVar= myVar1 + myVar2 + myVar3

Solely because of the ; at the end of the line?

Again, I am not referring to in between script statements but at the end
of a line prior to the CR/LF.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 16 '06 #11

P: n/a
mo********@gmail.com wrote:
Yeah I dont really bother with comments or the like, dont need it, and
I'm waaay to lazy to find a spell checker (Microsoft Word takes
forever).


You do not care about your readers, why the heck should they care about you?
PointedEars
Jan 16 '06 #12

P: n/a
JRS: In article <c6********************@comcast.com>, dated Sun, 15 Jan
2006 14:22:10 local, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :

I have yet to see code (and am interested in a *real world example*)
where leaving the semicolon off breaks the code but inserting it fixes
the code.


This is a constructed case; but ISTM that the lines with semicolons are
each an efficient way to determine the last "large" value in A, for
different values of "large".

Omitting the first semicolon gives an infinite loop.
Omitting the second instead sets T incorrectly.

A = [1,1,1,7,1,1,4,1,1,1,1]

J = 10 ; while ((X=A[J--])<6) ;
J = 10 ; while ((Y=A[J--])<3) ;

T = [X, Y]

Bodyless FOR loops are also possible ...

Perhaps someone can find instances of such bodyless loops in code-in-
use.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 16 '06 #13

P: n/a
I was just seeing if you were willing to help, if you arent then okay.
And its just that I assume that everybody else can read it the way I
do......

Jan 16 '06 #14

P: n/a
JRS: In article <_N********************@comcast.com>, dated Mon, 16 Jan
2006 03:55:06 local, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
What I am asking for is the reverse. An example of *real world code*
that when the ; is left off then it causes a syntax error but adding
fixes that error.


You did not, AFAICS, specify a *syntax* error before. At the time of
writing, the one cited above is the only article containing the word and
visible to me in the thread.

Syntax errors don't much matter, of course; it's syntactically-
acceptable semantic differences that really matter.

A really good example would be syntactically correct and executable both
with and without the semicolon; but with different results. And the
code should look plausible in either state : for (j=1;j<10;j++) ; is
legitimate but implausible.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 16 '06 #15

P: n/a
mo********@gmail.com said the following on 1/16/2006 6:22 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
I was just seeing if you were willing to help, if you arent then okay.
And its just that I assume that everybody else can read it the way I
do......


Give it some time and you get used to Thomas' pedantic non-sense.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Jan 17 '06 #16

P: n/a
Dr John Stockton said the following on 1/16/2006 4:16 PM:
JRS: In article <_N********************@comcast.com>, dated Mon, 16 Jan
2006 03:55:06 local, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :

What I am asking for is the reverse. An example of *real world code*
that when the ; is left off then it causes a syntax error but adding
fixes that error.

You did not, AFAICS, specify a *syntax* error before. At the time of
writing, the one cited above is the only article containing the word and
visible to me in the thread.


Yes, in my original I used the phrase "where leaving the semicolon off
breaks the code" instead of specifying a syntax error. I gave examples
in the thread you are replying to where adding the semicolon changes the
meaning of the code.
Syntax errors don't much matter, of course; it's syntactically-
acceptable semantic differences that really matter.
Very true. Hypotheticl post:
<hypothetical post>

Hey, my code worked fine and I read here that I should have ; at the end
of every line so I added them and now it doesn't work properly anymore.
Why? Here is my code:

var j = 0;
for (i=0;i<10;i++);
{j++};
alert(j);

</hypothetical post>
A really good example would be syntactically correct and executable both
with and without the semicolon; but with different results. And the
code should look plausible in either state : for (j=1;j<10;j++) ; is
legitimate but implausible.


That is one of the examples I gave where adding it will change the
meaning of the code and actually cause harm to the code to add it.

A lot is said in this group about "You should end your lines in
semicolons" when that is absurdly not true as it doesn't matter one bit
whether you do or not. That is specifically related to Javascript.

I say that last line before someone points out "but if you use another
language.....". The use of another language does not dictate its
requirement in this language. And I would be totally shocked if it made
that much difference in a real world application where having them there
made any noticable difference in speed of execution.

"Hey Louie, I just shaved 60 ms off the 218 seconds it takes this script
to execute by adding 380,000 semicolons to this script but it added 180
ms to the download time"

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 17 '06 #17

P: n/a
JRS: In article <11*********************@z14g2000cwz.googlegroups. com>,
dated Mon, 16 Jan 2006 15:22:17 local, seen in
news:comp.lang.javascript, mo********@gmail.com <mo********@gmail.com>
posted :
I was just seeing if you were willing to help, if you arent then okay.
And its just that I assume that everybody else can read it the way I
do......


Don't worry about Thomas Lahn; he has an Emperor complex.

There are normal people posting here who will be able to help; but for
that you still need to present your problem in a helpful manner.

That means indented to show structure, spaces included for legibility,
compatible line-lengths, etc.

Note too that it is helpful to reduce your problem code to the minimum
size by cutting out irrelevancies, and then to post it here; that's more
convenient for those with off-line newsreaders. Try to show civility
and intelligence; distinguish yourself from the common herd of anonymous
GoogleGroups Gmail users.

And remember, if you only have experience of Google access to News, your
experience is very limited and untypical of that of the experts.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 17 '06 #18

P: n/a
Randy Webb wrote:
<snip>
I have yet to see code (and am interested in a *real world
example*) where leaving the semicolon off breaks the code
but inserting it fixes the code.

When I say "real world example" I am not asking for a
theoretical situation where the code would never be used
for any purpose other than showing the lack of ; causes
an error but adding it removes the error.


Earlier today I omitted a semicolon and encountered a "real world"
example where the omission of a semicolon made a significant difference
to the interpretation of (and consequent behaviour of) javascript source
code. I was reminded of this thread so I though I would post it here.

A small but undesirable display glitch was being triggered in a
particular method and to identify the specific line of code responsible
I inserted - alert - calls in strategic positions in the method body. As
this was short-term debugging code I did not think about it much and
omitted some of the semicolons, only to find that IE complained 'Object
expected' (the error message that usually means that it has not found a
function that it was expecting to call).

This is the code, with the alert call:-

if(
(selectedNode)&&
(selectedNode.nextSibling)
){

alert('3')
(selectedNode = selectedNode.nextSibling).selectItem();
...

Without the semicolon following the alert call the following primary
expression and contained assignment expression changes nature, becoming
the arguments to a function call.

The omission of the semi-colon may not have actually produced a syntax
error, but it has significantly altered the meaning of the following
line of code.

Richard.
Feb 8 '06 #19

This discussion thread is closed

Replies have been disabled for this discussion.