Is comparison of unrelated objects symantically valid???

The use of specific JADE features and proposals for new feature suggestions
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Is comparison of unrelated objects symantically valid???

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:52 am

by CarlRanson >> Thu, 16 Jan 2003 3:55:20 GMT

We've just been bitten by a bug in some code we inherited that effectively boils down to the following:

given classes Foo & Bar , both descended from Object.

var
foo : Foo;
bar : Bar;begin

....(some code).

if foo=bar then
// code we expected to get called that didn't.
endif;
end;

Consider that foo and bar are on different branches of the class hierarchy, i.e. foo.isKindOf(Bar) = bar.isKindOf(Foo) = false

Does it really make sense for this comparison to be allowed by the compiler? The only time it could EVER evaluate to true is if foo=bar=null which pretty much all developers would code as if foo=null and bar=null then (do something useful).

Surely it makes more sense that if comparisons are only allowed where assignments would be as well.....(note that foo:=bar would be a 6072 error at compile time).

So for a=b to be valid, either a must be descendant of b or b must be a descendant of a.

Opinions?
CR

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Is comparison of unrelated objects symantically valid???

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:52 am

by CarlRanson >> Thu, 16 Jan 2003 3:58:02 GMT

Ok, so i misspelt "semantically" rather badly. Ever notice that outlook express doesnt spell-check the heading.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Is comparison of unrelated objects symantically valid???

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:52 am

by torrie >> Thu, 16 Jan 2003 8:19:18 GMT

Carl

I agree. I'd much rather the compiler picked up potential bugs rather than trying to debug the code at run time. Should the compiler prevent the method from compiling or just make you aware of the problem?

Torrie

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Is comparison of unrelated objects symantically valid???

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:52 am

by allistar >> Thu, 16 Jan 2003 9:39:21 GMT

What you have found is basically the same as comparing an Integer and a String (without any casting). The compiler definitely complains about that sort of comparison, it seems that comparing incompitable objects should also make the compiler complain.

Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz ------------------------------------------------------------------


Return to “Feature Discussions”

Who is online

Users browsing this forum: No registered users and 6 guests

cron