« first day (1496 days earlier)      last day (3446 days later) » 

4:00 PM
Squares are defined as a rectangle with the same width and height, so while enforcing it in the setters isn't pretty, it is mostly correct.
 
@ssube That's the entire point I'm trying to make "extends" does not simply mean "is a"
 
@SterlingArcher You were right.
 
@Retsam Well it should
 
@Sippy about what?
 
@MetroidFan2002 that was not what I was saying .. my point was that both versions are retarded
 
4:00 PM
@Retsam But a Square is a Rectangle. that's what extends does in any well-designed system of inheritance.
 
This shit. :D
 
IF that's not the case, you've screwed up and need to refactor.
 
A square has all the properties of a rectangle, and a rectangle does not have all the properties of a square
 
@tereško I agree
 
4:01 PM
@ssube If you approach from the Mathematical definition, yes. But if you approach from a comp-sci first definition, a rectangle is a square.
 
@Retsam No, not in any system. A Square is always a Rectangle.
 
@tereško But if we're going to make arbitrary subclasses to model the real world, we should do it right.
 
A rectangle has all the properties of a square ("width") but a square does not have all the properties of a rectangle ("width and height")
 
A square is a rectangle with additional restrictions.
 
@Retsam of course a square has width and height
 
4:01 PM
!!define rectangle
 
@Sippy rectangle (geometry) A quadrilateral having opposing sides parallel and four right angles.
 
@Retsam A square does have width and height
 
@ssube A rectangle is a square with extra data.
 
!!define square
 
@Sippy square (geometry) A polygon with four sides of equal length and four angles of 90 degrees; a regular quadrilateral whose angles are all 90 degrees.
 
4:02 PM
@Retsam They're just the same.
 
@Retsam You have your inheritance backwards.
 
Oh great, argumentum ad dictionarium. Good job.
 
@Retsam That's like saying an animal is a cat with extra data
 
@KendallFrey What extra data does an animal have that a cat doesn't?
 
@ssube That's what my psuedoclasses were trying to illustrate
 
4:02 PM
Inheritance starts least specific and goes toward most.
 
@Retsam Google's definition was what I was going for ..
 
@Retsam Perhaps, number_of_tentacles
 
a plane figure with four straight sides and four right angles, especially one with unequal adjacent sides, in contrast to a square.
 
@KendallFrey would polydactile cats be considered "extra data" because extra toes?
 
@Sippy I don't give a damn what Google defines square and rectangles as.
 
4:03 PM
Shape (has some sides) -> Rectangle (4 sides with 90 degree angles) -> Square (4 sides of equal length with 90 degree angles)
 
@KendallFrey Not a necessary property of an animal. Width and height are necessary properties of a rectangle.
 
@Retsam Nobody gives a damn what you define them as
@Retsam and also of a square
 
@ssube I just learned that last night, order of derivation!
 
@SterlingArcher Square and rectangle is the classic example.
 
@KendallFrey Not from a data first approach. It doesn't require two properties to define a square.
 
4:04 PM
@SterlingArcher sorry, on shitty internet
 
Same way you might have a Reader and a FileReader and NetworkReader, where the latter two have additional restrictions.
 
@Retsam Do you have any idea what polymorphism is?
 
@BenjaminGruenbaum no worries :) I pinged you because you know lots and I have to start using Java at work
 
@KendallFrey Yes, I know what polymorphism is.
 
Reader is the base interface, saying this can read something. The implementations can read a particular thing, and so fulfill the contract with additional restrictions.
 
4:05 PM
@Retsam Do you understand why you are breaking it?
 
@KendallFrey Pretend I don't.
 
ok, I'll explain
 
I guess in @Retsam data driven model there would be two classes and a shared interface between them, since it would be split up. A more generic shape interface with getters for width and height, and Square and Rectangle would be shapes but a Square would not be a Rectangle?
 
user1596138
@Sippy SUP DOGEE
 
maybe something like RectangularShape
 
4:06 PM
@MetroidFan2002 this is why "in OOP the objects represents the real world thins" is incorrect statement
 
@someDoge WAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 
user1596138
whatzup
 
@tereško I don't think I made that statement....
 
stackoverflow.com/questions/27044023/… Isn't that parsing html with regex? ._.
 
Weekend away with the missus and it's shark week fucking gg
If I meet mother nature in the afterlife I'ma break that bitch nose
 
4:08 PM
For everyone arguing for "Square is a rectangle that enforces width == height":
    public testArea(Rectangle rectangle) {
        rectangle.setWidth(100);
        rectangle.setHeight(50);
        expect(rectangle.getArea() == 100 * 50)
    }
 
@retsam Ah, but in my model you don't have setters.
 
function fillSquare(square, context)
{
    context.fillRect(square.x, square.y, square.width, square.width);
}
That's some canvas pseudocode
 
@MetroidFan2002 Okay, replace the "setter" with "rectangle.width = 100"; unless you're arguing for immutable which works but has its own problems.
 
clearly broken if you pass in a rectangle
 
@Retsam Yes, I'm arguing for immutable.
 
4:10 PM
@Retsam Immutability is a nice concept
 
@Retsam In my example, Rectangle had a constructor for setting the values. Square provided a constructor that allowed setting just the width (or height if you prefer) through the superclass constructor.
 
@Retsam What problems?
 
@KendallFrey Not problems, per se, but tradeoffs.
Immutability is a pain... well if you want to mutate your shapes regularly. (Yes, you can do it; but it's a lot of object construction)
 
Yeah, but with immutability I don't have to bother with overriding setters to enforce setting both fields at the same time.
 
@Retsam When you think about it, that test is really fucked up
 
4:13 PM
@KendallFrey Oh?
It's not reasonable to expect a rectangles area to be the product of its width and height?
 
passing in a rectangle, only to discard its values and rewrite them?
You should be creating a test rectangle
 
@KendallFrey You wouldn't have to pass it in; I did that for the convenience of not having to construct it and to save a line that I pasted into chat.
 
wow. meta-pendants.
 
@Retsam You didn't save a line, you lost one
 
public testArea() {
    Rectangle rectangle = new Rectangle(10, 10);
    rectangle.setWidth(100);
    rectangle.setHeight(50);
    expect(rectangle.getArea() == 100 * 50)
}
Better?
 
4:15 PM
hell no
 
@KendallFrey Okay, well I think I'm done with this conversation and am going to get back to work.
 
public testArea() {
    Rectangle rectangle = new Rectangle(100, 50);
    expect(rectangle.getArea() == 100 * 50)
}
 
@Retsam Though logically that might make sense, that is very hard to understand
 
making your point moot
 
I was trying to have a simple discussion, and I've mostly just been talked down to about how obviously I don't understand OOP.
 
4:15 PM
posted on November 20, 2014

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); try { var pageTracker = _gat._getTracker("UA-3727700-1"); pageTracker._trackPageview(); } catch(err) {} Whee!

 
@KendallFrey Suppose I actually wanted to test the setters?
 
That doesn't belong in the same test as the test for area
 
@Retsam I don't think I've done that. But I think your arbitrary classes that you posted earlier are inverted.
 
@KendallFrey You can't test that the area is still calculated correctly after the width and height changes?
 
@Retsam Phrased that way, it is another valid test (not replacing the previous ones)
 
4:17 PM
What if getArea() was just returning a static value computed on construction?
 
TEST ALL THE THINGS
@Retsam of course, that should be tested too
 
@KendallFrey 100% branch coverage or die trying
 
My point isn't about test coverage; but that doing a square that enforces width==height violates the contract established by Rectangle, that width and height can be set independently.
It's a violation of the Liskov-Substitution Principle: the subclass isn't always substitutable for the superclass.
 
@Retsam Rectangle doesn't specify one way or the other.
 
That's why changing width or height should be illegal
 
4:20 PM
@Retsam I see what you mean, though that isn't a contract
 
@Retsam Well the other way around certainly isn't any better
 
Since it's all about pendantry, I'd argue that it would be an issue if you made the superclass MutableRectangle
 
@KendallFrey The other way is pretty clearly wrong.
 
then MutableSquare would have all sorts of issues.
 
@KendallFrey Example?
 
4:21 PM
As usual, immutability solves most of it but isn't practical performance-wise.
 
If you made a base class Square that hid setHeight and only used setWidth, it doesn't violate Rectangle anymore than a Queue based on a List is violating List
 
12 mins ago, by Kendall Frey
function fillSquare(square, context)
{
    context.fillRect(square.x, square.y, square.width, square.width);
}
 
@ssube Immutability can be a huge performance boost if used properly
 
@ssube In languages like C# that have value types, immutability isn't really a problem
 
@KendallFrey If you pass a rectangle into a class expecting a square, that's pretty much exactly what I'd expect to happen.
 
4:23 PM
@Neil Which can be really tricky, and if you screw it up at all (and thrash small object creation), you're screwed.
 
@ssube I agree, you have to know what you're dealing with
 
Clearly, the solution is to never create objects - ever.
 
@Neil Like threads and locks, you have to do it just right for it to be good (and if you do, it's great).
@MetroidFan2002 Correct. new is evil.
 
Sometimes immutable objects do have to have an internal state that changes, though it must be entirely transparent to those who use the object
 
@Retsam So, you'd expect your recommended approach to be really fucked up?
 
4:24 PM
As is malloc and factories and anything else that allocates memory. Writes should be avoided as well.
 
@KendallFrey No, I expect that you have to actually define a method that fills a rectangle if you want to be able to fill a rectangle.
 
Polymorphism is really useful
If you don't care about polymorphism, just abandon the whole idea of extending types
 
s/Polymorphism/Inheritance/
 
@KendallFrey It's not that I don't care about polymorphism. Yes, you've raised one point where things would be slightly more convenient for Squares to extend Rectangles.
 
Abstracts :3
 
4:27 PM
My real point is that there are tradeoffs to every way you can go about it.
 
@SterlingArcher It's not super common to actually need abstract classes irl. They're mostly for when you want to provide a partial implementation.
 
Oh? I kind of liked the concept of making a superclass where subclasses need to specify a specific method
 
There are advantages to Rectangle extends Square, too, like not violating the LSP. There are advantages to immutablilty, there are advantages to mutability...
 
@Retsam Treating Squares like Rectangles would be a little more than "slightly convenient"
 
@Retsam So far the only problem with my approach is that immutability is slow for object-based languages like JS. Yours involves breaking polymmorphism.
 
4:28 PM
@SterlingArcher The problem with abstract classes is that they lock you into a hierarchy if they don't also implement an interface
 
Like a Shape class defining area(), but since lots of shapes have different formulas, specific shape classes like Triangle or Circle would need to define area explicitly
 
@SterlingArcher The Number class in Java is an abomination.
 
@SterlingArcher They have a use, but more often than not you'll have all-or-nothing implementations.
 
@SterlingArcher Every formula valid for a rectangle is valid also for a square
 
@SterlingArcher It violates the en.wikipedia.org/wiki/Liskov_substitution_principle in that you can't really use Number as is
 
4:29 PM
@KendallFrey I'm not breaking Polymorphism.
 
Can't be said for everything of course, but the Square extending Rectangle is almost a perfect example of polymorphism that you see it as the de facto example
 
@SterlingArcher For example, if you have a BigDecimal, you're going to have to do BigDecimal specific operations on it to do anything productive.
 
@Retsam Then explain how my code is supposed to work with your approach
 
This is so overwhelming
I hope implementing these concepts isn't as confusing as it sounds
 
@SterlingArcher :hug:
 
4:30 PM
@KendallFrey Your code isn't valid polymorphism if Rectangles extend Squares. You're writing code for the subclass (Square), and then trying to pass the superclass (Rectangle) into it. That's backwards of how it's supposed to work
 
@SterlingArcher It's not. You'll be like wtf for a little while, then see a good example, and it'll be obvious.
 
@SterlingArcher Now, if Number was an interface, and it had the same contract, it'd be ok
@SterlingArcher But the problem is, when you use BigDecimal, you want the exact number.
 
I think I need to actually start a Java project. Reading about it is fine, but I need to see it in action
 
@SterlingArcher No rounding!
 
@Retsam There is no reason for Rectangle to ever extend Square. Rectangles are not Squares.
 
4:31 PM
@MetroidFan2002 ohhhh ._.
 
@ssube Just keep repeating that. It's getting more convincing every time you say it.
 
@Retsam My code isn't valid polymorphism if Rectangles extend Squares, which is exactly the approach you're recommending. Your approach invalidates perfectly reasonable code
 
@SterlingArcher Write a cli tool or something. Don't start with a REST API, then you have to get into all sorts of container stuff and it's bad.
 
@KendallFrey that helps :)
 
@KendallFrey It's only perfectly reasonable code if you assume Squares extends Rectangles.
 
4:32 PM
@SterlingArcher :surprise buttsecks:
 
@ssube well, I think my boss is going to have my first project be a URL shortener
@KendallFrey D: my booty
 
@Retsam Rectangle allows (but does not require) the sides to be different lengths. Square requires them to be the same. Thus Rectangle violates the contract Square establishes, but Square does not violate any property of Rectangle.
 
@Retsam No, it's reasonable in any case that a Square is a square
 
Now I see what my wife means when she says all us programmers are a bit "abstract", yet here we are, discussing about how to implement a Square..
 
Based on that, Square extends Rectangle but not vice versa, at all.
 
4:33 PM
brb afk
 
@KendallFrey I'm confused now.. I thought that you thought that a Square was supposed to extend Rectangle
 
@Neil It is
 
@KendallFrey The code is reasonable, but is passing a rectangle into that code and expecting it to work reasonable?
 
@KendallFrey That's what he just claimed
 
@Retsam No, that's why your approach breaks polymorphism
@Neil Whoops, no, read that backwards
 
4:35 PM
4 mins ago, by Retsam
@KendallFrey Your code isn't valid polymorphism if Rectangles extend Squares. You're writing code for the subclass (Square), and then trying to pass the superclass (Rectangle) into it. That's backwards of how it's supposed to work
 
I thought the definition of a Square was a 4 sided shape with all sides equal?
 
@Neil Wait, yes. Square is supposed to extend Rectangle
 
I'm not breaking polymorphism by not allowing the superclass to be passed into logic written for the subclass. That's not how polymorphism works.
 
@SterlingArcher No, that's a rhombus
 
Not.. helping.. confusion
 
4:35 PM
wat
 
@SterlingArcher and all 90-degree angles.
 
^ yes that too
 
Where as a rectangle does not have the "all sides equal" constraint.
A Square is a rectangle with an additional constraint.
 
Rectangles still require 90d angles but parallel sides must be equal, right?
 
Rectangle is a quadrilateral with all 90 degree angles, a quad is a shape with 4 sides, etc...
 
4:36 PM
@ssube Code generally works by adding data, not constraints. Just saying.
 
@Retsam I'm not saying that rectangles should or can be passed in
 
@SterlingArcher That ends up by synonymous with 90 degree angles.
 
There's also parallelogram, rhombus, quadrilateral
 
I'm saying that your approach means they could be
 
I didn't do well in geometry
Or math in general
 
4:37 PM
@KendallFrey Then what's the problem with that code if Rectangles extend Squares?
 
@Retsam Not necessarily true. Subclasses are more specific in some fashion, while meeting a larger contract. Nobody ever said they have to have more data.
 
@Retsam Because then Rectangle is a valid argument for the function, and shit flies everywhere
 
They often do to support that specificity, but there's no reason they have to.
 
@KendallFrey So you are passing a Rectangle into a code that expects a square?
 
No, you are
 
4:38 PM
Totally confused right now
 
@KendallFrey No your mom is.
 
Not even high
 
My mom isn't a programmer, I'm not suprised she's confused
 
But, I wouldn't becasue it's not valid polymorphism to pass a superclass into a method expecting a subclass.
 
lol too much sorry
 
4:39 PM
@Retsam So, you're saying that Rectangle is the superclass?
@SterlingArcher You can never have too much sorry, eh
 
EH!
HOCK-EH!
 
Sorry, eh
 
Man, no way, dude, eh?
 
canada just invaded us eh?
 
4:41 PM
Or it could be Australia, eh, mate?
 
@FlorianMargaine you betcha, friend
 
sorry, eh
 
@KendallFrey No, I guess I'm saying that backwards.
 
You have been saying things backwards all along :P
 
Square is the superclass?
 
4:42 PM
I bloody hope not
 
Square is the superclass of Object, which should extend Shape.
After all, if you're doing good OO, classes represent objects.
and every real life object has a shape.
 
I AM THE SUPERCLASS GOD OBJECT
BOW!
 
I am hungry
 
damn, me too now
I'll just smoke
 
reductio ad absurdum wins the day!
 
4:44 PM
@FlorianMargaine CANCER EVERYWHERE
 
still better than fat everywhere
 
Shape is the base class of Fat, which is cousins with Pretzel and Banana
 
I hope no one here died of cancer, that was a bit insensitive.
@Neil Fat kid meets Banana, and boom, retarded kids?
2
 
I can't find my cat :(
 
@KendallFrey The internet: the only place where there might actually be dead people around and you can't tell.
Well, not only, I guess. City council meetings count.
 
4:49 PM
@KendallFrey Fat kid + Banana base classes get you Square
 
@KendallFrey Should Fat be a trait you can compose with Kid or Banana, so you can FatBananaKid implements Kid, Banana, Fat?
 
class Woman extends Object {
}
 
Java is inherently sexist?
 
not necessarily...
class Man extends Object {}
works too...
 
Only if you consider man a primitive value
 
4:55 PM
So Java is just an uncaring, unforgiving asshole?
3
cause I'd totally believe that
 
public Woman(Man man) {
    man.ribs--;
}
3
 
poor ribs
 
@Retsam return type pls
 
@Retsam You've just removed a rib from man :(
 
4:58 PM
@FlorianMargaine It's a constructor
 
@FlorianMargaine It was a constructor
 
ah, my bad
 
> As his trainer takes him off the field, like a mustache lion dragging a gazelle
 
@Neil No, post outside of assignment makes it a noop, more or less.
 
4:58 PM
@Neil From a single instance of man.
 
Unless man is mutable...
and exposes its fields
 
user1596138
@Retsam lol everyone in our state gets that for sure
 
@Retsam I fail to see how that defines Woman from man
 
user1596138
> Occupation: sexist
 
@ssube Man is, unfortunately mutable
 
user1596138
4:59 PM
Hmm.....
 
@Neil read the Bible
 
user1596138
I think I have been provided false information
 

« first day (1496 days earlier)      last day (3446 days later) »