Prior to my internship at Xandr, I had only done C development in an academic setting with a barebones C development environment: just me, my keyboard, and plain old Vim. I quickly learned that this set-up was not going to be sufficient for my internship. My main project was to add support for the dynamic preview of native creatives with a hosted video asset, and this work would touch three applications: the Creative API (CAPI), Impbus, and Picasso. While CAPI is written in Java, both Impbus and Picasso are C applications, for which I would be developing in vim. Since Impbus’s main role is the auction engine at Xandr, dynamic previews only involve a small portion of the nearly 2,000 files that make up Impbus, and narrowing down which files I would actually have to edit was a huge challenge. Thankfully, my manager introduced me to ctags, Silver Searcher, and buffers, and my appreciation for these vim tools skyrocketed as I navigated the overwhelmingly large codebase.
Ctags is a vim tool that generates tags or indices based on variables, macros, functions, etc. in the header and source files of a project that are then used to pinpoint areas of usage and definitions for those segments of code. These tags allow the user to jump around easily within their project. A major feature that I found useful was the ability to navigate swiftly from the usage of a function or variable to its definition. With a quick tap of the keyboard, I could easily locate the sources for these code snippets and trace the code, and with another tap I would return the point where I had started. This ability to fully flesh out a code path and then jump right back to my original start point was a huge time saver. For example, below I demonstrate finding the source for creative_native2_asset_video_media_file_init by hitting ctrl+], and jump back to where I originally with ctrl+t. I often had to trace a function call back to its definition or find where a struct was defined, and ctags was my best friend in this endeavor.
Silver Searcher is a code searching tool that has a plugin for vim. Developed as a full replacement to the searching tool ack, the Silver Searcher, or ag, can find matches to search terms within an entire project. With one command, I was able to search through hundreds of files for keywords — especially useful as I wanted to narrow down where certain functions were used. Ctags was useful for finding the sources for code, but Silver Searcher was a life saver when trying to flip through each instance of a phrase or code snippet. In this example, I am able to locate another file, creative_native2.c, that uses creative_native2_asset_video_media_file_init. If I needed to identify where a function was used throughout a project, Silver Searcher was super convenient.
Buffers aren’t necessarily a vim plugin or specialized tool, but as someone who had previously only worked on small C projects that touched 3 or 4 files, I didn’t have much experience or need to use the buffers functionality of vim. As the internship ramped up however, I soon learned that buffers are a very powerful component in vim and combined with the Silver Searcher or Ctags became a vital instrument in my code exploration. A buffer is just the actual document that is loaded into memory for editing, i.e. the open files you’re currently working on, and vim allows you to seamlessly toggle through these buffers. Below I’m able to view my open files and quickly switch between creative_native2.c and preview_handler_v2_native_handler.c. The ability to switch between open files was essential as I could easily make several simultaneous changes to those files efficiently.
Contributing to a codebase that is completely new to you, which has been populated by hundreds of coders over the span of a multitude of years, is always a daunting task, but through this internship, I have become better equipped with the skills I need for efficient collaborative coding in a professional environment. Unlike in college where I was given an empty file that I controlled completely and where I wrote and understood every line of code, I couldn’t immediately jump into a task that I was assigned. For the internship, a deep investigation was required before I changed any code and I had to gain familiarity with dozens of files in several repos. Doing so without ctags, the Silver Searcher and vim buffers would have been impossible.
These plugins and functionalities were like the sword Link was given before he embarked on his quest, and my manager was the one handing it to me, delivering the iconic line: “It’s dangerous to go alone. Take this!” And she was right. Without these tools, I would have been drowning in thousands of lines of code, very much lost at C.