Programming and writing about it.

echo $RANDOM

Category: wyfp

New Book: Write Your First Program – C and Python

I am excited to announce that my book, Write Your First Program is finally available for public consumption. In this day and age, when there are easily accessible programming books galore (in the context of both, price and availability), why write a new book? Through this post, I hope to reach out to the prospective readers and buyers (and hence critics) of this book.

I will start with a summary of the contents of the book, and then make an attempt to analyze a few key things I chose to be a part of this book and how I think those choices should help anyone attempting to get a first taste of programming today.

Summary of the book

The book stands at 242 pages (in paperback). It has seven major chapters starting from a Hello World program, followed by the concepts of variables, input/output, user-defined functions, data structures, file handling, mathematical functions and advanced concepts (object oriented programming, error handling and version control) . Each chapter discusses and implements each of those concepts in two programming languages: C and Python.  Most of the chapters have a programming fun section where I use the concepts introduced in that chapter (and others before that) to write a program which the readers can enjoy implementing. There are exercise problems at the end of each chapter which aims to encourage the reader to try out writing new programs.

Analysis of the Choices

C & Python: Besides the contents, which I will come to soon, the major decision I made while starting with the book is that it will aim to teach not one, but two programming languages – C and Python. The choice was far from being arbitrary or a way to be different from most programming books. It reflects my own (however flawed that may turn out to be!) assessment of what the beginning programmer today should learn.

I was exposed to C few years after I learned to program and it’s power became clear to me as I explored writing MS-DOS TSRs and later, Linux Kernel modules. Somewhere in college, in the early 2000’s, I got a book on Python. As I have programmed increasingly in Python and learned of the multitude of ways it’s been used in all sorts of projects – Linux utilities, Scientific and Numerical computing and Web application programming, my quest to learn more about Python increased and with that my urge to talk and write about how awesome Python is. For me C was raw power, where as Python was elegant and beautiful – good to read, write in and get the job done fast.

And hence, when finally the moment arrived I decided that I would attempt to teach both C and Python in my first book.  I have this urge in me to always get out all I know and share with someone (not verbally, I am not much of a talker) via my writings.

How would I go about teaching two different programming languages in one book without intimidating the audience of the book?

Contents: I decided that I would include topics which covers the bare minimum that the beginning programmer should know from the perspective of programming. I start the book introducing concepts such as variables, data types, input and output, control structures and user-defined functions, showing how to implement the ideas and concepts as programs in both the languages. I introduced C’s scary pointers in Chapter 2, along with the discussion on variables and data types. It just seemed natural to me that addresses of variables should be discussed with variables. I also introduce recursion in the chapter on user defined functions. Towards the end, I cover the topics of encoding, error handling, and working with multiple files. Considering the importance of using version control for projects, I also discuss the preliminaries of the git version control system and briefly touch upon the idea of text encoding in one of the appendices. Overall, I aimed to keep the topics naturally coherent not assuming a topic or concept may be difficult for the beginning programmer and hence introduce it later. The reader should ideally skip such a topic and come back to later.

Within each topic, I tried to keep the treatment to “just enough”, but not superficial. The reader will be able to learn enough to write useful programs (as part of an academic course, hobby project) and more importantly, be able to approach more advanced areas of either programming language with confidence. I also refrained from discussing quirks of programming language constructs (such as for(;;) in C) , which I believe can be lived without. There are books out there aiming to equip a reader with such knowledge and honestly, even if I wanted to, I don’t have the skills to do that. My book doesn’t aim to be a reference text. It aims to get you started, true to its title – help you write your first program.

Throughout the book, I have attempted to discuss programming in the context of other “subjects” of study – by asking the reader to attempt writing programming solutions to problems from those fields. This will hopefully also interest the reader who may not aim to take up computer science or programming as a career, but may need to use it as a tool.

Well, that pretty much sums it up. If you think this book may be worth a read, the buying options are as follows.

Buying the book

Print copy: Print copies are limited to India only (at least as of now). You can buy it online using any of the options below:

Digital Editions: 

Closing Notes

The book’s website is at and it will contain additional articles/materials and other content that the book’s readers may find useful. And of course, a list of errata (already found two myself) :-). Thanks for reading this post. I would be keen to hear from you in case you happen to buy my book or have something related to say/discuss.

This book was quite a journey on the personal front as well. You may enjoy reading it here.


The story of my first book: A personal account

The Book

My first book is slowly hitting the book stores in India. I have been notified that 1100 copies of it have been printed. I haven’t yet seen the physical copy, yet but I am looking forward to hold it in a week or so.

Book Cover

The journey began in January’2012 on an evening when I was talking to Protyusha and she suggested that why don’t I write a book on introductory programming and approach an Indian publisher with the idea, since there was a lack of good books on programming in the Indian market. Well, there were a lot of books which taught programming, and they were not bad, but almost all of them approached the topic as a subject to learn and pass exams in schools and colleges. That is not how computer programming should be taught. That is now how I wanted to teach programming. So, I sent in a proposal to Prentice Hall India Learning – one of the prominent publishers and whose books both of us had grown up learning from.

The proposal itself was interesting to say the least. I wanted to teach programming concepts and demonstrate them in three different languages – C/C++ and Python. Oh well, it was not the best of ideas – but the vision was grand – show different styles of programming. In the modern world, knowing one programming language is just not enough. Besides, I had to keep Python in it – it is something that young programmers should learn. I couldn’t keep out C, because you need to know C. By the end of several negotiations and literally selling our idea, it was finalized and I was finally convinced that the book would be on C and Python programming, also covering things like version control and open source software development. I was initially asked to send in a couple of sample chapters. And after about two weeks of near full-time writing, I had them ready. Protyusha helped me make the chapters stay to the point and also had some graphics, which sometimes I was lazy to add. She knew two things: that the book was good idea and had a business value associated with it.The publishers liked the sample chapters and I was asked to complete the entire book. I decided to complete the book by June’2012 end, when I would visit India and hand over the book in person.

But, plans are plans. I decided to quit my Ph.D in early June, and had to complete my thesis in a space of a month among various other things. I kept working on the book in bits and pieces in flights, in airports, in cafes and in shops where people would stare at me, not having a clue what I am doing with a laptop there (shops in India, i.e.). Finally, I worked for a month and half again after September’ 2012 (after I joined my new job) and finally submitted the entire book in November’2012 – covering Canberra, Kolkata, Brisbane, Singapore as the cities written in. In between, Protyusha helped me write a proper preface. The first version I had written was hilarious and had a girl, Lea talking to a robot Hal. Hilarious it was. She is a straight forward person and likes to talk and write like that. I agree with her on that, and hence I rewrote the preface and also kept that in mind for the entire book – not tell stories, but facts.

Who would I dedicate the book to? None, but Protyusha. She is super excited to see the hard copy of the book. I can’t wait to show her. This was a team effort and we saw the task to completion.

The process of writing

I went through phases of joy, excitement, frustration and doubtfulness while working on the book. That dilemma how little or how much to tell your reader got me bogged down so many times, and then that inability to exactly write and present what you have in mind led to self doubts often. By the end, I think I did about 90% of what I had initially thought the book would be like. I also feel that being in a career where I could talk to students directly might have helped.

I am feeling lucky.

Thank You Protyusha for not giving up on me for more than a decade and making me the person who can now call himself a book author. Not many can, not from where I started (and then got myself into).