I apologize for resurrecting this thread, but I figured it'd be better writting here than making a new one.
I have a few more questions:
1- Sould non void functions always return a value ?
Lets say I have a function that returns true if some condition is met. Should it return false if it isn't ?
2- does checking many conditions at once affects performance more than using nested if-elses ?
e.g:
Code:
if(someConditionIsMet) && (someConditionIsMet) &&(someConditionIsMet)
doSomething();
VS
if (someConditionIsMet)
if(someConditionIsMet)
if (someConditionIsMet)
doSomething();
3- is it OK to allow a variable to be assigned the same value over and over, for convenience purposes. Or is it better to check if the variable has the value already ?
e.g:
Code:
...
intVar = 7;
...
VS
...
if (intVar != 7)
intVar = 7;
...
4- Which leads to the main question, what is more expensive for the cpu; retrieve the contents on a var and compare them, or simply writte to to memory ?
Thanks in advance.