Use of Cartisian Products?

  • Thread starter Thread starter Brett
  • Start date Start date
B

Brett

Where are cartisian products, http://c2.com/cgi/wiki?CartesianProduct, used
in the majorithy of non scientific oriented software (and besides the query
example given in the previous link)?

From the previous link, "Identifying hidden Cartesian products in a design
is my favorite way of spotting code which can be refactored with really big
benefits." How is that so? Any one have some non scientific examples?

Thanks,
Brett
 
Brett said:
Where are cartisian products, http://c2.com/cgi/wiki?CartesianProduct, used
in the majorithy of non scientific oriented software (and besides the query
example given in the previous link)?

From the previous link, "Identifying hidden Cartesian products in a design
is my favorite way of spotting code which can be refactored with really big
benefits." How is that so? Any one have some non scientific examples?

Every nested loop is a cartesian product, in the context to which is
referred in your second paragraph:

for(int i=0;i<foo;i++)
{
//..
for(j=0;j<bar;j++)
{
//...
}
}

(or foreach loops of course)

more hidden cartesian products are calls in a loop and the methods
called contain a loop too.

These kind of constructs often show potential slow code, though it can
be the code is necessary.

I wouldn't use it to optimize code though, as it smells like
micro-optimization, which does more bad than good.

Frans


--
 
Frans Bouma said:
Every nested loop is a cartesian product, in the context to which is
referred in your second paragraph:

for(int i=0;i<foo;i++)
{
//..
for(j=0;j<bar;j++)
{
//...
}
}

(or foreach loops of course)

more hidden cartesian products are calls in a loop and the methods called
contain a loop too.

How are for loops products? Because like this occurs:
foo(i)

The above is a product of "foo" and "i".

What is the difference between a product and cartesian product?

Thanks,
Brett
 
Back
Top