The ternary operator in C

Reading time ~1 minute

Most programmers are familiar with the ternary operator ?: that is available in C and most other languages. But what some people may not know is that you can also use this operator with only two arguments.

Instead of writing

int y = 23;
int x = (y ? y : 34);

you can do this

int y = 23;
int x = (y ?: 34);

The other thing some of you may not know is that when defining a const you can’t use an if statement to define it based on a condition, but you can do this:

int y = 23;
const int x = (y ?: 34);

That’s it for the first post!

Testing Throwable Methods in Swift 2

With the addition of error handling to Swift 2, we got a way to deal with errors with the nice try/catch exception handling syntax from m...… Continue reading

NSFastEnumeration in Swift

Published on October 01, 2014

Singleton Pattern in Swift

Published on June 07, 2014