[28086] in Perl-Users-Digest
Perl-Users Digest, Issue: 9450 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 11 18:05:48 2006
Date: Tue, 11 Jul 2006 15:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 11 Jul 2006 Volume: 10 Number: 9450
Today's topics:
Get Invoked Script Location in Perl fiorentico@gmail.com
Re: Get Invoked Script Location in Perl <David.Squire@no.spam.from.here.au>
Re: Get Invoked Script Location in Perl <1usa@llenroc.ude.invalid>
Help with grep function <pradeep.bg@gmail.com>
Re: Help with grep function axel@white-eagle.invalid.uk
Re: Help with grep function <David.Squire@no.spam.from.here.au>
Re: Help with grep function <xicheng@gmail.com>
Re: Help with grep function <kst-u@mib.org>
Re: Help with grep function <tadmc@augustmail.com>
Re: Inner classes, sort of? <No_4@dsl.pipex.com>
Re: processing large numbers/values/figures <ruf@rawip.org>
Re: processing large numbers/values/figures <ruf@rawip.org>
Re: processing large numbers/values/figures <ruf@rawip.org>
Re: processing large numbers/values/figures <ced@blv-sam-01.ca.boeing.com>
Re: processing large numbers/values/figures <tadmc@augustmail.com>
Re: Results in multiple pages. Takes too much time <mark.clementsREMOVETHIS@wanadoo.fr>
Re: Results in multiple pages. Takes too much time <penryu@saiyix.ath.cx>
RSS feeds and HTML special characters eurosnob@gmail.com
Re: Using References to Formats, Examining Scalars With <vtatila@mail.student.oulu.fi>
Re: What is a type error? <david.nospam.hopwood@blueyonder.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Jul 2006 12:31:58 -0700
From: fiorentico@gmail.com
Subject: Get Invoked Script Location in Perl
Message-Id: <1152646318.196338.211920@s13g2000cwa.googlegroups.com>
Hi,
I'd like to obtain the location of the script I am calling. E.g.
If I am calling
perl X:\script.pl
I want to obtain "X:\". How do I do that?
getcwd and cwd don't apply beacuse I am running the Script from another
location. Thanks
------------------------------
Date: Tue, 11 Jul 2006 20:38:22 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Get Invoked Script Location in Perl
Message-Id: <e90unf$da$2@gemini.csx.cam.ac.uk>
fiorentico@gmail.com wrote:
> Hi,
>
> I'd like to obtain the location of the script I am calling. E.g.
>
> If I am calling
>
> perl X:\script.pl
>
> I want to obtain "X:\". How do I do that?
>
> getcwd and cwd don't apply beacuse I am running the Script from another
> location. Thanks
>
See perldoc perlvar. Look for the string "Contains the name of the
program being executed".
DS
------------------------------
Date: Tue, 11 Jul 2006 19:56:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Get Invoked Script Location in Perl
Message-Id: <Xns97FDA2322952asu1cornelledu@127.0.0.1>
David Squire <David.Squire@no.spam.from.here.au> wrote in
news:e90unf$da$2@gemini.csx.cam.ac.uk:
> fiorentico@gmail.com wrote:
>> Hi,
>>
>> I'd like to obtain the location of the script I am calling. E.g.
>>
>> If I am calling
>>
>> perl X:\script.pl
>>
>> I want to obtain "X:\". How do I do that?
>>
>> getcwd and cwd don't apply beacuse I am running the Script from
>> another location. Thanks
>>
>
> See perldoc perlvar. Look for the string "Contains the name of the
> program being executed".
See perldoc FindBin.
AFAIK, the contents of $0 are OS dependent.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 11 Jul 2006 12:17:21 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: Help with grep function
Message-Id: <1152645441.340123.32760@35g2000cwc.googlegroups.com>
Hi All,
I am trying to count the number of errors in a file:
ERROR: Display
ERROR:Virtual
ERROR: Test
ERROR: Random
I use:
$ctError = `grep -ci error filename`;
It gives 4
Now i am trying to count error which doesnot contain Virtual, so i
should get $ctError = 3. Is there any way possible to implement in the
same line.
Thanks
------------------------------
Date: Tue, 11 Jul 2006 19:31:53 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: Help with grep function
Message-Id: <J0Tsg.6481$5K2.2711@fed1read03>
Deepu <pradeep.bg@gmail.com> wrote:
> Hi All,
> I am trying to count the number of errors in a file:
> ERROR: Display
> ERROR:Virtual
> ERROR: Test
> ERROR: Random
> I use:
> $ctError = `grep -ci error filename`;
> It gives 4
> Now i am trying to count error which doesnot contain Virtual, so i
> should get $ctError = 3. Is there any way possible to implement in the
> same line.
Have a look at the -v option to grep...
`grep -i error filename | grep -vci virtual`
It's not really a Perl question.
Axel
------------------------------
Date: Tue, 11 Jul 2006 20:32:46 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Help with grep function
Message-Id: <e90ucu$da$1@gemini.csx.cam.ac.uk>
Deepu wrote:
> Hi All,
>
> I am trying to count the number of errors in a file:
>
> ERROR: Display
> ERROR:Virtual
> ERROR: Test
> ERROR: Random
>
> I use:
>
> $ctError = `grep -ci error filename`;
>
> It gives 4
>
> Now i am trying to count error which doesnot contain Virtual, so i
> should get $ctError = 3. Is there any way possible to implement in the
> same line.
You could try using Perl's own grep function, rather than making a
system call. This would also make your program more portable. On the
other hand, you don't need to store the matching lines, so grep is not
needed. How about this:
----
#!/usr/bin/perl
use strict;
use warnings;
my $TotalErrors;
my $NonVirtualErrors;
# here you would open your file, e.g. open my $FileHandle, '<',
'filename' or die "Couldn't open filename: $!";
# then use $FileHandle instead of DATA below
while (my $Line = lc(<DATA>)) {
next unless $Line =~ /error/;
$TotalErrors++;
$NonVirtualErrors++ unless $Line =~ /virtual/;
}
print "Total errors: $TotalErrors\nNon-virtual errors: $NonVirtualErrors";
__DATA__
ERROR: Display
ERROR:Virtual
ERROR: Test
ERROR: Random
----
Output:
Total errors: 4
Non-virtual errors: 3
----
DS
------------------------------
Date: 11 Jul 2006 12:58:08 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: Help with grep function
Message-Id: <1152647888.077352.86250@m73g2000cwd.googlegroups.com>
Deepu wrote:
> Hi All,
>
> I am trying to count the number of errors in a file:
>
> ERROR: Display
> ERROR:Virtual
> ERROR: Test
> ERROR: Random
>
> I use:
>
> $ctError = `grep -ci error filename`;
>
> It gives 4
>
> Now i am trying to count error which doesnot contain Virtual, so i
> should get $ctError = 3. Is there any way possible to implement in the
> same line.
my $count = grep /ERROR:(?!\s*Virtual)/i, <$fh>;
Xicheng
------------------------------
Date: Tue, 11 Jul 2006 21:17:19 GMT
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Help with grep function
Message-Id: <lnu05ndeow.fsf@nuthaus.mib.org>
"Xicheng Jia" <xicheng@gmail.com> writes:
> Deepu wrote:
>> I am trying to count the number of errors in a file:
>>
>> ERROR: Display
>> ERROR:Virtual
>> ERROR: Test
>> ERROR: Random
>>
>> I use:
>>
>> $ctError = `grep -ci error filename`;
>>
>> It gives 4
>>
>> Now i am trying to count error which doesnot contain Virtual, so i
>> should get $ctError = 3. Is there any way possible to implement in the
>> same line.
>
> my $count = grep /ERROR:(?!\s*Virtual)/i, <$fh>;
Note that it's not really necessary to force everything into a single
regular expression. For example:
my $count = grep { /ERROR:/i && !/Virtual/i } <$fh>;
Or, if you want to be even more verbose:
my $count = 0;
while (<$fh>) {
if (/ERROR:/i and not /Virtual/i) {
$count ++;
}
}
Which approach you use is a matter of taste.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
------------------------------
Date: Tue, 11 Jul 2006 16:39:15 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help with grep function
Message-Id: <slrneb86k3.9bs.tadmc@magna.augustmail.com>
Deepu <pradeep.bg@gmail.com> wrote:
> I am trying to count the number of errors in a file:
> I use:
>
> $ctError = `grep -ci error filename`;
> Now i am trying to count error which doesnot contain Virtual,
$ctError = grep !/virtual/i, `grep -ci error filename`;
or, probably less confusing:
$ctError = grep !/virtual/i, qx/grep -ci error filename/;
Or don't use grep(1) at all, and do it all with (tricky) Perl:
perl -lne '$cnt++ if /error/i and not /virtual/i }{ print $cnt' filename
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 11 Jul 2006 21:37:15 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Inner classes, sort of?
Message-Id: <jvCdnbPvOtRmlinZRVny2w@pipex.net>
fishfry wrote:
>
> For reasons of encapsulation and object-purity and so forth, you don't
> want the caller to do that ... you'd rather have them write
>
> $name = $item->name();
For purity you probably don't want to do that either.
What you actually want to do tell the Object to perform an action on
each member of its list.
sub my_action {
my $item = shift;
....
}
my $l_obj = MyObject->new(.....);
$l_obj->send_items_to(\&my_action);
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: 11 Jul 2006 22:00:04 +0100
From: Lukas Ruf <ruf@rawip.org>
Subject: Re: processing large numbers/values/figures
Message-Id: <slrneb80q5.oqe.ruf@pc-4082.ethz.ch>
> Sisyphus [Tue, 11 Jul 2006 21:23:03 +1000]:
>
>
> "Lukas Ruf" <ruf@rawip.org> wrote in message
> news:slrneb6hbk.34l.ruf@pc-4082.ethz.ch...
> > > Abigail [10 Jul 2006 22:26:45 GMT]:
> > >
> >
> > thanks for answering,
> >
> > > Lukas Ruf (ruf@rawip.org) wrote on MMMMDCXCVI September MCMXCIII in
> > > <URL:news:slrneb55hc.kbb.ruf@pc-4082.ethz.ch>:
> >
> > >
> > > A Perl using 32-bit integers will automatically convert integers to
> > > floats. If you're dealing with numbers up to about 2**53, there
> shouldn't
> > > be any loss of precision.
> > >
> >
> > weird, why do I still get '-1' even when using 'bignum'?
> >
>
> Checkout 'perldoc -f sprintf' (which applies equally to the 'printf'
> function). There you'll find:
>
> %d a signed integer, in decimal
>
> Specifying "%d" is good for numbers up to 31 bits (plus the 'sign' bit) only
> on 32-bit systems (since that's the size of a signed integer). For larger
> numbers up to 2 ** 53 use "%f" (or "%.0f" if you want to avoid the decimal
> point) .... or you may find that simply using the 'print' function instead
> of the 'printf' function produces the output you want.
>
thanks. this solves my problem.
> It would probably help us to answer your questions about specific instances
> if you could provide a (*minimal*) script (copy'n'paste) that demonstrate
> the problem(s) - as opposed to code snippets and general descriptions.
>
ok. I understand.
wbr,
Lukas
--
Lukas Ruf <http://www.lpr.ch> | Ad Personam
rbacs <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP <http://www.rawip.org> | Low Level Network Programming
<http://lists.lpr.ch/muttprint> | muttprint mailing list
------------------------------
Date: 11 Jul 2006 22:00:49 +0100
From: Lukas Ruf <ruf@rawip.org>
Subject: Re: processing large numbers/values/figures
Message-Id: <slrneb80ri.oqe.ruf@pc-4082.ethz.ch>
> xhoster@gmail.com [11 Jul 2006 16:31:53 GMT]:
>
> You have a floating point number which is holding something which
> happens to be an integer which doesn't fit into a 32bit integer.
> Your %d field is coercing it into a 32 bit integer for formatting
> purposes, which does overflow. Print with a floating point format,
> not an integet format.
>
> printf "%20.f", 2**50; 1125899906842624
>
thanks! This, I have not known before.
wbr,
Lukas
--
Lukas Ruf <http://www.lpr.ch> | Ad Personam
rbacs <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP <http://www.rawip.org> | Low Level Network Programming
<http://lists.lpr.ch/muttprint> | muttprint mailing list
------------------------------
Date: 11 Jul 2006 22:01:17 +0100
From: Lukas Ruf <ruf@rawip.org>
Subject: Re: processing large numbers/values/figures
Message-Id: <slrneb80sd.oqe.ruf@pc-4082.ethz.ch>
> Tad McClellan [Tue, 11 Jul 2006 07:51:46 -0500]:
>
> Lukas Ruf <ruf@rawip.org> wrote:
>
> > $hsh{$key} += @record{$index};
>
>
> You should always enable warnings when developing Perl code.
>
meanwhile, I do.
wbr,
Lukas
--
Lukas Ruf <http://www.lpr.ch> | Ad Personam
rbacs <http://wiki.lpr.ch> | Restaurants, Bars and Clubs
Raw IP <http://www.rawip.org> | Low Level Network Programming
<http://lists.lpr.ch/muttprint> | muttprint mailing list
------------------------------
Date: Tue, 11 Jul 2006 20:10:58 GMT
From: Charles DeRykus <ced@blv-sam-01.ca.boeing.com>
Subject: Re: processing large numbers/values/figures
Message-Id: <J299EA.15A@news.boeing.com>
Lukas Ruf wrote:
>> Abigail [10 Jul 2006 22:26:45 GMT]:
>>
>
> thanks for answering,
>
>> Lukas Ruf (ruf@rawip.org) wrote on MMMMDCXCVI September MCMXCIII in
>> <URL:news:slrneb55hc.kbb.ruf@pc-4082.ethz.ch>:
>
>> A Perl using 32-bit integers will automatically convert integers to
>> floats. If you're dealing with numbers up to about 2**53, there shouldn't
>> be any loss of precision.
>>
>
> weird, why do I still get '-1' even when using 'bignum'?
>
Failure to read the docs... :)
perldoc -f printf:
Don't fall into the trap of using a "printf" when a simple
"print" would do.
The "print" is more efficient and less error prone.
Actually, Perl's printf is probably just passing back the underlying
library error even though bignum produces the correct result. On
Solaris's printf(3C) manpage, for example:
The printf(), fprintf(), and sprintf() functions return the
number of bytes transmitted (excluding the terminating null
byte in the case of sprintf()).
...
Each function returns a negative value if an output error
was encountered.
So, on 32-bit, you'll see:
use bignum;
my $x = 10*(2**40);
print "x = $x";
printf( "%d should be in the range up to 2**40\n", $x );
--> x = 10995116277760
-1 should be in the range up to 2**40
--
Charles DeRykus
------------------------------
Date: Tue, 11 Jul 2006 16:31:01 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: processing large numbers/values/figures
Message-Id: <slrneb864l.9bs.tadmc@magna.augustmail.com>
Lukas Ruf <ruf@rawip.org> wrote:
>> Tad McClellan [Tue, 11 Jul 2006 07:51:46 -0500]:
>>
>> Lukas Ruf <ruf@rawip.org> wrote:
>>
>> > $hsh{$key} += @record{$index};
>>
>>
>> You should always enable warnings when developing Perl code.
>>
>
> meanwhile, I do.
You should not ignore the warnings that perl emits when
developing Perl code.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 11 Jul 2006 21:00:36 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Results in multiple pages. Takes too much time
Message-Id: <44b3f554$0$872$ba4acef3@news.orange.fr>
premgrps@gmail.com wrote:
> Hi,
> I have a table of a million records and wrote a CGI-PERL script to
> display the results based on the user input. The results might be
> anywhere from 100 to 1000 per query and presently I am displaying them
> as 25 results per page.
>
> Problem: Each query is taking about 20-30 seconds.
>
> My solution: I have tried to optimize the table and also index the
> table. I have actually converted a MS access database to SQL database,
> so it wasn't previously indexed. Both optimization and indexing doesn't
> give any good results. I always get a timeout. ie. it takes longer
> after indexing and optimizing.
>
> 1. I was wondering if someone has a creative solution for this. ie.
> reduce the time from 20-30 seconds to atleast 10 seconds.
>
> 2. I have links of pages of results beneath the first page result. When
> each of these links are clicked it takes 20-30 seconds again. Is there
> a way I can reduce the time taken for the subsequent pages are reduced?
> I cannot use the LIMIT option in mysql, since I have a where clause
> which has to search through the whole table. I tried using views and
> using limits, but it takes as much time.
>
At first glance, this is more of a MySQL question than a Perl question.
How long does a typical query take if executed at the MySQL prompt? What
happens when you prefix the query with EXPLAIN? You may find you don't
have all the indexes you need.
If the query doesn't run fast by itself, no amount of tuning in Perl is
going to help.
Mark
------------------------------
Date: Tue, 11 Jul 2006 20:11:34 GMT
From: Tim Hammerquist <penryu@saiyix.ath.cx>
Subject: Re: Results in multiple pages. Takes too much time
Message-Id: <slrneb81fm.l9o.penryu@ruri.saiyix>
premgrps@gmail.com <premgrps@gmail.com> wrote:
> I have a table of a million records and wrote a CGI-PERL script to
> display the results based on the user input. The results might be
> anywhere from 100 to 1000 per query and presently I am displaying
> them as 25 results per page.
>
> Problem: Each query is taking about 20-30 seconds.
>
> My solution: I have tried to optimize the table and also index the
> table. I have actually converted a MS access database to SQL
> database, so it wasn't previously indexed. Both optimization and
> indexing doesn't give any good results. I always get a timeout. ie.
> it takes longer after indexing and optimizing.
>
> 1. I was wondering if someone has a creative solution for this. ie.
> reduce the time from 20-30 seconds to atleast 10 seconds.
>
> 2. I have links of pages of results beneath the first page result.
> When each of these links are clicked it takes 20-30 seconds again.
> Is there a way I can reduce the time taken for the subsequent pages
> are reduced? I cannot use the LIMIT option in mysql, since I have
> a where clause which has to search through the whole table. I tried
> using views and using limits, but it takes as much time.
This is all SQL-related information. X-posting an SQL problem to
a computer language group doesn't help anyone.
Other information that might be helpful might include: number of
records in the table being queried; number of tables/joins/etc used to
generate queries; available memory on both the database server *and*
the web server.
And, the most important thing to post to a programming newsgroup:
as much actual and relevant code as necessary to produce the results
discussed.
It might be possible the CGI script is causing a significant portion
of your delay. If so, we need Perl code before we can help. If not,
then this is off-topic and doesn't belong here.
Cheers,
Tim Hammerquist
------------------------------
Date: 11 Jul 2006 13:28:43 -0700
From: eurosnob@gmail.com
Subject: RSS feeds and HTML special characters
Message-Id: <1152649723.425216.41580@h48g2000cwc.googlegroups.com>
If this isn't the right place to post this, please point me in the
right direction?
I'm a relatively casual Perl programmer trying to implement an RSS feed
into my personal site. I've got it working using a slightly modified
example from the O'Reilly book (content syndication with RSS), but for
one annoying caveat...
If I load the feed in, say, Firefox, a title might look like this:
<title>This Artist is Good - Frank D'Armata</title>
When I use "View Source," the title string is actually:
<title>This Artist is Good - Frank D’Armata</title>
However, when I go to use the string from within Perl, I get a Warning,
"Wide character in print", and giberish printed where the special
character sits:
This Artist is Good - Frank D=E2=80=99Armata
(That's a lowercase 'a' with an accent, the Euro symbol, and the
trademark symbol, between D and Armata.)
I'm sure there's a relatively simple fix, but I'm kind of lost at this
point... Help?!
Thanks!
------------------------------
Date: Wed, 12 Jul 2006 00:03:53 +0300
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: Re: Using References to Formats, Examining Scalars With Devel::Peek
Message-Id: <e913nr$373$1@news.oulu.fi>
Hi,
Replying a bit late and slightly out-of-order, too.
attn.steven.kuo@gmail.com wrote:
I wrote:
>> To make format references useful at all, I suppose one would have to be
>> able to dereference them somehow. IS that possible, and if so how?
> Well, just use another typeglob for dereferencing.
>
>> sub writeForm
>> { # Write out the specified format.
>> local $~ = shift;
>> write;
>> } # sub
>
> becomes:
>
> use Scalar::Utiil ('reftype');
>
> sub writeForm {
> if (reftype $_[0] and reftype $_[0] eq 'FORMAT') {
> local *FOO;
> *FOO = $_[0];
> local $~ = 'FOO';
> write;
> } else {
> local $~ = shift;
> write;
> }
> }
Hey, thanks for the code. Works fine for me. Somehow aliasing the name of
the format to be able to refer to it by another name didn't occur to me. But
as the built-in functions seem to support using a stringified scalar as a
format name, I doubt if using format refs have any benefits at all. It just
serves to make the syntax more gory, eh. No wonder they haven't been
documented propperly.
> You can use Devel::Peek instead of Data::Dumper
> if you want to look at the guts of a format reference.
Ah, nice. Seems most of the fields are the same as for the rest of the Perl
data types. The Peek module can be quite handy, I think. I initially
overlooked it, when going through all the built-in modules that semed
interesting, because the title talks about XS and I'm not ready to tackle it
yet.
Your note about the function got me playing around with other Perl variables
and browsing PErlguts to understand at a high level what's going on behind
the scenes.
In particular, I've been tracking when exactly scalars change their datatype
from integer to double and how frequently the string portions are updated.
Again I don't think even Perlguts covers the rules but I might be wrong, as
I didn't read it all through.
I've only experimented a little but it would seem to me that:
- Perl is pretty smart in keeping integer values integers. Even if you add
and subtract doubles you might still end up with an integer value, if the
result happens to fit exactly to an int.
- Using an operator or a built-in with a double and an int usually converts
the int to a double if you assign the result to a variable. THis is natural,
of course.
- There don't seme to be many instances in which variables which are now
doubles would be converted to ints. Even the int function doesn't do that,
if I'm interpreting these funny type abbreviations right.
- Perl appears to update all but the most recent types lazily. Sometimes the
string or double values can lag behind considerably. They do get updated
when current values for the types are needed such as in stringification or
calling functions taking doubles.
--
With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/
------------------------------
Date: Tue, 11 Jul 2006 19:21:14 GMT
From: David Hopwood <david.nospam.hopwood@blueyonder.co.uk>
Subject: Re: What is a type error?
Message-Id: <KSSsg.307978$8W1.277237@fe1.news.blueyonder.co.uk>
George Neuner wrote:
> On Tue, 11 Jul 2006 14:59:46 GMT, David Hopwood
> <david.nospam.hopwood@blueyonder.co.uk> wrote:
>
>>What matters is that, over the range
>>of typical programs written in the language, the value of the increased
>>confidence in program correctness outweighs the effort involved in both
>>adding annotations, and understanding whether any remaining run-time checks
>>are guaranteed to succeed.
>
> Agreed, but ...
>
>>Look at it this way: suppose that I *need* to verify that a program has
>>no range errors. Doing that entirely manually would be extremely tedious.
>>If the compiler can do, say, 90% of the work, and point out the places that
>>need to be verified manually, then that would be both less tedious, and
>>less error-prone.
>
> All of this presupposes that you have a high level of confidence in
> the compiler. I've been in software development for going in 20 years
> now and worked 10 years on high performance, high availability
> systems. In all that time I have yet to meet a compiler ... or
> significant program of any kind ... that is without bugs, noticeable
> or not.
That's a good point. I don't think it would be an exaggeration to say
that the some of the most commonly used compilers are riddled with bugs.
gcc is a particularly bad offender, and at the moment seems to be introducing
bugs with each new version at a faster rate than they can be fixed. Sun's
javac also used to be poor in this respect, although I haven't used recent
versions of it.
One of the main reasons for this, IMHO, is that many compilers place too
much emphasis on low-level optimizations of dubious merit. For C and
Java, I've taken to compiling all non-performance-critical code without
optimizations, and that has significantly reduced the number of compiler
bugs that I see. It has very little effect on overall execution performance
(and compile times are quicker).
I don't think that over-complex type systems are the cause of more than a
small part of the compiler bug problem. In my estimation, the frequency of
bugs in different compilers *for the same language* can vary by an order of
magnitude.
> I'm a fan of static typing but the major problem I have with complex
> inferencing (in general) is the black box aspect of it. That is, when
> the compiler rejects my code, is it really because a) I was stupid, b)
> the types are too complex, or c) the compiler itself has a bug.
Rejecting code incorrectly is much less of a problem than accepting it
incorrectly. *If* all compiler bugs were false rejections, I would say that
this would not be too much of an issue.
Unfortunately there are plenty of bugs that result in silently generating
bad code. But I don't think you can avoid that by using a language with a
simpler type system. The quality of a compiler depends much more on the
competence and attitudes of the language implementation developers, than
it does on the language itself.
[Although, choosing a language with a more quality-conscious compiler
development team doesn't necessarily help if it is compiling to C, since
then you still have to deal with C compiler bugs, but on autogenerated
code :-(.]
> It's certainly true that the vast majority of my problems are because
> I'm stupid, but I've run into actual compiler bugs far too often for my
> liking (high performance coding has a tendency to uncover them).
Yes. Cryptographic algorithms, and autogenerated code also tend to do that.
> I think I understand how to implement HM inferencing ... I haven't
> actually done it yet, but I've studied it and I'm working on a toy
> language that will eventually use it. But HM itself is a toy compared
> to an inferencing system that could realistically handle some of the
> problems that were discussed in this and Xah's "expressiveness" thread
> (my own beef is with *static* checking of range narrowing assignments
> which I still don't believe can be done regardless of Chris Smith's
> assertions to the contrary).
>
> It seems to me that the code complexity of such a super-duper
> inferencing system would make its bug free implementation quite
> difficult and I personally would be less inclined to trust a compiler
> that used it than one having a less capable (but easier to implement)
> system.
I don't think that the complexity of such a system would need to be
any greater than that of the optimization frameworks used by many
compilers. IIUC, what Chris Smith is suggesting is essentially equivalent
to doing type inference on the SSA form of the program.
--
David Hopwood <david.nospam.hopwood@blueyonder.co.uk>
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9450
***************************************