Programmer guidelines -A brief introduction

Introduction

I have a basic document, which briefs about linux commands, Vim editor, Using vim for browsing C/C++ code and GDB. I thought that rewriting tutorials won't help. Instead I have mentioned how to go about, and specified the seemingly correct references. I'll update whenever possible.

Linux Commands

There are many linux commands, which you should be knowing. I'll prioritize and add them. I dont want to explain in detail, instead read the man pages.

find:

Search for files in a directory, for example:

> find . -name sort.c

Search for file "sort.c" in current directory (See dot)

> find src -name "*.c"

Search for filenames with .c extension in "src" directory.

Note:  You can use pattern matching to search for files.

grep:

Search for patterns in files, for example:

> grep "sort_function" "*.[ch]"

Will search for "sort_function" in filenames with .c and .h extensions

> grep -R -i -n "sort_function" src

Searches recursively (-R option) in directory src for pattern

"sort_function" ignoring the case (-i option), and prefix each line of output with the line number within its input file (-n option).

 Note: Double quotes are excluded while searching. Dont specify many options; give whatever is required. For eg. specify case option (-i) whenever required. It will slow down the search a bit.

Combining commands

Use find and grep together to search for patterns in specific files, for example:

> find . -name "*.[ch]|xargs grep "my_function"

This command will search for "my_function" in all "*.[ch] files in current directory. This is very much used by a programmer.

Note: You can modify find and grep to to match your needs.

Editors

Vim is today one of the two most popular editors for programmers and users of Unix-like operating systems, alongside Emacs.

Vim is said to have a steep learning curve, meaning learning is slow initially but once the user gets a grasp of the basics they progress quickly and their editing becomes more efficient. To facilitate this there's the vim tutorial for beginners, usually invoked by typing "vimtutor" on the Unix command line or clicking on the Vim tutor icon on the Windows desktop. There's also the Vim Users' Manual that goes into depth about the basic and more advanced features of Vim which can be read by typing ":help user-manual" within Vim.

New users should also learn how to navigate and understand the conventions of the Vim help system by reading the main help file by
typing ":help" without any arguments.

Learn the basics: Instead of reading the text (boring!) you can use the vimtutor to learn your first Vim commands. This is a 30 minute tutorial that teaches the most basic Vim functionality hands-on. 

On Unix and MS-Windows, if Vim has been properly installed, you can start it from the shell: 
> vimtutor 
This will make a copy of the tutor file, so that you can edit it without the risk of damaging the original. 

Further: It takes time to master vim. You have to learn gradually, build up from the basics, and apply the basics to create complex commands. Knowing regular expressions will help a lot to enhance searching and substitution. You can refer to cheat sheets available on net. But don't use them blindly. Try to understand what is mentioned then apply it .

Using vim as a programmers Editor: Go through these links: -- - 

  • Introduction to Programming in C/C++ with Vim http://www.justlinux.com/nhf/Programming/Introduction_to_C_Programming.html -
  •  A detailed help on using ctags (Browse through program sources) http://www.vim.org/tips/tip.php?tip_id=94

Summary: 

Create tags file for your project source tree.
cd <SrcDirectory> #cd to the parent dir where you have the src code
ctags -R #create the tags file
vim <filename> #open the file you want and start using tags.

Note: Always see that vim can locate the tags file. You can either do it by opening vim in the directory where tou have the tags file, or you can set the tags option from vim. (eg:- :set tags+=). See help for more details. You can also run vim -ton command-line to jump to the tag. - The Vim/Cscope tutorial (Cscope is a developer's tool for browsing source code. Its much better than ctags) http://cscope.sourceforge.net/cscope_vim_tutorial.html It explains clearly how to use cscope with vim.

Vimrc file:

A good vimrc will enhance the way you use vim. There are lots of vimrc's available on net. I'll attach one later.

Links

There are lots of tips and scripts available. See the (most viewed/top rated) tips to start with.  

Google will give you thousands of links to other references.

GDB

RMS's gdb Debugger Tutorial:  This is gdb tutorial explaining only the essentials. Try it out using examples. Two examples are given at the end of it.

Once you get hands on you can refer the FSF's gdb refernece manual for more details, or read the info pages (info gdb).

Links
http://users.actcom.co.il/~choo/lupg/tutorials/debugging/debugging-with-gdb.html - Another basic gdb tutorial.

Note: You may use larger projects which use scripts and makefiles to compile your the project (Instead of just gcc -g). You may have to enable
relevant debugging flags while running the configure scripts/makefiles in order to debug the programs. There are other debugger apart from gdb
which works on different platforms; dbx on Unix, MS Visual Studio debugger on Windows platform to name a few.