Expressions that are idiomatic in one language but not used or impossible in another

Posted by Tungsten on Programmers See other posts from Programmers or by Tungsten
Published on 2011-02-26T03:41:53Z Indexed on 2011/02/26 7:32 UTC
Read the original article Hit count: 259

Filed under:
|

I often find myself working in unfamiliar languages. I like to read code written by others and then jump in and write something myself before going back and learning the corners of each language.

To speed up this process, it really helps to know a few of the idioms you'll encounter ahead of time.

Some of these, I've found are fairly unique.

In Python you might do something like this:

'\n'.join(listOfThings)

Not all languages allow you to call methods on string literals like this.

In C, you can write a loop like this:

int i = 50;
while(i--) {
 /* do something 50 times */
}

C lets you decrement in the loop condition expression. Most more modern languages disallow this.

Do you have any other good examples? I'm interested in often used constructions not odd corner cases.

© Programmers or respective owner

Related posts about language-agnostic

Related posts about syntax