Posts Tagged ‘Coding’

For anybody who loves programming, there is a problem of plenty. Naturally we are curious to learn more and there is simply too many options to pursue. When I started my career 4 years ago, the only language I knew fluently (well kinda) was C. I wanted to learn C++ and a scripting language for rapid prototyping. It has been 4 years, and I have learnt C++ and Python.

Now comes the predicament. What to study next. There are plenty of options. Should I study GUI programming via wxWidgets or learn Internet technologies like HTML and JavaScript. Both will not help me in my line of work (carrier class embedded software development in telecom domain). But it will be fun, and turn around time is much quicker. Applications always have this magical aura of being useful directly. Users interact with application directly and the developer gets feedback instantly. With infrastructure like Linux or the iPhone, we have to wait for some application to utilize the new goodies so that end users can appreciate the infrastructure.

Or I can take MIT Open Course Ware course on Operating Systems or strengthen my knowledge of algorithms. Both will help me in my line of work and should be tons of fun. But people around me (friends and relatives) identify with Internet technologies much better. Imagine showing my dad a terminal shell on the basic OS I wrote as part of MIT OCW or red black trees in action. Now imagine showing my dad an iGoogle widget written in HTML and JavaScript that he can interact with. But having a better understanding of the infrastructure OS or the algorithms can make us better programmers in general. This will benefit application programming too.

Another fascinating thread to follow is to learn Lisp. It may not give us any practical benefits. But I trust people when they say that learning Lisp is a profoundly enlightening experience for a programmer. I want to experience it first hand. But should I take it up now? If not now when?

Apart from technology, processes and paradigms are also a good candidate to delve into. Modern software engineering principles, design patterns, architectures, refactoring, software metrics, aspect oriented programming, functional programming, concurrent programming, literate programming etc are also promising. All of them, like investing in infrastructure, will help in general.

One of the things to consider while choosing is, how long will it be relevant. Ideally, we do not want to invest in something that will become irrelevant in the future. Till now I have invested in time proven technologies/tools like C, C++, Python, Vim, Linux… which are here to stay for good. Another aspect of relevancy is that it should be universally useful. It should still be relevant outside of my current organization, without licensing issues. Copyrights and licenses can make a current technology irrelevant for our purposes. Sticking with open standards and open source technologies with strong communities and vision ensures that our investment will not be obsolete quickly. HTML, JavaScript, OS concepts, algorithms and Lisp all are here to stay for good. Processes and paradigms may or may not stand the test of time and can quickly become a fad. Plus they can be picked up while focus is on learning the others.

So we have 3 main streams to pursue. Internet technologies (HTML and JavaScript), infrastructure (OS and algorithms) and Lisp. Well investing in infrastructure seems to be the most logical choice for me. It will directly help me in my line of work. It will help me be a better programmer by providing me a better understanding of the underlying universal principles of computer science. Both will be around for a long time (forever is more like it). Both will help me in my pursuit of the other two streams. So this can be a foundation for the other two streams 🙂

I am not the only on faced with this predicament. I quote Frederick P Brooks Jr from The Mythical Man Month.

The computer-related intellectual discipline has exploded as has the technology. When I was a graduate student in the mid-1950s, I could read all the journals and conference proceedings; I could stay current in all the discipline. Today my intellectual life has seen me regretfully kissing sub discipline interests goodbye one by one, as my portfolio has continuously overflowed beyond mastery. Too many interests, too many exciting opportunities for learning, research, and thought. What a marvelous predicament! Not only is the end not in sight, the pace is not slackening. We have many future joys.

So it is not really a predicament. We are just spoilt for choice. As Brooks predicts, we have many future joys. Amen.

Exuberant ctags is a pretty nifty utility for source code browsing. Especially since it integrates so well with vim. Also exuberant ctags can understand many languages (41 as per the official website). So this is relevant not only for C/C++ or Python but for all 41 languages supported (and future ones too). In this post, we explore yet another popular plugin using exuberant ctags – TagList.

TagList is capable of showing a list of functions/global variables/class/struct towards one side of the vim. This is similar to some IDEs or event editors like Notepad++. This makes browsing and navigation pretty easy. Our aim will be to be able to navigate current file using TagList window and to always display current function name in the status line.

Screenshot of TagList plugin showing current function name in status line

For this, we will need:

TagList will work only with exuberant ctags and not with any other ctags (specifically GNU ctags). Install exuberant ctags if required. Also ensure that ctags command should actually invoke exuberant ctags.

Install TagList plugin (see elaborate steps in the link). Typically vim plugins are installed by simply copying to $HOME/.vim/plugin directory. If any documentation is there, copy that to $HOME/.vim/doc and re-index vim help by giving “:helptags $HOME/.vim/doc” command in vim.

Now we need to customize the TagList plugin options to get what we want.

" TagList options
let Tlist_Close_On_Select = 1 "close taglist window once we selected something
let Tlist_Exit_OnlyWindow = 1 "if taglist window is the only window left, exit vim
let Tlist_Show_Menu = 1 "show Tags menu in gvim
let Tlist_Show_One_File = 1 "show tags of only one file
let Tlist_GainFocus_On_ToggleOpen = 1 "automatically switch to taglist window
let Tlist_Highlight_Tag_On_BufEnter = 1 "highlight current tag in taglist window
let Tlist_Process_File_Always = 1 "even without taglist window, create tags file, required for displaying tag in statusline
let Tlist_Use_Right_Window = 1 "display taglist window on the right
let Tlist_Display_Prototype = 1 "display full prototype instead of just function name
"let Tlist_Ctags_Cmd = /path/to/exuberant/ctags

nnoremap <F5> :TlistToggle
nnoremap <F6> :TlistShowPrototype

set statusline=[%n]\ %<%f\ %([%1*%M%*%R%Y]%)\ \ \ [%{Tlist_Get_Tagname_By_Line()}]\ %=%-19(\LINE\ [%l/%L]\ COL\ [%02c%03V]%)\ %P

Notice the call to Tlist_Get_Tagname_By_Line() within the statuline. This is what displays the current function name (actually tag which can be class name or struct name or any tag) in the status line. With the above settings, pressing F6 will show the prototype of current function at the bottom.

Pressing F5 will open up the TagList window which will show the list of functions/classes/structs/define etc. The focus is automatically switched to the list window and we can quickly jump to the function/class/struct definition we want to. Upon selecting an entry, the list window is automatically closed.shrink the window back to default size.

Screenshot of TagList window

Now with the full prototype display, it is not very easy to read the actual function name. TagList has a zoom feature to overcome this. Press “x” and the TagList window will enlarge, occupying almost the complete vim screen. Selection of an entry or pressing F5 again will close the window. Pressing x again will shrink the window back to default size.

Screenshot of TagList window zoomed using "x" key

TagList generates its own tags file and does not require the user to provide a tags file. This file is generated every time we switch to a buffer. The tags file is created somewhere in /tmp/ folder. TagList cannot work with a user generated tags file.