Monday, 1 June 2015

Disadvantages of creating excess instance variables


As we have heard that "creating unnecessary or excess instance variables is a bad practice."
but I don't understand why is it so, I started searching about this but couldn’t found a meaningful stuff, then I Dig a bit deeper and found that

As the number of instance variables increase there is a small increase in response time of application.

"A Rails view doesn’t have direct access to its controller’s instance variables."

After reading this a question arises "Then how can we access then controller's instance variable in view ??"

let me explain it: The source says that "The controller’s variables are transferred to the view renderer." which means all instance variables will be copied from the controller to the view you are using them or not, this process takes some CPU cycles which increases the response time of application by a time interval.

The Best practices say that we should have view with only a single instance variables as maintaining a single instance variable is simpler and easier

No comments:

Post a comment