Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Indispensible language features

by FoxtrotUniform (Prior)
on Jun 30, 2004 at 22:28 UTC ( #370928=perlmeditation: print w/ replies, xml ) Need Help??

I've been thinking a bit lately about the language features that I find indispensible: that is, if I'm hacking about in a language that doesn't have one of these, I either implement it right away, if possible, or miss it terribly and grumble about its absence.

My "must-have" feature list is, in part:

If I spend much more time playing around with Haskell, I'll probably want to add argument pattern-matching, lazy evaluation (Update 2004/07/01: including non-strictness, of course), and currying to that list.

It's interesting (although not too surprising) to me that my list of must-have features has changed so much in the past few years: back then, I'd probably have listed such low-level arcana as predictable memory layouts and pointer arithmetic. Back then, though, I was doing a lot of bare-metal C hacking; these days, I'm much more interested in functional programming.

It's admirable that Perl gives me what I want, and usually with at most as much fuss as any other language would (although sub {...} for lambdas is a bit verbose).

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
% man 3 strfry

Comment on Indispensible language features
Select or Download Code
Re: Indispensible language features
by theorbtwo (Prior) on Jun 30, 2004 at 23:08 UTC

    I find it amazing that you find five characters (the space is optional) for lambdas too long -- heck, the proper name of the feature is longer then that. OTOH, while I find them useful from time to time, they aren't a basic feature of my code often.

    OTOH, I would include the ability to do predictable memory layouts and pointer arithmetic as at least something that is very nice to have. OTOH, perl has these, via pack.

    I wouldn't inlcude higher-order functions on my list because they are a neccessary side-effect of coderefs as far as I can tell.

    On the other hand, I would include a CPAN, or something close to it... but I would also note that I consider apt-get, and even similar (but worse) repositories of other distributions, close enough to CPAN to count, at least for C and C++. Freshmeat and even sourceforge are also vaugely close.

    Easy foreaches are also important, even across somewhat abstract list-like things, which leaves out C, C++, and Java, so far as I know.

    Really, though, the number one requirement for a language (beyond obvious stuff like turing-completeness) is hashes.

      Easy foreaches are also important . . . which leaves out C, C++, and Java

      Java now has a foreach-like construct.

      beyond obvious stuff like turing-completeness

      I dunno. I think you could get some pretty nifty stuff in a language which isn't TC. Maybe it wouldn't work for general programming, but it may solve a specific problem domain very well.

      Which is why I'm more interested in Parrot than Perl6, but that's another issue.

      ----
      send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

        The C++ STL also has std::for_each(), so I guess that just leaves C.
      I find it amazing that you find five characters (the space is optional) for lambdas too long -- heck, the proper name of the feature is longer then that.

      I've given this a bit of thought: it's not so much the sub {...} part that I find verbose as the fact that I can't bind variables in a convenient way: I either have to use up keystrokes with a my ($x,$y,$z) = @_; at the front of the lambda, or constantly index @_ (which looks awful).

      For instance, in Haskell the "zip" function (take a pair of lists and return a list of pairs) is defined as:

      zip = zipWith (\x y -> (x,y))
      (What's important here is the lambda.) In Perl, assuming an equivalent zipWith, you'd have to say:
      zipWith {[$_[0], $_[1]]} @foo, @bar; # or: zipWith {($a,$b)=@_;[$a,$b]} @foo, @bar; # or: zipWith {[unshift,unshift]} @foo, @bar;
      none of which looks as pretty. That's more a matter of opinion, of course.

      --
      F o x t r o t U n i f o r m
      Found a typo in this node? /msg me
      % man 3 strfry

        I agree, none of those are pretty. In Perl 6 you can also use either of:
        zipWith {[$^a, $^b]} @foo, @bar;
        or
        zipWith -> $a, $b {[$a,$b]} @foo, @bar;
        But then, your entire OP reads a bit like an ad for Perl 6... :-)
Re: Indispensible language features
by runrig (Abbot) on Jul 01, 2004 at 00:21 UTC

    I don't know how I ever got along without hashes. Well, I do, but it wasn't pretty. It still isn't. In the statically typed language I'm forced to work with, 'associative array'-like classes have been added, but they are less than robust. You have to have one class for numeric keys and string values, another for string keys and string values, and ... you get the idea (if you need multidimensional hashes, just bang your head against the wall...you'll forget that you needed them in the first place :).

    Another feature I appreciate is variable length argument lists for functions. More than once I've wanted to add an optional argument to a function, but don't want to change every call to the function.

Re: Indispensible language features
by jZed (Prior) on Jul 01, 2004 at 00:41 UTC
    Indispensible things perl has: CPAN, Perlmonks, good mottoes, an inventor with both a sense of humour and a sense of style.
Re: Indispensible language features
by pbeckingham (Parson) on Jul 01, 2004 at 02:10 UTC

    Mine are:

    • Regular expressions.
    • Topicalizers $_, @_ etc.
    • The compact, expressive nature of the language.
    • Statement modifiers.

Re: Indispensible language features
by TilRMan (Friar) on Jul 01, 2004 at 02:24 UTC
    Syntax validator. Easy to overlook because it really belongs in the "would chew off my leg to escape a language without it" list rather than the "miss it terribly" list.
Re: Indispensible language features
by etcshadow (Priest) on Jul 01, 2004 at 02:30 UTC
    In addition to the others folks have mentioned:
    • ability to execute dynamically constructed code (ala eval in perl)
    • automatic memory management (unless there's a really, really, really good reason to do this yourself)
    • exception handling
    • namespacing
    ------------ :Wq Not an editor command: Wq
Re: Indispensible language features
by educated_foo (Vicar) on Jul 01, 2004 at 06:05 UTC
    In no particular order:
  • interactive environment (cf Lisp, Octave). Emacs integration is also nice. I've tried hacking this up for Perl, but it's not easy, since Perl's introspection (e.g. B::Xref) is still a bit primitive.
  • closures.
  • either macros or eval
  • OS interface
  • convenient C interface. While most code does not need to be optimized, many high-level languages make it somewhere between difficult and impossible to optimize that 5-10% that really needs it.
Re: Indispensible language features
by hawtin (Prior) on Jul 01, 2004 at 08:26 UTC

    I don't think there is anything that I have to have in a language. I find different languages valuable for different things. If I have selected, for example C to implement something it is because it matches the problem. If I need hashes and closures I select Perl not C.

    Now different languages clearly have distinct "areas of competence", but the trick surely is to have enough tools in your belt to always have one that is suitable.

Re: Indispensible language features
by dragonchild (Archbishop) on Jul 01, 2004 at 14:13 UTC
    I'm surprised no-one mentioned this.
    • Anonymous functions

    Without it, dispatch tables that curry their arguments are almost impossible.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      I think "Anonymous functions" are implied by the OP in "Lambdas (basically, anonymous closures)".

      P.S. - I love a good Curried Dispatch Table too, with a little Mango Chuntney and fresh Roti,... yummy ;-)

      -stvn
        I think "Anonymous functions" are implied by the OP in "Lambdas (basically, anonymous closures)".

        "Implied"?

        Yeah, I probably should have been more clear. When I mentioned "lambdas", I meant "anonymous functions, closures, and combinations thereof".

        Incidentally, one thing that I'm really starting to like about Haskell is its ability to seamlessly manipulate functions via currying, composition, and higher-order functions like flip. I'll try to come up with some examples that are neither trivial nor obscure for the next part of my Haskell intro.

        --
        F o x t r o t U n i f o r m
        Found a typo in this node? /msg me
        % man 3 strfry

Re: Indispensible language features
by adrianh (Chancellor) on Jul 05, 2004 at 16:21 UTC

    In addition to those already mentioned I'd add:

    • a testing framework
    • a profiler
    • lexical (my) and dynamic (local) variable scoping
    • decent runtime type system (any language that forces me to cast types to do anything useful is broken IMHO :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://370928]
Approved by adrianh
Front-paged by Enlil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-08-28 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (257 votes), past polls