• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I 'optimize' this set of if-else statements?  RSS feed

 
Ranch Hand
Posts: 34
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I have this set of 'if' and 'else' statements which works perfectly, however, it looks messy... I thought about using |,|| operators, i.e. if(hour.getText().equals("") | (minutes.get.....) | (..) //but this still will need if's to identify what's empty... Am I missing a trick or is this already fairly optimized?


thanks
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, work on your indenting. It's really wonky.
 
Benjamin Scabbia
Ranch Hand
Posts: 34
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Hint:


Fantastic solution, exactly what I was looking for - I'm surprised I didn't think of it to be honest!
Not sure what code went wonky, must have been a copy/paste issue.
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Benjamin Scabbia wrote:
Bear Bibeault wrote:Hint:


Fantastic solution, exactly what I was looking for - I'm surprised I didn't think of it to be honest!
Not sure what code went wonky, must have been a copy/paste issue.


I would suggest using

That is functionally the same, but makes your intent clearer.
 
Benjamin Scabbia
Ranch Hand
Posts: 34
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike. J. Thompson wrote:

I would suggest using

That is functionally the same, but makes your intent clearer.


I like this, I agree makes intent clearer. Thanks!
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Benjamin Scabbia wrote:I like this...

And then of course there's always:but sometimes you can overdo optimization.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!