Your browser (Internet Explorer 7 or lower) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.

X

Navigate / search

Test Driven Development: Development By Capturing Assumptions

When you normally develop, assumptions are made in about the behavior of each function you call and each class you instantiate. If you are using a well published API those assumptions are safe assumptions. These assumptions are documented in the API documentation. They have been throughly tested by the API developers and so they are known to work. What about the programming constructs in your application that you wrote? Are you absolutely sure that they do what they say they do? For example, you may create an function called add(). You may just have a return statement that adds two variables. But what if you wanted that function to also be able to handle non-numeric additions. What if you wanted it to add two vectors or two complex numbers? Normally those assumptions would be a made in the writers mind as a fog of thought that lead to the act of typing the code. When someone else reads the code again, they form assumptions on how they expect the code to function based on their impression of what the application should be doing and how the code should have been written. Writing unit tests is the act of making those assumptions explicit. I think it is wrong to call test as “tests”. I feel it is more appropriate to call them assumptions or expectations.

Setting Up A Continuous Integration System = Big Win

One of the most invaluable things I’ve learnt is continuous integration, test driven development, and object oriented programming. Those of you who are not technically inclined may skip to the next paragraph but if you are  - You might be balking at my not knowing OOP already.

Yeah, professors talk about the “Shape” class and how the “Circle” class extends from it and how Circle is an instance of Shape and blah blah. None of that shit is how anyone would approach a real world software development. The fact is all of that is complete bullshit.  You don’t do OOP by forming this enormous inheritance hierarchy, nail every detail and start to implement it with a bunch of interns. The hierarchy in my opinion emerges.  I always knew about OOP in an abstract level but I never learnt it the way I was taught in ThoughtWorks. One major issue that has caused me to lose ground to competing plugins is my efforts being squandered and wasted away by doing fire fighting. But now I have a solution to this. I am slowly bringing in test coverage for all of the functionality in the plugin. I am setting up a continuous integration system where the following checks are performed every time I make any progress or make any changes to the plugin automatically:
  • Whether all existing functionality is working on the latest version of WP Autoresponder
  • Whether the plugi’s existing functionality works in all versions of WordPress 3.5.2 and above.
  • Whether the plugin’s functionality works as expected when WP Autoresponder is upgraded from v5.2.8 and above to the latest development version.
I have to admit, a lot of times I came very close to giving up given all the frustrations I was going through. It seemed like I was running on a treadmill and going nowhere and felt powerless to change the situation. The day I discovered what I can do with jenkins and the benefits of TDD, unit testing, refactoring was the day I regained some confidence and hope that this project is worth continuing and confidence that the vision I had can be achieved. Once I started adding unit tests to my project and set up a CI environment, I am able to see very real confidence that a given section of my code will not break again and if it does, I will get instant notification of it when it does. By immediate I mean immediate – I will receive a message on my personal phone number if I make a breaking change. This is a huge win for the development of the plugin because I won’t face the nerve wracking anxiety that I generally feel before making a release because I can have the confidence of knowing everything works at all times. It is finally possible to get to a place where I am able to make a new release once every 2 weeks or so and that’s exactly where I want to go! I can see that the development can get so pleasurable that releasing a new version will be as simple as clicking on a button at any time as against the 2 weeks of preparation I am used to doing from before.

Why Reddit Is Awesome

Reddit if you haven’t heard is where all the action is these days on the internet. Apart from that blackhole of the Internet called 4chan, it is the most happening place. I have tried many times to quit reddit but I am not able to. I thought I would take a little time and explain why I like reddit so much: I meet a lot of people that are like me.

Expression Of Subtle Thoughts

People express very intimate and subtle thoughts that I am sure everyone has but we never acknowledge. This to me is the biggest reason for why I am on reddit. I like to read about about all the thoughts that other people have when they experience many life experiences. The thought you feel when you [some mundane activity] to [life changing outcome].

Alternative View Points

Reddit I have found is a great place to find an alternative view point to almost any topic. People express many perspectives on an issue and are surprisingly knowledgeable.

Stories

Reddit is an enormous collection of life experiences of so many people. Sure, a great number of the stories are probably fake. But I find many stories posted by other users eerily similar to my own experiences.

Education

It is very educational to read some of the many sub reddits in reddit. I am a fan of the technology and science subreddit as well as the ones for some games like half life, bioshock and such. There are many small communities there that it is amazing. Reading the TODAYILEARNED section is really incredible. It really shapes your point of view about the world given the nature of many of the things that are posted there run against the common notion of how the world runs.

WorldNews

The worldnews section of the website is a way to get an alternative right-wing-ish viewpoint of the world. It is an alternative western-tilted view point and not a balanced one. What becomes popular there is what suits a particular world-view. It is the worldview of the slightly naive mid to late 20s individual who was born in the 80s, probably geeky, probably idealistic, atheistic, westernized and tech savvy. There is a community for everything.

What effect has reddit had on me?

Forgiving of Self - I am a lot more forgiving of myself. I am a lot more forgiving of my feelings I don’t feel like I should be ashamed of having some needs that I do. I noticed that as a result of reading reddit, I am able to be better aware of my feeling and thoughts. It makes me realize that I should blog more and write more of my thoughts here or on my personal blog. I have learned that Americans are very expressive of their thoughts and learnt the advantage of being like that. I learnt the advantage of expression. Lot More Expressive - I am a lot more expressive of what I feel. This I believe is something that is unique to americans. They are very expressive. This I believe is something that is very important for me as an Indian because in India’s culture expression is not encouraged. It is just not encouraged, people actively work against it. The act of putting something in expression puts people on the defensive. Beware though! But do be aware that you could end up wasting long long hours at reddit. While it is a good pass time, it can be a bottom less pit. It is like an internet of its own. There are so many obscure sub-reddits that will suit your most mildest interests. It is mostly comprised of people of mid to late 20s – people born in the 1980s. So you are likely to get a little too comfortable with your faults and failures while  on reddit since it creates an impression that there are so many people in the world that share your faults.

My take on Twitter Bootstrap

Twitter bootstrap is suddenly, for the second time, getting a lot of attention from a lot of people. Some popular ideas floating around the hackerwebz are:
  1. Don’t Use Twitter Bootstrap Like A Million Other Websites -  One argument is that using Twitter bootstrap makes your website seem immediately recognizable as a Twitter Bootstrap website. 
  2. People Like The Websites Made With Twitter Bootstrap – The websites and applications made with Twitter bootstrap are great and they look good.
What do I make of it?
  1. There was a time when I was able to recognize that my friend’s digital logic assignment was a copy paste of a Wikipedia article in a fraction of a second. That’s what’s happening here. Except other developers, no one else, especially not your target users are going to know that you used twitter bootstrap.
  2. Most people don’t understand what Twitter bootstrap is. You’d be surprised how few people actually understand what it really is. I have seen people in high end IT consulting think it is some tool that will save developers from cross platform inconsistencies.
  3. Twitter bootstrap is good enough. It solves a problem – make a good looking app without having to design it and having to learn CSS. But it encourages a lot of bad practices. I am a big fan of semantic mark-up. I want my HTML to read like XML. I may use it myself in a project of mine in the future.
  4. Putting any dumb idea in writing and having it trend in hacker news is enough to get some importance attached to the message. Some people will actually start believing that shit.

No, I haven’t give up on the plugin.

I have been seeing a lot of posts recently online on the WordPress forums, elsewhere and in direct email to me asking me if I have given up development of the plugin. Allow me to make this very explicit and clear: No. I haven’t given up on the plugin. The current status of the project is that I am focusing on the autoresponder logic’s re-write. The previous implementation was very complicated, very brittle, very prone to breaking. I have built way too much and I am suffering for it. The past one and a half years has been spent on fire fighting and I wish to stop this from happening in the future. I wish to move away from this chaos and build a very good tool that can potentially become an industry standard.

Putting my foot down and doing it right

I have decided to put my foot down on the demands I get from all over the place. I see my google analytics for this website, and notice that the traffic is falling, I go online and search for WP autoresponder, I notice messages and posts saying I have given up or complaining about the plugin. I have decided that I should stop being swayed by all this and focus on setting up a sound base and safety net – a safety net of systems that will allow me to focus on future development without worrying about things breaking in the future. I have finished the implementation of WP Autoresponder’s autoresponder management interface. The implementation of the autoresponder process with unit test coverage has been a very complicated and time consuming task. It is a very complicated task. I’m currently having to deal with some really complex scenarios I did not think of in the first implementation that are critical to the proper functioning of an autoresponder. Along the way I’ve made innumerable mistakes, despite by great efforts to put some foresight, learnt a lot about PHP, WordPress and generally developing software. I wish to do this – develop the autoresponder process, once and only once. I would really like not to have to keep putting out the same fires over and over again in subsequent releases and actually move forward to a place where this plugin becomes a viable alternative to paid email marketing services. I’m sorry for the extended delay but this needs to be done right. As you are well aware I am having to develop the plugin in my free time and there hasn’t been much of that lately. We’re all doing the best we can with what time we have.

Grid Frameworks Are The New Tables

Grid layouts seem to be a new fad in web development. There is massive misunderstanding of them too. I am not going to establish what they are. I’ll get straight to the point:

Grid Frameworks Are Not An Alternative To Knowing CSS

Grid frameworks give you a shortcut to laying things on the screen. You don’t have to specify dimensions or percentage widths for the page to lay things on the screen, you can just use the following code, including the grid framework css using a link tag and start seeing things fall in place.
<div class="row">
   <div class="span2">some content goes here</span>
   <div class="span4">some other content goes here</span>
</span>
In other words, grids are being used as glorified tables. I have run into a lot of people who say laying things out using a table is an awful despicable practice but these people won’t flinch before using the new awesome shiny spanking grid framework to layout a non-grid visual design. Problems with grid frameworks:
  1. they are the same thing as tables. They mix layout information with presentation mark-up.
  2. they don’t describe the content that it encloses.
  3. they are often misunderstood as the tool
I was in a project once where one of the more influential members insisted that I use twitter bootstrap for its grid framework because of he thought it would ensure that the application rendered uniformly across the screen. Not only was this a misguided approach, using a grid framework to code a non-grid framework is actually more work than if no grids were used.

What are grid layouts?

Grid layout is a visual design paradigm where the elements on a page are laid out vertically and horizontally to make it easy on the eyes to scan the content. They have nothing to do with “cross-browser uniformity”. No I don’t mean that grid layouts are reserved for those designs where the elements line up vertically. I am saying that, in keeping with front-end engineering best practices,  you should be implementing that design in XHTML/CSS using proper naming of the class and id names that describe the content anyway. Don’t ever use grid frameworks. They are not to be used. Unless you WANT an alternative to typing css, if you find that using grid layout makes your life easy when trying to quickly code up the application’s UI then go right ahead. Just know that you are using a shortcut and not implementing a grid design. (Which is okay. What are we as hackers if we can’t reuse tools for ways other than intended?)

Keeping Sanity Through Unit Testing

Moving forward in making a application that is as complex as WP Autoresponder requires that I have peace of mind knowing that any new changes that I make, any new features that I implement will not break existing implementations. This has been a major problem over the past year when a fix to an existing issue has broken some other feature. Other than the benefit of being able to have sanity and confidence, it allows me to re organize the internal implementations so as to reduce duplication, and improve the quality of the application over all. I’m currently using phpunit in conjunction with wordpress-unit for testing WP Autoresponder. Much of what I thought would have had to be done through Selenium can be accomplished through phpunit through much less effort. That’s not to say that functional tests on the application using selenium are optional. I fully intend on writing them to ensure that the UI of the application behaves as expected and will always give me feedback going forward when something breaks. Implementing each new feature has been taking a LONG time these days, features that I implemented in days now take me months to finish. Bu this is a necessary investment. Overall, my attitude towards developing the plugin has changed. When I started, I started with the intention of making the most progress as fast as possible. But now, I approach developing this as a craft. As a work of art. :)

What Is A Layout Engine?

A layout engine is the software component that is responsible for rendering web pages. It takes XHTML/CSS that it receives from the server corresponding to a URL. There are currently 3 major layout engines:
  • Gecko – Gecko is the rendering engine used in the Firefox and Seamonkey browsers.
  • Webkit – Webkit is the rendering engine used in Chrome, Safari, Android web browser and iPhone web browser
  • Trident – Trident is the rendering engine embedded in Microsoft Internet Explorer
A rendering engine provides 80% of the browsers functionality. Without it, all you have are the address bar, browser back buttons and status bar if any. I am tempted to say it IS the browser. But there are other components like:
  1. Javascript Engine – The component that executes Javascript embedded in web pages.
  2. User interface for the browser – The back, forward buttons of the browser.
   

Emacs: Opening A File

To open a file in emacs, press Ctrl+x followed immediately by Ctrl+f. The focus will go to the emacs command line:

The bottom of the screen will show a “Find file:” prompt which has the path “~/” preloaded which is the path to your home directory. You can instead type your own path such as “/Users/you/file.txt” to open that file.