| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"len v" |
| Date: |
19 Oct 2003 07:53:58 PM |
| Object: |
C vs Perl |
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.( http://homepage.mac.com/billamend/images/patch.gif )
To see the comparison, go to ---> http://perl.hacker.freeservers.com/
.
|
|
| User: "Joona I Palaste" |
|
| Title: Re: C vs Perl |
20 Oct 2003 12:30:58 PM |
|
|
len v <ccya86@yahoo.com> scribbled the following
on comp.lang.c:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.( http://homepage.mac.com/billamend/images/patch.gif )
To see the comparison, go to ---> http://perl.hacker.freeservers.com/
Yes, and I could implement a language called FoxTrot that would have the
following program:
Do it
translate into code that wrote "I will not throw paper airplanes in
class" 500 times into stdout. But I wouldn't guarantee FoxTrot would be
useful for anything else.
IOW, one-off cases like these are useless for comparing elegance of
languages.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
.
|
|
|
| User: "len v" |
|
| Title: Re: C vs Perl |
20 Oct 2003 07:07:01 PM |
|
|
"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
news:bn164i$qho$1@oravannahka.helsinki.fi...
len v <ccya86@yahoo.com> scribbled the following
on comp.lang.c:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing me
to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.(
ttp://homepage.mac.com/billamend/images/patch.gif )
To see the comparison, go to ---> http://perl.hacker.freeservers.com/
Yes, and I could implement a language called FoxTrot that would have the
following program:
Do it
translate into code that wrote "I will not throw paper airplanes in
class" 500 times into stdout. But I wouldn't guarantee FoxTrot would be
useful for anything else.
IOW, one-off cases like these are useless for comparing elegance of
languages.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
I see your point and that is exactly what Perl is all about. If your
FoxTrot implementation had something to offer the community then FoxTrot
would be added to Perl.
Perhaps you could help me out? I've been trying to remember my C and C++
code, it's been about 5 years. How do I swap the values of 2 strings?
.
|
|
|
| User: "=?iso-8859-1?Q?Juli=E1n?= Albo" |
|
| Title: Re: C vs Perl |
21 Oct 2003 01:19:18 AM |
|
|
len v escribi=F3:
Yes, and I could implement a language called FoxTrot that would have =
the
following program:
Do it
(...)
I see your point and that is exactly what Perl is all about. If your
FoxTrot implementation had something to offer the community then FoxTro=
t
would be added to Perl.
Something like...?
#!/usr/bin/perl
use Bizarre::FoxTrot;
Do it;
Regards.
.
|
|
|
|
| User: "Jirka Klaue" |
|
| Title: Re: C vs Perl |
20 Oct 2003 08:33:21 PM |
|
|
len v wrote:
....
Perhaps you could help me out? I've been trying to remember my C and C++
code, it's been about 5 years. How do I swap the values of 2 strings?
Could you define "value of string", please?
Jirka
.
|
|
|
| User: "len v" |
|
| Title: Re: C vs Perl |
20 Oct 2003 09:02:31 PM |
|
|
"Jirka Klaue" <jklaue@ee.tu-berlin.de> wrote in message
news:bn229k$bov$1@mamenchi.zrz.TU-Berlin.DE...
len v wrote:
...
Perhaps you could help me out? I've been trying to remember my C and C++
code, it's been about 5 years. How do I swap the values of 2 strings?
Could you define "value of string", please?
Jirka
Sure --
I was using a string (scalar) as an example, it could be any two basic types
(ex: int's, char's, float's, reference's, arrays etc.) However, in keeping
with the original question:
CString m_firstName;
CString m_lastName;
put the value of (contents of, address of) m_firstName in m_lastName and put
m_lastName in m_firstName.
Regards
Len
.
|
|
|
| User: "Jirka Klaue" |
|
| Title: Re: C vs Perl |
20 Oct 2003 09:11:59 PM |
|
|
len v wrote:
Could you define "value of string", please?
....
Sure --
....
CString m_firstName;
CString m_lastName;
There is no CString in C, C++ or Perl.
To clarify my question:
char a[] = "C", b[] = "C++";
char *a = "C", *b = "C++";
Are a and b strings? What are their values?
How would *you* swap their "values"?
Jirka
.
|
|
|
| User: "len v" |
|
| Title: Re: C vs Perl |
20 Oct 2003 09:45:13 PM |
|
|
"Jirka Klaue" <jklaue@ee.tu-berlin.de> wrote in message
news:bn24i2$djm$1@mamenchi.zrz.TU-Berlin.DE...
len v wrote:
Could you define "value of string", please?
...
Sure --
...
CString m_firstName;
CString m_lastName;
There is no CString in C, C++ or Perl.
To clarify my question:
char a[] = "C", b[] = "C++";
char *a = "C", *b = "C++";
Are a and b strings? What are their values?
How would *you* swap their "values"?
Jirka
Perhaps I'm not reading it correctly:
http://support.microsoft.com/default.aspx?scid=kb;en-us;111923
A string would be a scalar. In Perl it would be $a and $b
http://www.perl.com/pub/a/2000/11/begperl2.html No need to declare the
type. Scalars can be a numbers, text, references to a scalar, references to
an array, or references to a hash, or references to a sub (a function or
method). And no need to pre-declare the variable prior to its' use.
Example of strings (scalars) in Perl:
$a = 'C';
$b = 'C++';
$tmp = $a;
$a = $b;
$b = $tmp;
However this is too much work for me, so I was thinking more like:
$a = 'C';
$b = 'C++';
($a, $b) = ($b, $a);
or
($a, $b) = ('C', 'C++');
($a, $b) = ($b, $a);
Regards
Len
.
|
|
|
| User: "Jirka Klaue" |
|
| Title: Re: C vs Perl |
20 Oct 2003 09:57:07 PM |
|
|
len v wrote:
There is no CString in C, C++ or Perl.
....
Perhaps I'm not reading it correctly:
http://support.microsoft.com/default.aspx?scid=kb;en-us;111923
CString is part of MFC which is *not* part of C++.
Ever heard of std::string?
Example of strings (scalars) in Perl:
$a = 'C';
$b = 'C++';
$tmp = $a;
$a = $b;
$b = $tmp;
However this is too much work for me, so I was thinking more like:
$a = 'C';
$b = 'C++';
($a, $b) = ($b, $a);
or
($a, $b) = ('C', 'C++');
($a, $b) = ($b, $a);
std::swap(a, b);
Jirka
.
|
|
|
| User: "len v" |
|
| Title: Re: C vs Perl |
20 Oct 2003 10:02:12 PM |
|
|
"Jirka Klaue" <jklaue@ee.tu-berlin.de> wrote in message
news:bn276m$f2c$1@mamenchi.zrz.TU-Berlin.DE...
len v wrote:
There is no CString in C, C++ or Perl.
...
Perhaps I'm not reading it correctly:
http://support.microsoft.com/default.aspx?scid=kb;en-us;111923
CString is part of MFC which is *not* part of C++.
Ever heard of std::string?
Example of strings (scalars) in Perl:
$a = 'C';
$b = 'C++';
$tmp = $a;
$a = $b;
$b = $tmp;
However this is too much work for me, so I was thinking more like:
$a = 'C';
$b = 'C++';
($a, $b) = ($b, $a);
or
($a, $b) = ('C', 'C++');
($a, $b) = ($b, $a);
std::swap(a, b);
Jirka
That is what I'm looking for. Thank you
.
|
|
|
|
|
|
|
|
|
|
|
| User: "Programmer Dude" |
|
| Title: Re: C vs Perl |
20 Oct 2003 04:24:19 PM |
|
|
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking
causing me to edit the origional comic.
"Origional" ??
--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|_______________________|
.
|
|
|
| User: "Joe Wright" |
|
| Title: Re: C vs Perl |
20 Oct 2003 06:42:42 PM |
|
|
Programmer Dude wrote:
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking
causing me to edit the origional comic.
"Origional" ??
--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|_______________________|
I just hate spilling errors.
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
.
|
|
|
| User: "len v" |
|
| Title: Re: C vs Perl |
20 Oct 2003 06:55:22 PM |
|
|
"Joe Wright" <joewwright@earthlink.net> wrote in message
news:3F9472F6.77BA@earthlink.net...
Programmer Dude wrote:
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking
causing me to edit the origional comic.
"Origional" ??
--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|_______________________|
I just hate spilling errors.
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Note to self. Find spell checker for vi.
Looks like I spelled it wrong on the web site too. I've always maintained
that a programmer does not have to spell correctly, just consistent, either
right or wrong - the syntax checker does not care.
.
|
|
|
| User: "Noah Roberts" |
|
| Title: Re: C vs Perl |
20 Oct 2003 10:14:17 PM |
|
|
len v wrote:
Note to self. Find spell checker for vi.
Looks like I spelled it wrong on the web site too. I've always maintained
that a programmer does not have to spell correctly, just consistent, either
right or wrong - the syntax checker does not care.
My compiler really doesn't like it when I spell freind wrong.
--
Noah Roberts
- "If you are not outraged, you are not paying attention."
.
|
|
|
| User: "Keith Thompson" |
|
| Title: Re: C vs Perl |
22 Oct 2003 08:50:04 PM |
|
|
Noah Roberts <nroberts@dontemailme.com> writes:
len v wrote:
Note to self. Find spell checker for vi.
Looks like I spelled it wrong on the web site too. I've always
maintained
that a programmer does not have to spell correctly, just consistent, either
right or wrong - the syntax checker does not care.
My compiler really doesn't like it when I spell freind wrong.
Mine doesn't care.
--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
.
|
|
|
|
|
| User: "Programmer Dude" |
|
| Title: Re: C vs Perl |
21 Oct 2003 12:06:34 PM |
|
|
len v wrote:
...causing me to edit the origional comic.
"Origional" ??
Looks like I spelled it wrong on the web site too.
That was why I mentioned it. (-:
I've always maintained that a programmer does not have to spell
correctly, just consistent, either right or wrong - the syntax
checker does not care.
I would disagree. For many reasons.
Comments, tech docs, communicating effectively with others.....
--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|_______________________|
.
|
|
|
| User: "W K" |
|
| Title: Re: C vs Perl |
21 Oct 2003 12:38:24 PM |
|
|
"Programmer Dude" <Chris@Sonnack.com> wrote in message
news:3F95679A.8E6C8487@Sonnack.com...
len v wrote:
...causing me to edit the origional comic.
"Origional" ??
Looks like I spelled it wrong on the web site too.
That was why I mentioned it. (-:
I've always maintained that a programmer does not have to spell
correctly, just consistent, either right or wrong - the syntax
checker does not care.
I would disagree. For many reasons.
Comments, tech docs, communicating effectively with others.....
They're all dyslexic too, so it doesn't matter.
.
|
|
|
|
|
|
|
|
| User: "Noah Roberts" |
|
| Title: Re: C vs Perl |
19 Oct 2003 08:03:11 PM |
|
|
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.( http://homepage.mac.com/billamend/images/patch.gif )
To see the comparison, go to ---> http://perl.hacker.freeservers.com/
Where is the C++ version? I don't see it.
--
Noah Roberts
- "If you are not outraged, you are not paying attention."
.
|
|
|
| User: "red floyd" |
|
| Title: Re: C vs Perl |
20 Oct 2003 01:37:22 AM |
|
|
Noah Roberts wrote:
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing
me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.(
http://homepage.mac.com/billamend/images/patch.gif )
To see the comparison, go to ---> http://perl.hacker.freeservers.com/
Where is the C++ version? I don't see it.
Don't know, but the original C code had an error. There was no new line, so it
would output the following;
I will not throw paper airplanes in class.I will not throw paper airplanes in
class.I will not....
Oh, here's a C++ version
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<string> v(500,string("I will not throw paper airplanes in class."));
copy(v.begin(), v.end(), ostream_iterator(cout,"\n"));
return 0;
}
.
|
|
|
| User: "len v" |
|
| Title: Re: C vs Perl |
20 Oct 2003 05:54:54 PM |
|
|
"red floyd" <no.spam@here.dude> wrote in message
news:CoLkb.126$lK4.4@newssvr14.news.prodigy.com...
Noah Roberts wrote:
len v wrote:
A recent (Oct 3) Fox Trox comic (Bill Amend ) got me thinking causing
me to
edit the origional comic. Bill then had to write a patch, as most C
programers must do.(
http://homepage.mac.com/billamend/images/patch.gif )
To see the comparison, go to ---> http://perl.hacker.freeservers.com/
Where is the C++ version? I don't see it.
Don't know, but the original C code had an error. There was no new line,
so it
would output the following;
I will not throw paper airplanes in class.I will not throw paper airplanes
in
class.I will not....
Oh, here's a C++ version
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<string> v(500,string("I will not throw paper airplanes in
class."));
copy(v.begin(), v.end(), ostream_iterator(cout,"\n"));
return 0;
}
The author of the comic received the same ridicule regarding the
error.... --> http://homepage.mac.com/billamend/ Half way down you will
find his patch.
umm.... I don't think I can fit the c++ version on the chalk board.
.
|
|
|
| User: "red floyd" |
|
| Title: Re: C vs Perl |
20 Oct 2003 06:00:41 PM |
|
|
len v wrote:
[redacted]
umm.... I don't think I can fit the c++ version on the chalk board.
What about Julian Albo's (sorry Julian, don't know how to put the accent on in Moz...)?
His is three lines shorter:
doesn't need #include <vector>
uses the implicit return 0 from main
doesn't need to declare the vector I used
Would that fit? :)
.
|
|
|
| User: "len v" |
|
| Title: Re: C vs Perl |
20 Oct 2003 06:59:24 PM |
|
|
"red floyd" <no.spam@here.dude> wrote in message
news:tOZkb.3605$A8.42264712@newssvr21.news.prodigy.com...
len v wrote:
[redacted]
umm.... I don't think I can fit the c++ version on the chalk board.
What about Julian Albo's (sorry Julian, don't know how to put the accent
on in Moz...)?
His is three lines shorter:
doesn't need #include <vector>
uses the implicit return 0 from main
doesn't need to declare the vector I used
Would that fit? :)
That just might do it. I'll try and repost the link.
I wonder if I could fit COBOL, Fortran or Java code in there too. Ouch. My
brain just started to hurt. It's been awhile.
.
|
|
|
|
|
|
| User: "Serve La" |
|
| Title: Re: C vs Perl |
20 Oct 2003 12:37:19 PM |
|
|
"red floyd" <no.spam@here.dude> wrote in message
news:CoLkb.126$lK4.4@newssvr14.news.prodigy.com...
Oh, here's a C++ version
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<string> v(500,string("I will not throw paper airplanes in
class."));
copy(v.begin(), v.end(), ostream_iterator(cout,"\n"));
return 0;
}
Hmm, there's more includes than lines, what's the world coming to :-)
.
|
|
|
|
| User: "=?iso-8859-1?Q?Juli=E1n?= Albo" |
|
| Title: Re: C vs Perl |
20 Oct 2003 10:15:25 AM |
|
|
red floyd escribi=F3:
Oh, here's a C++ version
=
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
=
int main()
{
vector<string> v(500,string("I will not throw paper airplanes in c=
lass."));
copy(v.begin(), v.end(), ostream_iterator(cout,"\n"));
return 0;
}
Mine is better ;)
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
int main ()
{
fill_n (ostream_iterator <string> (cout, "\n"),
500, string ("I will not throw paper airplanes in
class") );
}
Regards.
.
|
|
|
| User: "Jerry Coffin" |
|
| Title: Re: C vs Perl |
21 Oct 2003 10:53:25 AM |
|
|
In article <3F93FC0D.3F109F27@terra.es>, says...
[ ... ]
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
int main ()
{
fill_n (ostream_iterator <string> (cout, "\n"),
500, string ("I will not throw paper airplanes in
class") );
}
std::string supports implicit conversions from C strings, so this can be
reduced a bit further:
#include <ostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
int main ()
{
fill_n (ostream_iterator <string> (cout, "\n"),
500, "I will not throw paper airplanes in class");
}
Also note that I've included <ostream> instead of <iostream> --
including <iostream> _usually_ declares std::cout, but isn't required
to.
--
Later,
Jerry.
The universe is a figment of its own imagination.
.
|
|
|
| User: "Micah Cowan" |
|
| Title: Re: C vs Perl |
22 Oct 2003 05:22:20 PM |
|
|
Jerry Coffin <jcoffin@taeus.com> writes:
Also note that I've included <ostream> instead of <iostream> --
including <iostream> _usually_ declares std::cout, but isn't required
to.
This is a bizarre statement. Perhaps you meant the other way
around, but that doesn't make much sense either. Read your
standard, and try again.
#include <iostream>
Is *guaranteed* to declare as follows:
namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;
extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
}
It has not been my experience that ostream "usually" declares
std::cout at all; and it certainly isn't required to.
I'd have fixed the cross-post, except that I didn't want people
who are only reading alt.comp.lang.c and comp.lang.c to come away
with the wrong idea, either. Followups have been fixed.
--
Micah Cowan
micah@cowan.name
.
|
|
|
| User: "Jerry Coffin" |
|
| Title: Re: C vs Perl |
22 Oct 2003 08:22:49 PM |
|
|
In article <m365iggbfn.fsf@localhost.localdomain>,
says...
[ ... ]
This is a bizarre statement.
Oh, come on. I can take a bit of honesty: what I said wasn't bizarre --
it just plain wrong!
--
Later,
Jerry.
The universe is a figment of its own imagination.
.
|
|
|
|
|
| User: "=?iso-8859-1?Q?Juli=E1n?= Albo" |
|
| Title: Re: C vs Perl |
21 Oct 2003 12:13:26 PM |
|
|
Jerry Coffin escribi=F3:
int main ()
{
fill_n (ostream_iterator <string> (cout, "\n"),
500, string ("I will not throw paper airplanes in
class") );
}
=
std::string supports implicit conversions from C strings, so this can b=
e
reduced a bit further:
True. I was under the impression that implicit conversion will not allow
correct template argument deduction, but not.
Also note that I've included <ostream> instead of <iostream> --
including <iostream> _usually_ declares std::cout, but isn't required
to.
True again. My bad habit.
Regards.
.
|
|
|
|
| User: "Kevin Goodsell" |
|
| Title: Re: C vs Perl |
21 Oct 2003 01:01:27 PM |
|
|
Jerry Coffin wrote:
Also note that I've included <ostream> instead of <iostream> --
including <iostream> _usually_ declares std::cout, but isn't required
to.
The C++ standard appears to require std::cout be declared in <iostream>:
27.3 Standard iostream objects [lib.iostream.objects]
Header <iostream> synopsis
namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;
extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
}
As far as I know, the thing that people usually assume is in iostream
which is technically not required to be is std::endl - though I believe
this is considered a defect.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
.
|
|
|
| User: "Jerry Coffin" |
|
| Title: Re: C vs Perl |
22 Oct 2003 11:11:56 AM |
|
|
In article <Xvelb.73$I04.14@newsread4.news.pas.earthlink.net>,
usenet1.spamfree.fusion@neverbox.com says...
[ ... ]
The C++ standard appears to require std::cout be declared in <iostream>:
Oops -- you're absolutely right. My apologies for the incorrect post.
--
Later,
Jerry.
The universe is a figment of its own imagination.
.
|
|
|
|
|
|
| User: "Stephen M. Webb" |
|
| Title: Re: C vs Perl |
21 Oct 2003 12:01:22 PM |
|
|
Julián Albo <JULIANALBO@terra.es> wrote in message news:<3F93FC0D.3F109F27@terra.es>...
red floyd escribi :
Oh, here's a C++ version
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<string> v(500,string("I will not throw paper airplanes in c
lass."));
copy(v.begin(), v.end(), ostream iterator(cout,"\n"));
return 0;
}
Mine is better ;)
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
int main ()
{
fill n (ostream iterator <string> (cout, "\n"),
500, string ("I will not throw paper airplanes in
class") );
}
Feh.
#include <iostream>
struct C {
C() { std::cout << "I will not throw paper airplanes in class\n"; }
} c[500];
int main() { return 0; }
Why resort to complexity? Brevity is the soul of wit.
--
Stephen M. Webb
.
|
|
|
|
|
|
|

|
Related Articles |
|
|