l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
January 6: Social gathering
Next Installfest:
TBD
Latest News:
Nov. 18: Club officer elections
Page last updated:
2001 Dec 30 17:05

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] A question of perl style
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] A question of perl style


  • Subject: Re: [vox-tech] A question of perl style
  • From: Micah Cowan <micah@cowanboMAPSx.com>
  • Date: Tue, 01 May 2001 10:11:13 -0700
  • References: 20010430181706.11026.qmail@web4903.mail.yahoo.com
  • References: 20010430112528.A13682@mcowan-linux.transmeta.com
  • References: 20010430154253.C3597@houseag.com

On Mon, Apr 30, 2001 at 03:42:53PM -0700, Henry House wrote:

> Pointers are variables that don't hold interesting data, but instead hold the
> address in the machine's memory where the interesting data may be found. The
> main value in this is that you can (1) dynamically store any amount of data,
> limited only by available memory, organized however you like, and (2) you can
> pass large chunks of data around without the inefficiency of making a
> complete copy.
> 
> References in Perl are a safer version of C pointers. While (1) above is a
> nonissue in perl, (2) is essential for most serious programming. Hence the
> need to use references in Perl.

I find that many (more or less newer) Perl programmers - even ones
with a good deal of C experience, often don't think about (2) very
much.  Especially since Perl is so efficient you often don't realize
when you're taking significantly much more time on copying something
than you would if you were passing by reference.

One thing I kind of miss in Perl is C and C++'s const qualifier -
particularly with respect to lists of lists.  Because with lists of
lists, you are guaranteed that copying a list will end you up with a
new list of references to the very same original sublists - and
modifying the contents of one of these could change the original's
value as well.

In C, 

const int foo[10][10][10];

would create a multidimensional array which can not be altered (or at
least, you're promising the compiler that you won't).

Perl's LOLs really aren't anything at all like C's multidimensional
arrays, though - the analogy in C would be more like:

const int * const * const * const foo;

(const pointer to const pointer to const pointer to const int)

But you can't do anything like that in Perl.  When Henry's (2) is the
only reason for passing references, in C I'd usually carefully
cosnt-qualify the thing, but in Perl you just can't.

This is pretty much my only beef with Perl, which I still love anyway:
Both C and Perl give you quite a lot of freedom and power (though C
gives it to you a bit faster, but requires extra effort generally) -
but only C really gives you the power to carefully structure your code
so that "code accidents" are more easily spotted.

For this reason, I really wouldn't consider using Perl much for large
projects, no matter how much text processing, etc. was involved - it'd
take me longer in C, but I'd be much more sure of the quality of my
program.


- Just another mindless rant from your friendly neighborhood Micah :)


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.