473,836 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing text from strings

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
18 1597
Patient Guy said the following on 1/16/2006 1:05 AM:
Randy Webb <Hi************ @aol.com> wrote in news:c6Gdnb83xa BKPVfeRVn-
uQ@comcast.com:

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

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>JavaScri pt 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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 16 '06 #11
mo********@gmai l.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
JRS: In article <c6************ ********@comcas t.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 16 '06 #13
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
JRS: In article <_N************ ********@comcas t.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 16 '06 #15
mo********@gmai l.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.c om, 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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Jan 17 '06 #16
Dr John Stockton said the following on 1/16/2006 4:16 PM:
JRS: In article <_N************ ********@comcas t.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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 17 '06 #17
JRS: In article <11************ *********@z14g2 000cwz.googlegr oups.com>,
dated Mon, 16 Jan 2006 15:22:17 local, seen in
news:comp.lang. javascript, mo********@gmai l.com <mo********@gma il.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 17 '06 #18
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.n extSibling)
){

alert('3')
(selectedNode = selectedNode.ne xtSibling).sele ctItem();
...

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2523
by: Paradox | last post by:
In general I love Python for text manipulation but at our company we have the need to manipulate large text values stored in either a SQL Server database or text files. This data is stored in a "text" field type and is definitely not unicode though it is often very strange text since it is either OCR or some kinda electronic file extraction. Unfortunately when it is retrieved into a string type in python it is invariably a unicode type...
0
5676
by: Eric | last post by:
Hi, I was sure I would be able to find some info about this in the LWP archives but I have had no luck. I also can't seem to tell if the libwwww Perl mailing list is alive or not. my $ua = LWP::UserAgent->new(); push @{ $ua->requests_redirectable }, 'POST';
1
346
by: ChrisC | last post by:
Im having trouble removing line breaks from my c# string. Actually, im having trouble getting .Trim() to work properly, as it seems to count a string that has nowt but a break of some sort as not being empty. To get trim to work properly im trying to axe out the line breaks seperately. Ive got .replace("/r") and "/n" but still having problems with some strings. Are there paragraph markers or something I should be removing too? how do i...
8
14279
by: Peter O'Reilly | last post by:
I have an HTML form with a textarea input box. When the user conducts a post request (e.g. clicks the submit button), an HTML preview page is presented to them with the information they have filled out in the prior page's form elements. Naturally some users like to copy and paste text into the textarea box and presumably do so from say a word processor program. Some Macintosh based users I know of experience problems with foreign...
16
2067
by: graham.reeds | last post by:
I am updating a website that uses a countdown script embedded on the page. When the page is served the var's are set to how long the countdown has left in minutes and seconds, but the rest of the script is left untouched. However I want to take the script out of the page and have it as a seperate file that can be cached, reducing serving costs - the page gets hit a couple of thousand times per day, sometimes as high a 5K, so any...
0
2477
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically added row it also removes the row at the end along with the added row. Plz tell me if, I am missing any thing. Code </asp:datagrid>
23
1768
by: Peter Row | last post by:
Hi, I am currently working on a VB.NET project that has been going for quite a while. In the past it has been developed with a lot of compatibility VB6 functions and constants, e.g Left(), LCase() and vbCr Whilst not currently able to port to C# I am trying to remove usage of these functions and constants.
6
8670
by: bruce | last post by:
hi... i'm running into a problem where i'm seeing non-ascii chars in the parsing i'm doing. in looking through various docs, i can't find functions to remove/restrict strings to valid ascii chars. i'm assuming python has something like valid_str = strip(invalid_str)
11
6201
by: cmay | last post by:
I am having this problem... Lets say that your source XML is formatted like this: <somenode> Here is some text Here is some more text </somenode> When to a <xsl:value-of select="somenode" /I want the output to be free of the tabs that are included in the source XML. These tabs are not really part of the content, but rather just there
8
2512
by: starsky51 | last post by:
I'm sure it's something i'm doing wrong, I just can't see it. I've set up a simple page with the following code: <html> <head> <title>tester</title> <script language="javascript" type="text/javascript"> alert('First String Second String'); </script> </head>
0
10819
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10570
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
10240
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
9355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5641
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...
0
5811
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4438
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
4000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3100
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.