Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Have you looked at the Vim source? There are a few things in platform-specific headers, but most ifdefs are scattered in actual code. There are even ifdefs in the middle of control flow statements. For example, in RealWaitForChar(): https://github.com/b4winckler/macvim/blob/master/src/os_unix...

That function is over 400 lines and has over 50 ifdefs. What does it do? It waits for any key to be pressed. Unfortunately, Vim is single-threaded and synchronously character-driven, so it has to try and process some autocmds and other events in the same loop.

Oh and the wait loop uses gettimeofday(), which is not monotonic.

To get another taste of Vim's source, take a look at https://github.com/b4winckler/macvim/blob/master/src/eval.c (Warning, may crash your browser.) That file is 25,000 lines and checks hundreds of different ifdefs.



If that example (eval.c) is supposed to be bad, I don't think there's a strong case here. It looks like lots of older Unix/BSD code, and most of the ifdefs are feature-related, rather than platform hacks; some of the functions are a bit long, but that's typical in older C code.

I've never read the vim code before and I was surprised how cleanly written and well-commented it is, given my expectations set by this thread.


I love that if whose condition stretches over 15 lines with inline ifdefs, and then the body of the conditional is just one line without surrounding braces..




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: