Decision of control mechanism (Necessity of if condition?)
Suppose I have a profile page which has these values: name, last name,
username, follower and following counts.
They may be updated after user logged into my application. So there is a
refresh button. When user clicks to refresh button, I am calling a web
service to get new values. In return, I get 5 values.
Here is example:
Suppose I have called web service and parsed return values into my
response class.
// Here is first approach.
if (!response.name.equals(name)) {
name = response.name;
}
if (!response.lastname.equals(lastname)) {
lastname = response.lastname;
}
// Here is second.
name = response.name;
lastname = response.lastname;
In first approach, I believe if condition is required because if their
values same, I won't lose time with assign operation. And also we know
that if condition is the fastest operation can computer does.
In second approach, I believe if condition is not required because I
already access both values in the if condition (name and response.name),
instead of losing time with accessing them, not consider that they are
same or not. Just make assignment.
Now, I want to know what is the faster way?
Thanks in advance.
No comments:
Post a Comment