r/shittyprogramming • • May 05 '15

Inheritance is beautiful

Post image
321 Upvotes

39 comments sorted by

32

u/pitibow May 05 '15

I did this to save myself some coding. Ovals and rectangles both have an x, a y, a width, a height, etc... they're stored the same way, just drawn differently. Was doing some GUI programming and I didn't want to make more change listeners.

18

u/Tjstretchalot May 06 '15

Add a corner radius to the rectangle, rename to rounded rectangle, allow for corner radius to be 0. The oval is just maximum rounded-ness.

25

u/pitibow May 06 '15

Dang, I had to implement a rounded rectangle already. I should have just used one class for all my shapes!

3

u/thfuran May 08 '15

That class: VersatileRectangle

10

u/UlyssesSKrunk May 06 '15

Why not just have the oval be a superellipse then have the rectangle extend oval and with the exponents set to max int and hope the pixels approximate well.

9

u/IDontBlameYou May 06 '15

It must be more efficient - it takes less classes to support more shapes!

-1

u/[deleted] May 06 '15

lol oop makes simple problems hard.

25

u/thorium220 May 06 '15

Rework circle into oval by giving it two foci instead of one, a circle is then focus1 = focus2.

12

u/80386 May 06 '15

That's what an ellipse is, not an oval.

5

u/[deleted] May 06 '15

Are ellipse and oval not synonyms, like rectangular and oblong? What's the difference?

9

u/[deleted] May 06 '15

An ellipse is specifically a figure with two foci such that the sum of the distance to the two foci for every point on the perimeter is equal. An oval is not a well-defined geometric shape, it's basically 'anything that looks like an oval.'

0

u/80386 May 06 '15

An oval is usually two 180° curves with straight bits in between.

4

u/detroitmatt May 06 '15

No that's a capsule, an oval is an ellipse where the radius of one focus is larger than the other (fat on one end).

1

u/[deleted] May 12 '15

So an egg?

8

u/ChemicalRocketeer May 06 '15

In most graphical apis I've used, you draw an oval by supplying a width and height, not focus1 and focus2.

12

u/DPErny May 06 '15

I know you're not really asking, but if you were interested or someone else was curious, the less shitty way to do this would be to abstract common functionality of the rectangle and oval classes into a superclass that they would both inherit from.

Of course, you can also just leave it like this just as well, it really doesn't matter a whole lot.

2

u/djcraze May 06 '15

I believe you may be confusing a Rect and a Shape. A Shape has a Rect, and the Rect has a Point and Size. The point being X/Y and the Size being Width/Height. That's just my opinion.

0

u/[deleted] May 06 '15

[removed] — view removed comment

4

u/Chondriac May 07 '15

int SHENANIGANS;

139

u/adamnemecek May 05 '15

this actually isn't the worst thing ever if you consider that an oval is just a rectangle with corner radius set to max.

80

u/tian447 May 05 '15

I see the programmer has appeared.

63

u/adamnemecek May 05 '15

dude, i've been dealing with this shit since kindergarten http://i.imgur.com/1liCNx1.jpg

4

u/B-Rabbit May 06 '15

Don't know why, but this picture made me laugh.

0

u/[deleted] May 06 '15

[deleted]

20

u/gnarbucketz May 06 '15 edited Jun 08 '15

...like putting Windows 8 pegs in Windows 7 holes.

(I'm still working on this joke)

Edit: I am no longer working on this joke.

1

u/Tarmen May 06 '15

I mean, you also could change the norm and say both are the same shape, I guess?

0

u/[deleted] May 06 '15

[deleted]

1

u/adamnemecek May 06 '15

if you are talking about css, then maybe (i'm not actually sure) but it is in the 'general' case.

0

u/[deleted] May 06 '15

[deleted]

1

u/adamnemecek May 06 '15

i never said it was an ellipse, i said oval

6

u/pkillian May 06 '15

Ignoring the fact that an oval shouldn't inherit from a rectangle, at least keep defined strings in PR1Shape as a sort of registry of possible shapes.

5

u/Kristler May 06 '15

That translucency made me think hoverzoom had suddenly gained an opacity slider.

4

u/cefarix May 06 '15

The infinite sided rectangle.

6

u/Rescommunes May 06 '15

What's a PR10 val?

10

u/novelty_string May 06 '15

PR10 sites are worth quite a bit actually, I'd guess somewhere between 8 cents and eleventy billion doubloons.

2

u/hearwa May 06 '15

I hope the programmer at least felt a little dirty when writing that class definition.