Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When learning a new programming language you sometimes come across a language feature which makes you wish you had it in your other programming languages that you know.

What are some language feature which were at the time of learning very new to you and that you wish your other programming languages had.

An example of this is generators in Python or C#. Other examples may include list comprehensions in Python, template in C++ or LINQ in .NET or lazy evaluation in Haskell.

What other semi-unique language features have you come across which were completely new and enlightening to you? Are there other features of older programming languages which were unique and have fallen out of fashion?

share|improve this question

closed as not constructive by Mark Trapp, ChrisF Apr 24 '12 at 12:33

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

18 Answers 18

up vote 23 down vote accepted

Practically anything in Haskell

  • Monads. Yes - the big scary word that makes increadibly easy parsers, IO, operations on Lists and other things so easy (once you notice common pattern)
  • Arrows. The same for advanced users ;)
  • Standard stuff like lambdas etc.
  • Currying functions
  • Algebraic data types
  • Pattern matching

And many more.

PS. Yes. I am Haskell fanboy if anyone asked.

share|improve this answer
To be fair, you should give ML credit for most of that list. – munificent Sep 22 '10 at 1:44
Well - except monads and arrows IIRC. But they still are semi-unique – Maciej Piechotka Sep 22 '10 at 9:16
+1 for pattern matching. I show it to other people and they don't get it. I think it's genius. – Barry Brown Oct 2 '10 at 21:09

Lisp macros.

The Lisp macro language is Lisp, with a few predefined syntax features for the sake of convenience. Using them, it is possible to add major features to the language, such as one's choice of object orientation styles or Prolog-like deterministic matching, without looking out of place. It makes the setf macro possible, which is a conceptually very powerful macro: (setf A B) means that, when you evaluate A you will get B, and that can be extended to any limit you like.

C++ template metaprogramming is capable of similar things, but in a much different language than regular C++.

share|improve this answer

Python's decorator.

It's extremely easy to implement memoization or timing of function using the decorator.

Example of a function timer.

class FuncTimer(object):
    """ Time how much time a function takes """
    def __init__(self, fn):
        self.fn = fn
        self.memo = {}
        self.start_time = time.time()
    def __call__(self, *args):
        self.memo['return'] = self.fn(*args)
        print("Function '%s' took %u seconds" % (self.fn.__name__, time.time() - self.start_time))
        return self.memo['return']

Now if you have a function foo you want to time, you can simply do this,

def foo():
    # foo's implememtation goes here

You will see something like,

Function 'foo' took 3 seconds.

share|improve this answer
+1: Python's decorators have impressed me more than almost any other feature in the language. They are very beautiful and simple! – Adam Paynter Sep 9 '10 at 23:26
Shouldn't the start time be computed as part of the call? – detly Jul 16 '12 at 7:48

Casting to void* in C. You can cast everything to raw bytes, and do whatever you want with these data.

(Yes, nowadays it's unique...)

share|improve this answer
Object in .Net languages is very similar. Only more type-safe etc. – Maciej Piechotka Sep 7 '10 at 20:01
@Maciej: even in .NET, you can't really cast primitives to Object. You box them, and it's quite a different beast. Besides, that's still totally different to casting to void*... – Dean Harding Oct 18 '10 at 23:18
Casting to Pointer in Pascal and Object Pascal does the same thing. – Frank Shearar Oct 26 '10 at 7:50
@DeanHarding: Well - in C you have int64_t which you cannot always safely cast to void * (Sorry for late - 2 years - reply). – Maciej Piechotka Jul 16 '12 at 6:46

Yield in Python

In Python (and I believe in C#), you can define a so-called generator that pauses function execution at a yield statement, returns the value and on subsequent calls, restarts the function where it left off (with the state preserved between calls). This is great for generating long lists of values where you are only interested in the current value of the function (which is very common). It allows you to build potentially infinitely long sequences while only occupying very limited space in memory.

share|improve this answer
Yield is already listed in the question. – Trinidad Dec 6 '10 at 14:50

Lambda expressions (closures, nested functions, anonymous methods, whatever you call them).

I first came across them in Perl, instantly loved them and wondered why other languages don’t have them. Nowadays I guess it’s not that unique anymore; even PHP have managed to hack them in somehow. But they were semi-unique at the time.

share|improve this answer
Unique, as long as you count going back to Lisp, which is the second-oldest programming language around. ;-) – khedron Sep 22 '10 at 1:35

Continuations from Scheme (later adopted by a few other languages including Ruby.)

share|improve this answer

Sets in Delphi are very useful, pretty much just a named boolean array. They're very useful for saving a settings form with 32 checkboxes. But they've got all the same set theory functions (i.e. difference, intersection, union).

I'm not sure if they've fallen out of fashion, but I use them all the time.

share|improve this answer

C# Properties

/// <summary>
/// Get ID
/// </summary>
public int ID
    get; set;



 * Name of user
private String name;

 * Gets name of user
 * @return Name of user
public String getName() {

 * Sets name of user. 
 * @param name
public void setName(final String name) { = name;
share|improve this answer
Yes, they are better, but this is a bad example. The difference would be much smaller if the getter/setter would actually do something special, and the C# version is documented less. – Bart van Heukelom Sep 11 '10 at 21:14
My boss is strongly against the automatic properties of C# and whenever we have an argument about it, neither of us is able to see why the other is right or wrong. I just love them because they make the code so much cleaner and saves me a lot of time in the long run. – mbillard Sep 12 '10 at 1:43
Just don't allow this to encourage people to have getters and setters all over. Only those getters and setters that make sense as actions on an object should be used. – David Thornley Sep 22 '10 at 14:39
They're not called C# properties, they're called Auto-properties – Jaco Pretorius Sep 22 '10 at 14:53
Auto-properties are very common these days. Python, Objective-C... – Casebash Sep 22 '10 at 20:56

Unions in C

I can't honestly say that I haven't written enough C to make any of these myself but I have worked with other's code that does.

When it comes down to packaging mixtures of different data in applications that manipulate raw bits/bytes such as networking or binary data storage. In strongly typed languages theres just no easy way to do the equivalent.


Although Unions are extremely useful in some cases, they aren't found in most higher level languages because they aren't type safe. IE, you can make data bleed across boundaries of variables using unions (a big no no in the type safe world). With great power comes great responsibility.

share|improve this answer
IMHO for a good reason. Reinterpreting data is a beatiful way of shooting onself in foot ( Better use explicit conversions IMHO. Unions doing right way is IMHO algebraic data types. – Maciej Piechotka Sep 12 '10 at 10:29


From Erlang. Sends a message asynchronous to another thread.

Expr1 ! Expr2


From Erlang. Receives a message from another thread.

    Pattern1 [when GuardSeq1] ->
    PatternN [when GuardSeqN] ->
share|improve this answer

I really like the unless modifier in Ruby. It seems so natural and replaces a lot of scenarios where your code just seems to be very messy without it.

puts "All good" unless input.nil?

How can you not like that? :D

share|improve this answer
Perl had it before Ruby. I love it, too. – Barry Brown Oct 2 '10 at 21:10
Nemerle has similar keywords for unless and when which replace the most common branching scenarios which traditionally would use if/else. – MattDavey Jul 16 '12 at 9:38

fancy python argument syntaxes

I'm not sure how unique this is, but in python you can do cool stuff like have keyword pairs automatically made into a dictionary and back. Same with lists:

def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
    print "-- This parrot wouldn't", action,
    print "if you put", voltage, "volts through it."
    print "-- Lovely plumage, the", type
    print "-- It's", state, "!"

parrot(action = 'VOOOOOM', voltage = 1000000)
parrot('a thousand', state = 'pushing up the daisies')
parrot('a million', 'bereft of life', 'jump')

python docs (scroll down for more argument pasing stuff)

share|improve this answer
+1 for being able to pass a parameter deep in the list without having to pass values for all of the optional parameters before it. – eswald Nov 1 '10 at 17:35

The C preprocessor. You can even write common code to different platforms with - less or more - ifdefs.

share|improve this answer
There are better preprocessors readily available that take their own extra step, and work with all languages. – David Thornley Sep 22 '10 at 14:38

Objective-C Categories

Categories offer an easy way to extend an object's functionality at runtime (think composition versus inheritance). The classic example is to add a spellchecker to the NSString class.

@interface NSString (SpellChecker)
- (BOOL) checkSpelling;

Also useful for low impact bug-fixes, since a category's implementation of a method will override its parents implementation.

share|improve this answer
Very similar to extension methods in C# – Casebash Sep 22 '10 at 20:52

Ruby's inject method combined with the Symbol#to_proc feature of Ruby 1.9 lets one write some incredibly concise (but still readable) code:

e.g. (1..10).inject(:+)

which sums the integers 1 through 10 => 55

Seeing examples like this made me want to learn Ruby, which I've just started doing.

share|improve this answer
To be fair, inject is Ruby's version of fold/foldl/foldr from languages like Lisp, Haskell, etc. – mipadi Sep 22 '10 at 19:38
The title of the question says "semi-unique", not unique. Certainly the conciseness of the code afforded by the combination of inject (or map etc) and Symbol#to_proc is way beyond mainstream languages like C, Java, and C++. – tcrosley Sep 23 '10 at 2:06

The Binding Mechanism in JavaFX (R.I.P). The bind keyword enables you to bind the value of a variable to the value of an expression and getting you rid of all those ugly Listener whatsoever boilerplate code.

While JavaFX was quite a fail in many ways, I found many features of the scripting language quite nice.

share|improve this answer

String mixins plus compile time function evaluation in D is a pretty unique killer feature. Yes, technically it's two features, but the real power comes from combining them. With this combination, you can write regular D functions that generate code as a string at compile time, and then mix this code into any scope and have it be evaluated as regular D code. The code is fully statically compiled and executes exactly as if it had been handwritten. This feature is even used to work around a couple sticky situations in the standard library.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.