Slashdot Mirror


Favorite Programming Language Features?

johnnyb asks: "I'm curious what everyone's favorite programming language features are. I'm looking for both the general and the specific. I'm especially looking for features that few people know about or use, but are really useful for those who do know about them. What are your favorite programming language features?" "A couple of examples to kick off the conversation:
  • Continuations

    Continuations are very interesting, because they can be used to implement a number of flow-control features such as exceptions, coroutines, cooperative multithreading, and are better at modelling web interactions. This is a more general feature, but most people use these in conjunction with either scheme or ML.

  • Tuple-returning

    It is a huuuuge time-saver when languages like Perl allow functions to return tuples. Instructions like '($a, $b, $c) = $sth->fetchrow_array()' is a wonderful thing.

  • The flip-flop operator [Perl's '..' operator]

    Another perlism that I just think is cool. Read more about it here.

Okay, on to yours!"

3 of 312 comments (clear)

  1. Self-execution by BollocksToThis · · Score: 4, Informative

    My favourite thing is languages that can execute strings of their own code.

    For example, clipper can do this via blocks:

    cVar := &("{ || nVar += 43")

    Python has the same thing via "exec":

    >>> b
    NameError: name 'b' is not defined
    >>> exec "b=2"
    >>> b
    2

    This means you can build up strings of code at runtime and execute them, or store field-specific database logic in another database table, and fetch it when needed.

    C# is not quite so convenient - you have to build up a complete class and compile it, but it can all be done in memory at runtime so it's just a little more work. Clipper and python can both affect the current scope directly (which can be both bad or good, I suppose).

    I believe ruby has blocks similar to clipper (probably better), but I don't use it, so I'm not sure. I also don't use perl, so I have no idea if it supports this...

    --
    This sig is part of your complete breakfast.
  2. This "ask Slashdot" is a concurrent "cross-post" by Paul+Bain · · Score: 4, Informative
    The poster, johnnyb, also asked this question on Advogato just a short time ago. It will be interesting to see the differences in the comments made there and the ones made here at Slashdot.

    Hey, johnnyb, where else have you posted this question? When you get answers, will you analyze them and post your conclusions? It could be interesting.

    --

    A lawyer & digital forensics examiner. Also an expert on open source software (OSS).
  3. Don't bash C++ by Chemisor · · Score: 4, Informative

    > #1 Garbage collection. a.k.a. automatic memory
    > management. Not very sexy, but by far the single
    > biggest productivity boosting feature of any
    > language. I hate housework. It is just a waste of time.

    Garbage collection does not free you from memory management. It simply converts one kind of problem into another: namely it eliminates accesses of unallocated memory, but it creates memory leaks instead. The thing is, it is not always easy to figure out when you no longer need a block of memory. That's with garbage collection it is supposed to be good practice to "free" your pointers anyway, by assigning NULL to them. Why they can't just use STL containers instead, I don't know.

    > #2 No pointers, no buffer overruns, no memory
    > corruption. Related to the first point. Memory
    > corruption is just so hard track down. You can
    > keep your pointers

    You won't have any memory corruption if you don't use arbitrary indexes to access your arrays. For example, when iterating over a container, you run your iterator from ctr.begin() to ctr.end(); no corruption possible. The other cause of memory corruption is using unverified data to directly access your arrays. That happens when you ask the user for a number and then use it to index; this is wrong in so many ways, I can't even begin to list them all. Verify your data, and you will not have any data corruption.

    > #3 Stack traces. Not a language feature per se,
    > but it takes a lot of the drudge work out of
    > debugging.

    #include
    backtrace_symbols()

    > #4 Python's 'for' loop for iterating over the
    > contents of a list or array:
    >
    > for thing in myarray:
    > mutate(thing)

    #define foreach(t,i,c) for(t i = c.begin(); i #5 Dictionaries, a.k.a. associative arrays. It
    > just makes a lot of problems much much simplier
    > and faster to solve.

    map m;

    > Sure, most other languages
    > have dictionaries available as a class, but when
    > they are seamlessly built into the language you
    > use them as easily as any other primitive '
    > datatype.

    You can use map as easily as any other primitive data type of the same category: as an array.
    m["january"] = 31;
    cout "january has " m["january"] " days" endl;