Any advantage of optimizing things like loops, conditional checks, variables.etc? [closed]

StackOverflow https://stackoverflow.com/questions/23431093

  •  14-07-2023
  •  | 
  •  

Domanda

I am curious to know that should we optimize loops, conditional checks, setting variables and unsetting them after they are used in PHP?

Is the foreach loop better then the for loop?

When I make IF-ELSE condition? Is it better to use ELSE clause or eliminate it altogether?

Does functions come in to play when optimizing code? Is strstr better than strspos?

Does these stuff important when coding or is it just personal preference?

I hope this makes sense.

È stato utile?

Soluzione

I'd suggest focusing on the functional aspects of your code first. Make it easy to understand, easy to work on - maintainable.

Prematurely optimizing all of your code eats up lots of time, and may not be necessary.

Additionally, there are lots of myths / misconceptions about optimization and what is effective - making it all the more important to a) make sure there is an actual need for detailed optimization in the first place and b) invest the time to do it properly.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top