View Single Post
  #7   Spotlight this post!  
Unread 04-02-2015, 22:42
cstelter cstelter is offline
Programming Mentor
AKA: Craig Stelter
FRC #3018 (Nordic Storm)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Mankato, MN
Posts: 77
cstelter will become famous soon enough
Re: Limit Swtich Help

Quote:
Originally Posted by mmaunu View Post
Ether: I have learned so much from reading your posts and papers over the years. I didn't intend to sound like I was correcting your post but merely adding explicit context for other readers.
I for one appreciated the post. As a C/C++ guy who only recently has been using java (and only WRT FRC), I would have expected

Code:
int x=0;
if(x=8)
{
}
to compile fine. I didn't realize the if statement was strongly typed to boolean in java (kind of would have expected it to be overloaded to many types or that there may be some sort of implicit conversion of int to boolean that would happen transparently.)

Of course had I tried to code it, eclipse/netbeans/whatever would have let me know I was wrong long before I tried compile.

Reminds me of the most 'duh' moment I ever had that IDE's don't tend to flag for us yet. I had coded something along the lines of

int x=0;
...
if(x==4 && something_else==2 && something_else==some_other_thing);
{
//some stuff to do
}

It took me the longest time to figure out why I kept entering the if clause even though I was nearly 100% certain that x was *not* 4 and thus the hypothesis should evaluate to false. Finally I put in a sanity check to print x and confirmed that I was right (x was not 4 and the full expression for the if evaluated to false). Only then was I able to see the error of my ways...

sorry to send this slightly off topic.... I did appreciate the points made thoug.
Reply With Quote