• Post Reply Bookmark Topic Watch Topic
  • New Topic

using if condition effects perfomance or writing more lines of code effects performance?  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while displaying colored balls in the VIBGYOR color sequence, only coordinates are to be changed.
so if i can use if condition to give coordinates for the color or should write entire code again and again with the coordinate changes for each color? which is the best way of writing code, keeping performance as priority. thanks in advance.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What you should always keep in mind first is writing clear, easy to understand code. That is far more important than worrying about performance. Don't write code a certain way just because you have a feeling that it will perform better that way. Write clear code, make sure that it works correctly. Only think about optimizing performance when there really is a performance problem, and if you do, then do it by measuring, with a profiler, so that you know exactly which part of the code needs to be optimized.

Worrying about micro-optimizations, like whether an if-statement might be slow, is a waste of time. Most likely it does not matter at all for the performance if you use an if-statement or not.

siresha tumma wrote:... should write entire code again and again with the coordinate changes for each color?

Copy-and-paste programming is (almost) never a good idea.
 
siresha tumma
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much for your reply. i always had this doubt while coding. now i am happy my doubt is cleared.thank you once again.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!