PHP and MongoDB Web Development Beginner’s Guide – Thoughts of a first-time author

PHP and MongoDB web development

Social networking doesn’t always make you procrastinate, sometimes it pays off! When @packtauthors tweeted that they were looking for someone to author a book on PHP and MongoDB, I made contact. Few weeks later I signed a contract for writing the book. And six months after that, I am pleased to announce that PHP and MongoDB Web Development Beginner’s Guide is published and out for sale!

In this post I intend to share a few words about the motivation behind the book and the journey of a first time author.

The Motivation

I’m a supporter of the idea the MongoDB can potentially be the new M in LAMP. The web application data storage requirements have changed a lot during the past 4-5 years. Instead of producing contents of their own, the most popular websites are hosting contents created by their users. These contents are diverse in nature and humongous in volume. Mapping the diverse data into a rigid data structure gets harder as the volume grows. This is where the ‘Flexible Schema’ nature of MongoDB fits really well. Also MongoDB is easy to learn, developers with relational database experience should find little trouble adapting to it. There is a lot of similarity between the underlying concepts of an RDBMS and MongoDB (think documents for rows, and collections for tables). Developers don’t need to wrestle with radical ideas such as column-oriented or graph theory based data structures as some other NoSQL databases require them to. Finally, it is open-source, freely available (Creative Commons License), supports multiple platforms (Windows/Linux/OS X), have great documentation and a very co-operative community, and plays nicely with PHP! All these have lead me to believe that in near future MongoDB will be where MySQL is right now, the de facto database for web application development (I would urge you to read Stephen O’Grady’s article which makes more persuasive arguments). And since PHP is the dominating language for web programming, writing a book on web development with PHP and MongoDB felt just right.

The intended audience for this book are web developers who are completely new to MongoDB. It focuses on application development with PHP and MongoDB rather than focusing only on MongoDB. The first few chapters will try to ease the reader into understanding MongoDB by building a simple web application (a blog) and handling HTTP sessions with MongoDB as the data back-end. In the next chapters he will learn to solve ‘interesting’ problems, such as storing real-time web analytics, hosting and serving media content from GridFS, use geospatial indexing to build location-aware web apps. He will also brainstorm about scenarios where MongoDB and MySQL can be used together as a hybrid data back-end.

The Inspiration

Scott Adams, the creator of the famous Dilbert comic strip, wrote an inspirational article on Wall Street Journal. I’m going to quote a few lines here:

“I succeeded as a cartoonist with negligible art talent, some basic writing skills, an ordinary sense of humor and a bit of experience in the business world. The ‘Dilbert’ comic is a combination of all four skills. The world has plenty of better artists, smarter writers, funnier humorists and more experienced business people. The rare part is that each of those modest skills is collected in one person. That’s how value is created.”

These words moved me. I like programming and I like writing, and although there are smarter programmers and better writers out there, by combining these two passions I could potentially produce something. Besides I had an amazing learning experience with MongoDB. I built an API analytics solution with MySQL which became difficult to handle as the volume of the data grew. I started playing with MongoDB as a potential alternative. A month later I moved the entire data from MySQL to a more solid and scalable solution based on MongoDB. I wanted to share this learning experience through a series of blog posts but lacked the personal discipline and commitment to do so. Being obligated a deliver a book within tight deadlines solved that problem!

I also must thank Nurul Ferdous, my friend and former colleague who is a published tech author himself. His guidance and influence has been instrumental.

The Journey

My journey as an author writing a book for the first time has been an exhaustive yet amazing one! I work in a tech startup, which naturally requires longer than usual hours and harder than usual problems to solve. I would come home late and tired, research on MongoDB topics, plan how to deliver the message to the reader, write code, test and debug the code, write the content on a text editor, fight with Microsoft Word so the content has proper formatting as required by the publisher. Then on weekends I would revise and rewrite most of what I have done over the week and hustle to make the deadline. Nevertheless it all had been a rewarding experience.

In the rewrite phase I had a lot of help from the technical reviewers – Sam Millman, Sigert De Vries, Vidyasagar N V and Nurul Ferdous. They corrected my errors, showed me what more could be added to the content and what should be gotten rid off, helped me communicate complicated topics to readers in a clearer way. I convey my sincere appreciations to them!

Time to end this lengthy blog post. I hope you find this book enjoyable and use it to build some really cool PHP-MongoDB apps! I will then consider my endeavor to be a success.

1 Comment

Filed under Programming, Personal, PHP, Database, Books, MongoDB

Random snaps from Thailand tour

I’m kinda bummed out since I didn’t get any chance to travel this year (and it looks like I won’t for the rest of the year). So I’ve decided to share some of the photos that I took in my Thailand tour last year. This photos have been lying around in my hard drive for almost a year , so I finally decided to upload a few of them.

This picture was taken on a beach in Phuket, Can’t remember the name of the beach right now.

The rock at James Bond Island, named so because it appeared in one of the James Bond movie.

You are always reflective when you are on a canoe.

A colorful moment.

This baby elephant put on quite a good show.

snorkeling

My attempt at snorkeling.

phi phi island

A sunny day on the beach of Koh Phi Phi

loh dalum bay

Loh Dalum bay

Leave a Comment

Filed under Personal, Travel

Learn core Python from Stackoverflow

The other day I needed to brush up my knowledge on Python decorators, for implementing a profiling hook for a Django REST API I’ve been working on. I googled around and landed on a question titled Understanding Python Decorators on Stackoverflow.com. The answer given by the user e-satis is an excellent introduction to decorators in Python, although it has not been selected as the official answer. Go ahead an give it read if you have done some Python coding.

This got me thinking. This guy does not care about whether or not his answer gets selected before others (so that he can bag some reputation). He took his time and explained what decorators are in a well thought-out, step-by-step manner. The end result is an answer worthy of being placed in a beginner level Python book as a chapter on decorators! So there must be other answers as awesome as this one, given by users as knowledgable as e-satis! I set out to find few more great StackOverflow threads on core Python programming, had them bookmarked for future reads, and now sharing them on this blog post. You should read each of them at least once to make your knowledge on core Python more solid.

Understanding Python decorators

As I mentioned above, great introduction to decorators in Python.

What is a meta-class in Python

Another great answer from e-satis (later turned into a community wiki). Explains what meta-classes are in Python and why are they so useful.

How to sort a list of objects in Python, based on an attribute of the objects?

The answer to this question often comes in handy!

Understanding Python super() and init methods

A short yet useful answer explaining what good is super() for. You should also read the article Pythons’s super() considered super! along with this.

What is the relationship between __getattr__ and getattr?

I always wondered; and Kimvais provided the answer! Also checkout Alex’s answer in the same thread.

The Python yield keyword explained

Another gem from e-satis. Introduced the concept of iterators and generators in Python and goes on to explain the use of yield statement.

Single quotes vs. double quotes in Python

The stylistic reasons for choosing double quotes or single quotes when coding in Python. Worth a read.

Python Compilation/Interpretation process

Very detailed answer explaining Python compilation/interpretation process to programmers not coming comp-sci background; something every Pythonist should know.

Python progression path- from apprentice to guru

Last but not the least! A great thread showing what road a Python beginner should take to achieve mastery.

If you know about any other great StackOverflow posts, please do share them on the comment section. I’ll update my list. The posts must be about Python (core Python more specifically).

2 Comments

Filed under Programming, Python

Making Chrome Canary the default browser [OS X]

This post is for Apple OS X users. This is a nice trick for setting Google Chrome Canary as the default browser in your OS X. You can’t do this within Canary itself. Since this is a nightly build edition of Chrome browser, the developers have intentionally disabled this feature. So to have Canary as your default browser:

  1. Launch Safari
  2. Click on Preferences
  3. Under the tab General, choose Google Chrome Canary as the value for Default web browser
That should do the trick!
Update: Since this post is getting quite a lot of attention I figured I should update this with a cautionary tale. You should know the Canary is an unstable and untested build of Google Chrome. When the browser gets updated behind the scene, you may be introduced to a few bugs. One such bug deleted all the links in the Bookmark bar! And since my bookmarks are synced across browsers and devices using Xmarks, I lost the bookmarks in all my browsers in all my machines! I launched Firefox and watched the links disappear before my eyes and cried out in horror! Fortunately Xmarks keeps backups of your links in the cloud, so I was able to download the backup files and restore them. But I stopped using Canary since then.
Morale of the story: use with caution!

1 Comment

Filed under How-To, Mac