Coffee Coder

Shubham Jain's Weblog

Imperfect ‘Best’ Practices

| Comments

Six years ago, I was taught my first lesson of C++. Soon after learning about loops, came a subsidiary lesson about the goto statement. The teacher made it clear that using goto was a horrible practice because of unconditional-jumps mess it creates and should always be avoided. A bit of googling followed and I ended up with a well known essay of E. Djikstra’s ‘Goto is considered harmful’ and I committed myself to never use the statement even if it meant creating a frivolous flag variable.

When I didn’t had much exprience with web development, the only worthwhile thing I was able to sell as a freelancer was web scraping. After all, it was just a lousy combination of cURL and preg_* functions. Twiddling around Stackoverflow I got to know about the most upvoted answer on the site – a hyperbolic poetry on how you should never parse HTML with regular expressions and half a dozen more answers parroting the same message with their own flavour of the joke.

This moved me to abandon my way of using regexes and try a using a DOM Parser instead. Note that, at that time, the DOM libraries in PHP were really bad and DOMDocument API was far too weak to do anything moderately complex but anyway, I bore with them for any web scraping that I did.

Debugging Stuck PHP-FPM Process With Strace

| Comments

For most of the times, debugging is easy – a silly logical error or an oversight, quick to correct and move on but some problems are hard – because you don’t know where it is wrong. The bigger the involved stack is, the higher are your chances of getting stuck at them. In such cases, tools like strace can be of great aid as they can help you give a hint about where things are getting screwed up.

Recently, I faced an issue at my company where navigating beyond the dashboard page resulted in navigation getting stuck.

The Problem

First a bit about our development environment – we use Vagrant to have a complete isolated environment which is similar to what we use in production. To provision our VM we use Puppet configuration management (although, we have been poor to keep it up to date with incorporation of newer technologies).

Now, we started facing a problem in which the PHP-FPM process just get hung and won’t process any other request for a long time. It would do load after a while, having the same problem when navigating to another page. “Annoying” would be an understatement to describe how expasperating this problem was.

The only solution was to run sudo service php5-fpm restart inside the VM everytime it happened (resulting in 503 Bad Gateway) and refresh the page again. Certainly, not a worthwhile solution but short of solutions, we aliased the command to have a quick fix.

Blog Little Things

| Comments

John Carmack once speculated that StackOverflow might have added billions in productivity.

Quite rightly so. Imagine, the no of people that didn’t have to go through (maybe lousy) documentation, and long threads to seek solution for their problems. RTFM, many of programmers would be quick to point out but even the simplest questions, like, “How to read a whole file in python?”, “How to kill a process with its name?” must have saved thousands of programmers’ time. Thanks to rookies who didn’t feel embarrassed in asking them, that even experienced programmers can enjoy fruits of their answers.

Why Productivity Tricks Don’t Matter

| Comments

We’re living in an exciting century. The majority of today’s success stories trace its existence from few nerds hacking in their garage. Yet, majority of ambitious hackers, struggle to get going with any of the dozen of ideas that they have thought, most of which end up being un-fiddled in their favorite note-taking apps.

It seems very exciting to draw the plan for your side-project, its features, its technology and of course, how it could be a million-dollar thing but rarer is for someone to get started, and more rarer, to manage more than a few sittings on desk over it, eventually after, the enthusiasm dries up and its time to head back to browsing your favorite sites.

Almost everyone, knowingly or unknowingly, suffers from the same compulsion of doing activities that come under umbrella of “wasting time” but the scope is a lot different for hackers who don’t procrastinate over not doing their assignments, or presentation but shipping something that people might need.

What is procrastination?

Wikipedia defines Procrastination as:

a practice of carrying out less urgent tasks in preference to more urgent ones, or doing more pleasurable things in place of less pleasurable ones, and thus putting off impending tasks to a later time, sometimes to the “last minute” before a deadline.

The task which can be getting a hair-cut, writing an academic paper, or coding the first version of the application. Paul Graham, in one of his essays argues that procrastinating over the first isn’t necessarily bad if it serves a better purpose but the most common way people procrastinate is either by endlessly browsing social media sites, watching netflix, playing video games or any similar activity which echoes the sentiment of “doing nothing”. In short, procrastination is “wasting time” which could otherwise, be spent in a more productive manner.

Creating Side-scroller Game in HTML5 and Javascript

| Comments

Recently I completed my first game, Penguin Walk, with help of free art in Javascript and it gave me empirical experience of a known-fact surrounding game development – “The hardest thing about developing a game is finishing it.”

Although, the game is dead simple and code runs in only few hundreds of lines, it took a lot of effort to finish it. The reason? I believe the hard thing related to game development, is that you are attempting to build something complex out of very simple elements (pixels). The same reason why building a programming language is hard – you are trying to ensure that a stream of characters obeys formal grammatical rules and convert them into something that can execute. In this post, I will describe how I created my side-scroller game.

Is Game Programming hard?

Think about it. What does it take to project a bird from a slingshot, show it flying in projectile motion, hitting a set of object which are then animated to move accurately, in accordance to laws of physics? Well, a lot. You can only tell computer what to paint on the screen, rest of all the higher level abstractions, you build on your own.

Although, using a library might help a lot; after all, who can be expected to complete a desktop application if he has to program all controls on his own but if you compare the two, there are two complications that arise in game development –