Tips – Using janus to manage your Vim settings.

What is janus?

From janus‘s official Github page:

This is a distribution of plug-ins and mappings for Vim, Gvim and MacVim.

Just as it statement says, it packaged some popular plug-ins and mapping for you, so you can to use a full featured Vim after you installed Vim(If you are using Mac and Lion+, that means you just need to run a command and start to use a luxury Vim).

If you are in a rush, just copy the line below and paste to your terminal.

$ curl -Lo- | bash

Why bothering janus?

There are many famous plug-ins for Vim. But searching and installing plugins could be a painful work.

Usually, you google it, then go to to download it, then you config it and use it. This process is fine for one plugin, what if you want to install the top 10 vim plugins for coder, what if you want to install another 10 popular plugins?

For me, I can’t go through this process again and again. Don’t even think about the weird errors popped out when you installing your plugins.

What’s the merit I can get?

With janus, all you need to know is run a command and then use it. Oh, maybe you still need to remember some command for the plugins.

Where to start?

If you have enough patient to read to here, I suggest you to take a look at janus’s Github page.

What? you just want to use it? OK, open your terminal and paste the code below.

$ curl -Lo- | bash

Good luck!

And, don’t forget to follow my twitter @TonnyXu

LLVM Compiler Overview(By Apple)

LLVM is the next generation of compiler toolchain created by Chris Lattner and Vikram Adve in University of Illinois Urbana-Campaign, currently Chris Lattner is an employee of Apple, and Apple is the biggest contributor to this open source project. LLVM intends to replace the whole GCC-family toolchain. It’s really, really awesome!

Here is an overview guide provided by Apple, but it hasn’t been updated for over 1 year. And during 2011, Apple released LLVM 3.1

NOTE: This page is the official release page, and will always show the most recent release. So if you visit this page and see LLVM 4.x, don’t be surprised.

Any way, it’s a good source for understanding the low level tool chains used by Apple and how apple is changing the C family compiler.

The documentations

Go to DevCenter, this page is free, no login is necessary. And all the videos has transcripts!

Other videos

Actually, the Clang community has some regular events held in San Francisco or San Jose. You can check it out from LLVM’s official site, for example, LLVM Developers’ Meeting@Nov 2011

And, as always, don’t forget to follow me @TonnyXu

ARC Learning Notes(1)

ARC(Automatic Reference Counting) was introduced by Apple on WWDC 2011, along with iCloud and OS X Lion. It’s a wonderful feature we need, but, how much it has been adopted to real projects?

How many projects adopted ARC?

Currently, 0 project is using ARC in my company.

This does not mean we hadn’t started new project since ARC was released, but because we have some constraints. We are using some common libraries across our projects, and we need to maintain the libraries consistent. We also need to add many features to the apps we released, and also, using ARC means all of our team members need to learn how to use ARC and know the common practices and have a better understanding of memory usage. That’s the time we could not afford in the past 8 months.

But we know we will move to ARC inevitably. So the problem is when?

Status of My projects

Currently we started to use ARC in some test projects. Here the Test Project means we use such kind of project to test some features quickly and without infecting the real projects.

What about yours?

How about yours? Are you starting to use ARC in your project now? Tell me about your projects’ status in the comment please.

It’s the time!

After 8 months, by watching a lot of Open Source project adopting ARC, I think it is our time to start using ARC from now on.

ARC only needs the new compiler, and it has a good backward compatibility to iOS 4. So let’s just try it.

Start from where?

Where should we start from? I think we can start from 2 things.

Apple’s document

Apple’s DevCenter for iOS has a good document for using ARC. Here is a simple list as far as I know.

  1. What’s New in iOS 5
  2. Transitioning to ARC Release Notes
  3. Advanced Memory Management Programming Guide
  4. Memory Management Programming Guide for Core Foundation

WWDC 2011’s HD Video

Also, WWDC 2011’s videos are great, don’t miss this one.

  1. Session 323 – Introducing Automatic Reference Counting

Next time, I will post what I learned about ARC.

And as always, don’t forget to follow me @TonnyXu

Have you seen MIN and MAX macro in Objective-C

How will you write a MIN(a, b) or MAX(a, b) macro?

In the real world, it is easy to tell which is the minimum and which is the maximum of 2 numbers. But to write a correct function in computer, it’s not an easy job as we can see.

Usually, MIN and MAX functions are written in macro, so how will you write it?

#define MYMIN1(a, b) {a < b ? a : b;}

This is definitely wrong, at least you need to add the parenthesis to the parameters. OK, it’s easy, let’s add this:

#define MYMIN2(a, b) ({(a) < (b) ? (a) : (b);})

But, this is still wrong. Let’s take a look at what Objective-C and other languages defines these 2 macros.

How does Objective-C define MIN and MAX?

Because there is no MIN or MAX defined by C standard library, Objective-C defined this in NSObjCRuntime.h

Let’s see the code:

#if !defined(MIN)
#define MIN(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })

#if !defined(MAX)
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })

Wow! that’s extremely long. Let’s see why it is necessary. Say your user write a piece of code like this:

int i=1, j=2;
int r = MIN(i++, j++);

What’s the supposed result of r? Obviously, it should be 2, but if you use MYMIN2, you got 3.

That’s why MIN and MAX are defined so complicated in Objective-C and other languages.

Make sure MIN/MAX does not change the value passed in

That’s the key point of write MIN and MAX in macro.

__typeof__(A) __a = (A);

is the key point to the correct result.

Don’t forget to follow me @TonnyXu