Old 744 Forum

Archived posts

Can I Just Say...

Page: 1

Author Post
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)


:evil: :x
_______________
Moderator
Registered: May 2009
Posts: 5140
Quote
What was it?

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)
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
Member
Registered: May 2009
Posts: 414
Location: Mumbai, India
Jeroen Hoppenbrouwers wrote
At work, we developed the habit of just asking the neighbour to look over the problem line(s) ...


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?"
Member
Registered: May 2009
Posts: 479
Location: EFTO
John Golin wrote
What was it?
 if (this.aSpeaker.muteState = true && sDL != null)

instead of
 if (this.aSpeaker.muteState == true && sDL != null)

hehehe John, never happens to me . . . any more... :D

And while we're at it, remember
if ( string1 == string2)...
vs.
if ( string1.equals(string2) )...

:mrgreen:
Member
Registered: May 2009
Posts: 772
Location: Sydney, Australia
Hardy Heinlin wrote
Too little sleep? :-)

Possibly! :) Also, too much wine the night before... :)
Quote
...
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)


Good point! I will go back and tidy that up as well! I have a mix of code due to learning as I went :) I already have Radio.isWorking and ACP.isWorking... if there is one thing that is consistent in my code, it is lack of consistency! :lol:

Even though I totally broke the program, I'm glad I'm overhauling the code - It was so 'dirty' in the original state.... :) I love OOP now!

Bloody part time programmers! :P
_______________
« Last edit by John Golin on Sun, 22 Apr 2012 21:46:26 +0000. »
Member
Registered: May 2009
Posts: 772
Location: Sydney, Australia
martin wrote
And while we're at it, remember
if ( string1 == string2)...
vs.
if ( string1.equals(string2) )...

:mrgreen:


Oh yeah - that one is easy to remember - NetBeans prompts me if I make that 'mistake' :)
_______________
Moderator
Registered: May 2009
Posts: 2449
Location: KTMB
What's wrong with a pointer?! :mrgreen:
Member
Registered: May 2009
Posts: 479
Location: EFTO
Jeroen Hoppenbrouwers wrote
What's wrong with a pointer?!

This?
Function:
int mymax (int(*a)(int(*)(int(*)()),int(*)(int(*)(int**))), int(*b)(int(*)
(int(*)()),int*,int(*)(int(*)()))){return (int)((((int(*)(int(*)(int(*)()),int(
*)(int(*)())))a)> ((int(*)(int(*)(int(*)()),int(*)(int(*)())))b))?((int(*)(
int(*)(int(*)()),int(*)(int(*)())))a):((int(*)(int(*)(int(*)()),int(*)(int(*)(
))))b));??>

Function call:
mymax((int(*)(int(*)(int(*)()),int(*)(int(*)(int**))))3,(int(*)(int(*)(int(*)
()),int*,int(*)(int(*)())))52);

"This works 100% fine for the intel / motorola architecture."
[source]

8)

Page: 1

Old 744 Forum is powered by UseBB 1 Forum Software