Scalawag

- friends
1,931 link karma
12,587 comment karma
send messageredditor for
what's this?

TROPHY CASE

reddit is a source for what's new and popular online. vote on links that you like or dislike and help decide what's popular, or submit your own!

My sister made this. I thought r/webcomics would like it! :) by Squidein webcomics

[–]Scalawag 4 points5 points ago

Nice catch.

My sister made this. I thought r/webcomics would like it! :) by Squidein webcomics

[–]Scalawag 7 points8 points ago

It's called cross-posting. I'm glad he did. relevent

Dad puts child in tumble dryer as prank; the obvious happens. [safe for work despite liveleak] by vidyagamesin offbeat

[–]Scalawag 7 points8 points ago

And that's why you always leave a note.

Brain implant allows paralysed woman to control a robot with her thoughts by JCronin1234in cogsci

[–]Scalawag -1 points0 points ago

The same numbers seem to pop up frequently... very suspicious.

Procedural Programmer [me] Needs Help Making The OO Transition. by My-Work-Redditin learnprogramming

[–]Scalawag 3 points4 points ago

I never decoupled these two ideas. It makes a lot of sense to do so, though. Perhaps I'll be able to put this to practice at work. Thanks.

Procedural Programmer [me] Needs Help Making The OO Transition. by My-Work-Redditin learnprogramming

[–]Scalawag 3 points4 points ago

I've compiled a working example of all of this here. Go ahead and play with the classes. Feel free to reply to this or message me with any further questions.

I had a similar problem. I had been coding procedurally for about a decade and then had to learn Java. I found that it was the concept of OOP that gave me the trouble. Once I conceived of it, it all made sense. Since you said you're trying to learn Java, let me try to explain OOP with Java examples.

OOP programmers tend to slowly become obsessed with the classification (or "class") of things. There's a term "ISA" that becomes fairly important. It's the conjunction of the phrase "is a". To say "A ISA B" is to say that A is a special kind of B. For example, a poodle ISA dog. A dog ISA mammal. A mammal ISA animal. You can alos jump levels and say a poodle ISA animal. The idea behind OOP is that everything ISA object.

If I wanted to make this system in Java, I would write:

class Animal { //there is an implicit "extends Object" after "Animal"
    //class definition
}
class Mammal extends Animal {
    //class definition
}
class Dog extends Mammal {
    //class definition
}
class Poodle extends Dog {
    //class definition
}

If I also needed a Human in my program, I would also create:

class Human extends Mammal {
    //class definition
}

The other term is HASA (which is the conjunction of the phrase "has a"). A poodle HASA hair color (because Mammals have hair). It also HASA lifespan (because all Animals HASA lifespan). To represent this information, I would write:

class Animal { //there is an implicit "extends Object" after "Animal"
    float lifespan; //in years
}
class Mammal extends Animal {
    Color hairColor; //Java provides the Color class
}
class Dog extends Mammal {
    //class definition
}
class Poodle extends Dog {
    //class definition
}

Now, as for functions (or "methods", as they're called in Java), there are also things that each level of the classifications system can do. For instance, a Dog can bark, but an Animal can't necessarily bark (unless it ISA Dog). However, all Animals eat. Let's say we also have defined (somewhere else) something called "Food" (that way, we have something we can pass to the eat method, to specify what the Animal is eating). If we add these functions, we get:

class Animal { //there is an implicit "extends Object" after "Animal"
    float lifespan; //in years

    void eat(Food theFoodItem){
        System.out.println("Mmmm... I love eating "+theFoodItem.productName);
    }
}
class Mammal extends Animal {
    Color hairColor; //Java provides the Color class
}
class Dog extends Mammal {
    void bark(){
        System.out.println("woof.");
    }
}
class Poodle extends Dog {
    //class definition
}

If we had the above code (and we had "Food" defined somewhere), we could write the following:

Poodle fido = new Poodle();
fido.bark(); //outputs "woof"
Food fish = new Food("fish");
fido.eat(fish); //outputs "Mmmm... I love eating fish"

Now, fido can only bark() because it ISA Dog. You could also write "Animal fido = new Poodle()" (and why not? I mean, fido represents an Animal and a Poodle ISA Animal, right?). However, if you store fido into an Animal variable, you won't be able to get him to bark() (because Animals can't bark). You could, however, still get him to eat, because Animals eat.

Let's say you had a different type of dog, a Pitbull, like so:

class Pitbull extends Dog {
    //class definition
}

You can replace "Poodle" with "Pitbull" in the above code and it would behave in the same exact manner, because a Pitbull can do everything a Poodle can do. But let's say that a Pitbull had a distinct bark, different from most Dogs. Let's say that rather than a Pitbull going "woof", it went "bazinga". You could specify this in the following manner:

class Animal { //there is an implicit "extends Object" after "Animal"
    float lifespan; //in years

    void eat(Food theFoodItem){
        System.out.println("Mmmm... I love eating "+theFoodItem.productName);
    }
}
class Mammal extends Animal {
    Color hairColor; //Java provides the Color class
}
class Dog extends Mammal {
    void bark(){
        System.out.println("woof.");
    }
}
class Poodle extends Dog {
    //class definition
}
class Pitbull extends Dog {
            void bark(){
        System.out.println("bazinga.");
    }
}

After defining those classes, you can run the following code:

Poodle fido = new Poodle();
fido.bark(); //outputs "woof"
Food fish = new Food("fish");
fido.eat(fish); //outputs "Mmmm... I love eating fish"

And you would get the output:

woof
Mmmm... I love eating fish

However, if you replace "Poodle fido = new Poodle();" with "Pitbull fido = new Pitbull();", like so:

Pitbull fido = new Pitbull();
fido.bark(); //outputs "bazinga"
Food fish = new Food("fish");
fido.eat(fish); //outputs "Mmmm... I love eating fish"

You would get the output

bazinga
Mmmm... I love eating fish.

Now, if you change that line to "Dog fido = new Pitbull();", it would still output "bazinga" when you call "fido.bark();" because that's what Pitbulls do when they bark. It's a Dog, so Java knows it can bark. The Pitbull object knows how to bark. If you had written "Animal fido = new Pitbull();" and then tried to do a "fido.bark();", it wouldn't even compile. Java would say "Animals can't bark".

Procedural Programmer [me] Needs Help Making The OO Transition. by My-Work-Redditin learnprogramming

[–]Scalawag 4 points5 points ago

I would say that polymorphism is extremely important to OOP. To say "32 pieces" is fine, but this implies that each of the 32 pieces is the same thing. To a degree, that's true, but that's like saying a Poodle and a Lab are the same thing because they're both Dogs. I also don't think that abstract classes are an implementation detail because there is no such thing as a "Chess Piece". "Chess Piece" is an abstract idea which is a category of the possible chess pieces (that is to say, there's no concrete "chess piece"). All chess pieces have similar qualities, but they all move in different ways. I'd say this would be a great way for OP to be introduced to polymorphism.

Well, it's been a month and a half, and I was asked to see the finished t-shirt. Behold, ALL the TMNT by Quixlein secretsanta

[–]Scalawag 2 points3 points ago

Yea, I was more recommending that he sell it on "a cafe press" than cafe press specifically. Their products are pretty shoddy.

Well, it's been a month and a half, and I was asked to see the finished t-shirt. Behold, ALL the TMNT by Quixlein secretsanta

[–]Scalawag 0 points1 point ago

Put this up on cafe press for an easy $100 (at least). Based on the interest in this thread alone, you'd get a decent amount of sales. And cafe press simply requires that you upload the image. I do believe that it will become their property upon upload, though, so there's that to keep in mind. Perhaps a different, similar alternative would work out better for you.

Are there ANY at home jobs you can do that are not a scam and yield some kind of return? by Gilmoredditin SelfSufficiency

[–]Scalawag 0 points1 point ago

Agreed. But isn't that the mark of an addictive game?

Mux Mool - "Ballad of Gloria Featherbottom" by morphotomyin futurebeats

[–]Scalawag 0 points1 point ago

I present to you, Mrs. Featherbottom

Women of sexxit, what's the smoothest way someone's initiated sex with you? by 373711in sex

[–]Scalawag 34 points35 points ago

Oh, rocket science. That must be hard. I mean, it's not exactly brain surgery. And I would know... I'm a brain surgeon.

Time slows down near large mass and at high speeds. Is it possible that the first "seconds" of the Big Bang lasted billions of years because of this? by niklaskronwalledin askscience

[–]Scalawag 3 points4 points ago

Here ya go. It's not only possible, evidence suggests that's where we're headed. It won't hit absolute zero, of course, it will approach it asymptotically.

Saw this today and instantly thought this. I am a bad person. by HyperactiveToastin mw3

[–]Scalawag 1 point2 points ago

I'm still playing Black Ops. Whenever I'm going for ghost pro, I have to spend a couple games shooting down every spy plane that I can find. During those days, I don't even have to see a plane for this to happen. When I go outside, I start looking for them.

Overdrawn Bank Account by TurtleCavein WTF

[–]Scalawag -3 points-2 points ago

The 81 cents was probably just the tax.

How it feels working in the keyboard section at my local music store. by DefconTigerin WeAreTheMusicMakers

[–]Scalawag 1 point2 points ago

The odd thing is, I don't think that's a hyperbole.

Well shit by sai_sai33in fffffffuuuuuuuuuuuu

[–]Scalawag 1 point2 points ago

I could see it happening with earbuds but not with an over-the-ear set. With earbuds, everything in the world is just a little muted. I think I've actually made this mistake before, but it was with music so it was no big deal.

A fellow Redditor on Omegle by lolFlyin omegle

[–]Scalawag 0 points1 point ago

Charlie Sheen on Cocaine by _repost_in AdviceAnimals

[–]Scalawag 0 points1 point ago

...isn't it? I mean, perhaps I wouldn't say "just applied physics" but I'd say chemistry is applied physics.

Awesome animation showing how a curve in the Cartesian plane can be mapped into polar coordinates: y=sin(6x)+2 is mapped to r=sin(6theta)+2. by spikedmathin math

[–]Scalawag -2 points-1 points ago*

I have an honest idea for you. If you made an animation just like this one using the Cannibis Curve, it would spread like crazy. Perhaps set it up such that the stem comes together on the -y axis.

edit: Also, could you describe the method by which you created this animation? I've always had an interest in creating animations of a similar sort.

view more: next