RubyOnRails

MVC Antipatterns : Models Antipatterns

Here are some excepts from Rails Antipattern book that I have reading lately. Even though the examples are specific to rails, the fundamental principles applies to pretty much any MVC framework. In this post, I list out various Model Antipatterns & their potential solutions. I would be writing about other anti-patterns in next posts …

Antipattern # 1 : Voyeuristic Models

  • Solution: Follow the Law of Demeter

  • Solution: Push All find() Calls into Finders on the Model

  • Solution: Keep Finders on Their Own Model

AntiPattern # 2 : Fat Models

  • Solution: Delegate Responsibility to New Classes

  • Solution: Make Use of Modules

  • Solution: Reduce the Size of Large Transaction Blocks

AntiPattern # 3 : Spaghetti SQL

  • Solution: Use Your Active Record Associations and Finders Effectively

  • Solution: Learn and Love the Scope Method

  • Solution: Use a Full-Text Search Engine

Advertisements
RubyOnRails, Technology and Software

Complexity is the biggest enemy of successful projects

Curiosity killed the cat & complexity killed the project !!

2008-03-17-curiosity-killed-the-catThe importance of simplicity in application development is paramount. Complexity is the number-one killer of projects today, and it comes into an application in many ways, including through excitement over new features, overly clever developers, and unfamiliarity with the Ruby on Rails framework.

Geeks, Tech, Startups, opensource, Technology and Software, Web Culture

The dark craft of Engineering Managemet – Laura Thomson

I came across this wonderful post by Writer & veteren PHP developer Laura Thomson titled The dark craft of Engineering Management. Completely agree with her. Here are some excerpts that I liked in particular:

“Management is the craft of enabling people to get things done.”

Engineers, in general, know their jobs, to a greater or lesser extent.  My job, as an engineering manager, is to make their jobs easier.

Autonomy is the key to scaling yourself as an engineering manager.  As an engineer, I hate nothing more than being micromanaged.  As an engineering manager, my job is to communicate the goals and where we want to get to, and work with you to determine how we’re going to get there.  Then I’m going to leave you the hell alone to get stuff done.

Don’t become an engineering manager because you want power – that’s the worst possible reason.  A manager is a servant to their team.  Become a manager if you want to serve.

 

Geeks, Tech, Startups, opensource, Technology and Software

Online Privacy & National Security – A statement by Oxblood Ruffin

I had the pleasure to listen to Oxblood Ruffin at All India Privacy Symposium at New Delhi last week & was hugely impressed by the way he put the case for on-line privacy in very simple yet extremely persuasive words. I particularly liked the analogy between our virtual selves and our covered real selves. I have included the complete statement for the readers.

 The online citizenry of any country is part of its national security infrastructure. And the extent to which individual privacy rights are protected will determine whether democracy continues to succeed, or inches towards tyranny. The challenge then is to balance the legitimate needs of the state to secure its sovereignty with protecting its most valuable asset: The citizen.

It has become trite to say that 9/11 changed everything. Yet it is as true for the West as it is for the global South. 9/11 kickstarted the downward spiral of individual privacy rights across the entire Internet. It also ushered in a false dichotomy of choice, that in choosing between security and privacy. It was privacy that had adapt to the new realities, or so we’ve been told.

Lets examine some of the fallacies of this argument.

* The false equation. Many argue that we must give up privacy to ensure security. But no one argues the opposite. We needn’t balance the costs of surveillance over privacy, because rarely banning a security measure protects privacy. Rather, protecting privacy typically means that government surveillance must be subjected to judicial oversight and justification of the need to surveil. In most cases privacy protection will not diminish the state’s effectiveness to secure itself.

* The deference argument. Security advocates insist that the courts should defer to elected officials when evaluating security measures. But when the judiciary weighs privacy against surveillance, privacy almost always loses. Unless the security measures are explored for efficacy they will win every time, especially when the word terrorism is invoked. The courts must take on a more active role to balance the interests of the state and its citizens.

* The war time argument. Security proponents argue that the war on terror requires greater security and less privacy. But this argument is backwards. During times of crisis the temptation is to make unnecessary sacrifices in the name of security. In the United States, for example, we saw that Japanese-American internment and the McCarthy-era witch-hunt for Communists was in vain. The greatest challenge for safeguarding privacy comes during times when we are least inclined to protect it. We must be willing to be coldly rational and not emotional during such times.

We are often told that if you have nothing to hide, you have nothing to fear. This is the most pervasive argument the average person hears. But isn’t privacy a little like being naked? We might not be ashamed of our bodies but we don’t walk around naked. Being online isn’t so different. Our virtual selves should be as covered as our real selves. It’s a form of personal sovereignty. Being seen should require our consent, just as in the real world. The state has no business taking up the role of Peeping Tom.

I firmly believe that the state has a right and a duty to secure itself. And I equally believe that its citizens are entitled to those same rights. Citizens are part of the national security infrastructure. They conduct business; they share information; they are the benefactors of democratic values. Privacy rights are what, amongst others, separate us from the rule of tyrants. To protect them is to protect and preserve democracy. It is a fight worth dying for, as so many have done before us.

Thank you.

Oxblood Ruffin

You can follow Oxblood on Twiitter @Oxbloodruffin

Blogosphere, Linux, productivity, Technology and Software, tricks

cURL – Swiss Army Knife for Web Sites

Lately, I have been using cURL a lot to diagnose & get more information about web pages download times, header information, automation of such tasks etc. Therefore I thought some of the very useful but not so obvious usage of cURL.

first of all, if you want to download a copy of a page to a local file, you can use

curl http://www.example.com -o local_copy.htm

If you don’t want to neccessarily download the file but only want to see response headers, you can do

curl -I http://www.example.com

If the web site is returning a redirect, 30x HTTP response code, you can ask curl to follow the redirect for example

curl -IL http://www.example.com

You can specify multiple URLs to curl as part of pattern for instance:

curl -I http://{www,play,sawaal}.ibibo.com

Output:

[1/3]: http://www.ibibo.com –> <stdout>
–_curl_–http://www.ibibo.com
HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 18:19:05 GMT
Server: Apache
Vary: Accept-Encoding
ServerID: Myibibo-34
Content-Type: text/html

[2/3]: http://play.ibibo.com –> <stdout>
–_curl_–http://play.ibibo.com
HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 18:19:08 GMT
Server: ibibo-WS
Cache-Control: no-transform
Vary: User-Agent,Accept,Accept-Encoding
ServerID: 25
Content-Type: text/html

[3/3]: http://sawaal.ibibo.com –> <stdout>
–_curl_–http://sawaal.ibibo.com
HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 18:19:08 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Set-Cookie: ASP.NET_SessionId=tu5c1y555oywv4fvxj1vj245; path=/; HttpOnly
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 112910

You can also specify advanced regular expressions when using the URLs for instance:

ftp://ftp.numericals.com/file[1-100].txt  ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)  ftp://ftp.letters.com/file[a-z].txt

Nested sequences are not supported, but you can use several ones next to each other:

http://any.org/archive[1996-1999]/vol[1-4]/part{a,b,c}.html

You can specify any amount of URLs on the command line. They will be fetched in a sequential manner in the specified order.

You can specify a step counter for the ranges to get every Nth number or letter:

http://www.numericals.com/file[1-100:10].txt  http://www.letters.com/file[a-z:2].txt

More later in another post.

opensource, Ruby on Rails, Technology and Software, Web Culture

Underdo Your Competition – on building web apps by David Heinemeier Hansson

I am reading one of DHH’s old book “Getting Real“. It is a really nice book explaining nice principles on building a killer web app. He emphasizes on building less rather than more. Building less features but doing them extremely well. I am quoting him here as it is:Getting Real

Conventional wisdom says that to beat your competitors you need to one-up them. If they have four features, you need five (or 15, or 25). If they’re spending x, you need to spend xx. If they have 20, you need 30.

This sort of one-upping Cold War mentality is a dead-end. It’s an expensive, defensive, and paranoid way of building products. Defensive, paranoid companies can’t think ahead, they can only think behind. They don’t lead, they follow.

So what to do then? The answer is less. Do less than your competitors to beat them. Solve the simple problems and leave the hairy, difficult, nasty problems to everyone else. Instead of oneupping, try one-downing. Instead of outdoing, try underdoing.

facebook, Ruby on Rails, RubyOnRails, Technology and Software

How to use Delicious to search for useful content

In this post, I would like to explain an extremely useful use-case of one of my favorite and highly popular tool Delicious. Let’s say I came across a useful URL that is relevant to the work that I am doing or stuff that I am interested in. For instance in this case, I came across rFacebook , a ruby gem for interacting with Facebook API.

Now, I want to search for more related links to Ruby, Rails and/or Facebook. Here is what I did:

1) Bookmarked this link on Delicious. As you can see in the image, the Addthis Addon already shows that it has been saved 391 times.

2) Select a few tags for instance rails & facebook in my case & click save. Once you have saved the link as well, it would go to delicious & increment the count by 1. Now it it showing 392 for me.

3) Click on the count to open all the saved items for this URL.

3) Now it shows all the users that have saved this URL & the tags they have used for this URL.

4) You can click on the tags to view other URLs that they have saved for these tags. Lastly, you can also add any of the users that you find useful to your network so that you can quickly browse their bookmarks quickly at any time.

I have found this to be a very useful technique to discover new, useful & relevant content. Hope you find it useful as well.