Friday, December 12, 2014

Digest for comp.lang.c++@googlegroups.com - 7 updates in 2 topics

"Öö Tiib" <ootiib@hot.ee>: Dec 12 03:47AM -0800

On Thursday, 11 December 2014 18:34:13 UTC+2, JiiPee wrote:
> would do the job, the only small issue is then that Point also has them
> (not a major issue for me though). Is there any other way to do this so
> I could use width and height?
 
The "distance" and "size" are similar (same) in sense that they
are relative (vector) values. "point" however is absolute (location)
value. Therefore there are different operations that may make
sense for us to do with one or other and also the results are
different.
 
For example it does make sense to add distance to point and we
will get other point. It makes sense to add distance to distance
and we get resulting distance. However it does not make sense
to add point to point. Similarly we may multiply (or divide)
distance with scalar and get scaled distance. However it does
not make sense to multiply point with scalar.
 
Therefore if you mix (or merge) "point" and "size" up then what
you will get is nonsense because the meaning of those terms is
lost.
 
There are plenty of tools in standard library to avoid writing
meaningless or confusing classes. For example if you want to bind
two values of type 'T' together but do not want any meaning bound
to that data then you can use 'std::pair<T>' or 'std::array<T,2>'
or 'std::tuple<T,T>'. These all work fine and efficiently with
some difference in usage syntax (so pick what fits your taste).
Usage of such abstract constructs documents that developer has
now taken responsibility to follow and check any "meaning" at
places of usage.
JiiPee <no@notvalid.com>: Dec 12 12:41PM

On 12/12/2014 11:47, Öö Tiib wrote:
> to add point to point. Similarly we may multiply (or divide)
> distance with scalar and get scaled distance. However it does
> not make sense to multiply point with scalar.
 
hmmm, the thing is that I was planning to use Point as a (mathematical-)
vector. But ye, thinking the correct name should be consider here, as
Point is not necessary the same as a mathematical vector. I ll have to
think about this. Although I think in computer graphics its is used a
lot that Point means vector as well. Or at least they are used as if
they are vectors. But I ll have to think about this...
 
Should I then create a "Vector" instead?
 
JiiPee <no@notvalid.com>: Dec 12 01:00PM

On 12/12/2014 11:47, Öö Tiib wrote:
> to add point to point. Similarly we may multiply (or divide)
> distance with scalar and get scaled distance. However it does
> not make sense to multiply point with scalar.
 
I was just thinking it (as a mathematician), and you are actually right!
Point is actually a one dimensional thing, and vector is in 2 dimension.
So probably the correct representation would be:
 
class Point
{
int x,y;
void setPos(int newX, int newY) {x=newX, y=newY}
// ... other 1 demensinal functions
};
 
class Vector : public Point
{
void multiplyByScalar(int a);
};
 
You got me thinking :). hmmm, I think I have to re-arrange my classes
now. This was a good observation. Only thing is that have to think about
the Size.... what is its base class...
JiiPee <no@notvalid.com>: Dec 12 01:17PM

On 12/12/2014 11:47, Öö Tiib wrote:
> Usage of such abstract constructs documents that developer has
> now taken responsibility to follow and check any "meaning" at
> places of usage.
 
So at the moment am thinking of having Point as a base class and inherit
Vector from it. Size maybe needs to be a totally different class,
although then I must multiply some code.
Paavo Helde <myfirstname@osa.pri.ee>: Dec 12 10:53AM -0600

> };
 
> class Vector : public Point
> {
 
As you just said, Vector is not a Point. Thus it makes no sense to derive
Vector (publicly) from Point (Liskov principle is violated!). Your Vector
just inherited the setPos() member function which now can be called on
it. What would it mean? A mathematical vector either does not have any
position, or maybe it has two of them (start and end), if that's what you
want to describe.
 
IOW, there is no need to abuse inheritance just to avoid code
replication. There are other ways to deal with code replication, starting
from extracting the code into a separate ordinary function.
 
 
hth
Paavo
JiiPee <no@notvalid.com>: Dec 12 07:02PM

On 12/12/2014 16:53, Paavo Helde wrote:
>> {
> As you just said, Vector is not a Point. Thus it makes no sense to derive
> Vector (publicly) from Point (Liskov principle is violated!).
 
true. Vector is not a type of point.
 
 
> IOW, there is no need to abuse inheritance just to avoid code
> replication. There are other ways to deal with code replication, starting
> from extracting the code into a separate ordinary function.
 
good idea. I will actually now think of doing this , might be best. But
there are a lot of functions doing the same thing so I really want to
re-use them. but this function thing might be a solution...
shilpa ch <shilparecruiter23@gmail.com>: Dec 12 12:12AM -0800

Hi,
we have urgent requirement on C++ Developer and if you are in the market share the updated resume mail to shilpa.cherukuri@platobpm.com.
 
Job Title: C++ Developer
Location:Andover,MA
Type:Contract
 
JD:
 
---->Good experience in Core C++

.....>At least 7-8 years of Core C++ experience. Understanding of the health care domain is an added advantage. Should have good communication and client interaction skills.

Regards,
Shilpa
US IT Recruiter
Plato Technologies
Mail:shilpa.cherukuri@platobpm.com
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: