I just spent about 5 hours looking for a bug. What was it?
if (this.aSpeaker.muteState = true && sDL != null)
instead of
if (this.aSpeaker.muteState == true && sDL != null)


_______________
Page: 1
Author | Post |
---|---|
#1 Sun, 22 Apr 2012 06:58:59 +0000
|
|
Member
![]() Registered: May 2009
Posts: 772
Location: Sydney, Australia
|
AUURGGGHHHH!H!!!
I just spent about 5 hours looking for a bug. What was it? if (this.aSpeaker.muteState = true && sDL != null) instead of if (this.aSpeaker.muteState == true && sDL != null) ![]() ![]() _______________ |
#2 Sun, 22 Apr 2012 08:19:38 +0000
|
|
Moderator
![]() Registered: May 2009
Posts: 5140
|
Too little sleep? :-) By the way ... well, we all know there are languages where booleans can have more states than true and false so that the "==" method has to be used. However, in languages such as Java we also know that booleans can have only two states; I always name them with an adjective (the Java makers recommend names starting with "is...") and never use "==" in boolean tests, this makes life easier. E.g.: if (this.aSpeaker.isMuted && sDL != null) |
#3 Sun, 22 Apr 2012 13:30:54 +0000
|
|
Moderator
![]() Registered: May 2009
Posts: 2449
Location: KTMB
|
John,
I've seen hard-core programmers use a different syntax to exactly prevent this kind of hard-to-spot error, but personally I don't use this syntax either as I find it counter-intuitive: if (true == this.aSpeaker.muteState && null != sDL) Such a statement cannot be compiled if you mistakenly use the = sign. Of course it won't help any bit if there is an assignable expression on the left side. At work, we developed the habit of just asking the neighbour to look over the problem line(s) when you stop seeing your own mistakes. We all know this is not unnecessary bothering of each other. It usually produces the issue in about 15 seconds. Very annoying indeed. Jeroen |
#4 Sun, 22 Apr 2012 14:45:22 +0000
|
|
Member
![]() Registered: May 2009
Posts: 414
Location: Mumbai, India
|
Haha ... I can just picture John leaning over the hedge with his laptop and saying, "G'day, Mrs. Julia Gillard, could you just have a quick look at this code and see if you spot something funny?" |
#5 Sun, 22 Apr 2012 17:43:41 +0000
|
|
Member
![]() Registered: May 2009
Posts: 479
Location: EFTO
|
hehehe John, never happens to me . . . any more... ![]() And while we're at it, remember if ( string1 == string2)...vs. if ( string1.equals(string2) )... ![]() |
#6 Sun, 22 Apr 2012 21:39:20 +0000
|
|
Member
![]() Registered: May 2009
Posts: 772
Location: Sydney, Australia
|
Possibly! ![]() ![]()
Good point! I will go back and tidy that up as well! I have a mix of code due to learning as I went ![]() ![]() Even though I totally broke the program, I'm glad I'm overhauling the code - It was so 'dirty' in the original state.... ![]() Bloody part time programmers! ![]() _______________ « Last edit by John Golin on Sun, 22 Apr 2012 21:46:26 +0000. » |
#7 Sun, 22 Apr 2012 21:42:05 +0000
|
|
Member
![]() Registered: May 2009
Posts: 772
Location: Sydney, Australia
|
Oh yeah - that one is easy to remember - NetBeans prompts me if I make that 'mistake' ![]() _______________ |
#8 Mon, 23 Apr 2012 12:06:17 +0000
|
|
Moderator
![]() Registered: May 2009
Posts: 2449
Location: KTMB
|
What's wrong with a pointer?!
![]() |
#9 Mon, 23 Apr 2012 12:36:55 +0000
|
|
Member
![]() Registered: May 2009
Posts: 479
Location: EFTO
|
This? Function: int mymax (int(*a)(int(*)(int(*)()),int(*)(int(*)(int**))), int(*b)(int(*) Function call: mymax((int(*)(int(*)(int(*)()),int(*)(int(*)(int**))))3,(int(*)(int(*)(int(*) "This works 100% fine for the intel / motorola architecture." [source] ![]() |
Page: 1
Staff List · Statistics · RSS Feed · Contact Admin
Old 744 Forum is powered by UseBB 1 Forum Software