Expressions that are idiomatic in one language but not used or impossible in another
- by Tungsten
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.