C Programming Tips by Philip Guo

Programming Languages

Philips Guo at Stranford University has useful collection of C programming lessons which may be quite useful if you are new to C programming. Guo starts by answering the simple question of why someone should start programming in C language.

This is the first question you should ask yourself before sitting down to start a new programming project. Why are you programming in C in the first place? For quick hacks and small projects, high-level interpreted languages like Python and Ruby allow you to get something up and running much faster with less fuss. For more structured software engineering-like work, languages like Java and C# offer better type checking, more natural support for data abstractions, and more powerful standard libraries. For web programming, there’s PHP, XSLT, and loads of other acronyms. Given all of these other choices, why would anyone ever want to program in C nowadays?

The tips on pointers and dynamic memory allocation are excellent. For example pointers do not equal to dynamic memory allocation and always set a pointer to 0 after calling free() on it.  C program always have bugs, so it is never too early to learn to debug. Use print statements (with endlines) to hone in on a problem, then switch into a debugger.

In general, don’t write your own common data structures unless you have no other choice (with the exception of simple things like an array-based stack or a linked list that don’t take much effort). If you are interfacing with other code, look inside of them to see what data structures they use. Or search for libraries on the Internet like GLib, which provides several common data structures. Many C programmers create their own versions of common data structures to supposedly optimize for performance. Unless you are working on speed-critical applications (like an OS), performance is never an excuse for not using a well-maintained, well-debugged data structure library.

You can find complete webpage here. http://www.stanford.edu/~pgbovine/c-programming-tips.htm

Categories: Blog
M. Saqib: Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.
Related Post