Go to Post Remember everyone, during build season, if you mess something up..... In the words of Adam Savage... Failure is always an option! (and so is blowing stuff up) - J.Warsoff [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-03-2013, 21:51
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Anonymous functions

I want to do something like this

Code:
private ExtendedBoolean b = new ExtendedBoolean(){return m_pressed};
private void run()
    if(b){
        motor.set(1);
    }
}
but the only way i can do it now is

Code:
private ExtendedBoolean b = new ExtendedBoolean(){private boolean get() return m_pressed;};
private void run()
    if(b.get()){
        motor.set(1);
    }
}
which just looks ugly in my opinion. Is there a good way to do it?
Reply With Quote
  #2   Spotlight this post!  
Unread 31-03-2013, 20:24
armgeek's Avatar
armgeek armgeek is offline
Raspberry Pi Enthusiast
AKA: Tyler Pawlaczyk
FRC #0340 (Greater Rochester Robotics)
Team Role: Programmer
 
Join Date: Mar 2013
Rookie Year: 2011
Location: Rochester, NY
Posts: 10
armgeek is an unknown quantity at this point
Re: Anonymous functions

This is a "good" way to do it.

However, you could make it look a lot "neater" if you changed the "get" method's name to "pressed". That way the if statement would read more like English would.
__________________
I enjoy ARM processors.
Looking to earn rewards for working on Open-Source projects that help FIRST? You may be interested in the Summer of FIRST 2013 project. More info: 2013.summeroffirst.org
Also, visit my (sparse) blog: rainingbitsandbytes.blogspot.com
Reply With Quote
  #3   Spotlight this post!  
Unread 31-03-2013, 21:06
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Anonymous functions

I'm generally of the opinion that little bits of ugliness like that are necessary evils in programming. While I'd love it if everything could be simply and elegantly expressed, reality tends to disregard my desires. However, the example you gave was such that the only non-"ugly" solution was what you suggested, which isn't possible in Java. Depending on what you're trying to do (as opposed to how you're trying to make it look), there might actually be an elegant solution.
__________________
I code stuff.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi