Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

``Die CIS scum''

Name: Anonymous 2012-10-17 6:06

Amazing programming explanation using examples which respect people of all genders! I think everyone engaged in IT discussion and teaching should follow this style of highly tolerant and privilege-aware writing. ``Transgender'' and ``homosexual'' should become new ``foo'' and ``bar'' in educational code snippets.

---

I'll take a crack at the Factory Method pattern:

The Factory Method pattern uses a single method to construct objects according to some run-time data rather than hardcoding with new. For example, you may have a program which in various places may need to create a MalePerson or FemalePerson object depending on input, so you'd naturally pepper your code with:

if (gender.equalsIgnoreCase("male")) {
      return new MalePerson(name);
} else {
      return new FemalePerson(name);
}


Now what if you need to handle instances of TransgenderPerson or UndeclaredGenderPerson, etc? You'll have to go back and add those conditions to each place that conditional object creation occurs.

So, instead we employ the Factory Method pattern to be able to just call

PersonFactory.makePerson("male");

This encapsulates all creation of objects based on run-time data behind a single interface.

In Java this might be implemented as

public abstract class Person {
    protected final String name;
    public Person(String name) {
      this.name = name;
    }
}

public class MalePerson extends Person {
    public MalePerson(String name) {
      super(name);
    }
}

public class FemalePerson extends Person {
    public FemalePerson(String name) {
      super(name);
    }
}

public class PersonFactory {
    public static Person makePerson(String gender, String name) {
      if (gender.equalsIgnoreCase("male")) {
          return new MalePerson(name);
     } else {
          return new FemalePerson(name);
     }
    }

}


The declaration of the corresponding classes in Common Lisp is pretty straight forward:

(defclass person ()
  ((name :initarg :name :reader name)))

(defclass female-person (person)
  ())

(defclass male-person (person)
  ())


But, in Common Lisp, methods do not belong to classes, but to generic functions which dispatch specific methods based on their arguments. There is even EQL specialization on methods, which allows for methods to be dispatched based on the equality of their arguments to a specified value. So our PersonFactory in Common Lisp would look like:

(defgeneric make-person (gender name))

(defmethod make-person ((gender (eql 'male)) name)
  (make-instance 'male-person :name name))

(defmethod make-person ((gender (eql 'female)) name)
  (make-instance 'female-person :name name))


You'll notice that Common Lisp lacks a new operator. That's because there are no "constructors" in the usual sense of the word. The standard way of creating objects is to pass runtime data either a class object or symbol that is the name of the class object to the factory method MAKE-INSTANCE.

Now, that's all well and good, but let's look at what happens when we want to add the feature to create a TransgenderPerson to our factories. In Java we have to open the PersonFactory.java class file and modify it:

public class PersonFactory {
    public static Person makePerson(String gender, String name) {
      if (gender.equalsIgnoreCase("male")) {
          return new MalePerson(name);
      } else if (gender.equalsIgnoreCase("transgender")) {
          return new TransgenderPerson(name);
      } else {
          return new FemalePerson(name);
      }
    }

}


But in Common Lisp, we do not need to modify anything. We can just extend the MAKE-PERSON generic function with a new method:

(defmethod make-person ((gender (eql 'transgender)) name)
  (make-instance 'transgender-person :name name))

Name: Anonymous 2012-10-18 10:09

>>79
Now you're saying everyone in the world has the same opinions on euthanasia, abortion and gay marriage.

Yes, it's relative and there are tons of factors that may affect it.

Name: Anonymous 2012-10-18 10:09

>>78
You're a pig for not censoring it.

Name: Anonymous 2012-10-18 10:14

>>81
Moral relativism is bullshit == everyone feels the same way about everything? In your world, immoral people and idiots just don't exist?
This is Reddit-level intellectual dishonesty.

Name: Anonymous 2012-10-18 10:17

>>81
Hello straw man. This is why anti-vegetarians are always so over-the-top aggressive: there's no substance to their position, so their only hope is to discourage engagement.

Name: Anonymous 2012-10-18 10:19

>>84
That's the thing that always gets me. They know they're in the wrong, but they're really invested in not admitting it to themselves. It's textbook cognitive dissonance.

Name: Anonymous 2012-10-18 10:22

>>84
eating = killing
Unless you can eat rocks.

Name: Anonymous 2012-10-18 10:27

>>86
Maybe you should spend half a second thinking your argument through before shitting it onto the Internet. Plants don't have a mind.

Name: Anonymous 2012-10-18 10:54

>>83
== everyone feels the same way about controversial topics*

``Immoral people'' are people who don't respect my beliefs. If I were a sandnigger, people who don't pray at the designed time would be immoral and should be put to death.

Name: Anonymous 2012-10-18 11:03

>>84
Not >>81, but you're not going to win an argument just by saying words like strawman, logical fallacy, ad hominem and biases.

Everyone is over-the-top aggressive on the Internet.

I'm a vegetarian, but not for moral reasons. It simply made my bowels happier.

Name: Anonymous 2012-10-18 11:36

>>87
Plants can feel pain as well as various stimuli.  Check your meat privilege!

On a related note, if meat is so expensive to make, are there any cheaper similar-tasting vegetarian substitutes?

Name: Anonymous 2012-10-18 12:15

>>89
Oh, yeah, I get you. Myself I am a militant feminist because it's easier for beta faggots like me to get into women's pants if you can talk at length about the patriarchy and privilege. Nothing wrong with that.

Name: Anonymous 2012-10-18 12:23

>>90
Mapo tofu is delicious, but then it's smothered in spicy pork sauce.

Name: Anonymous 2012-10-18 12:35

I like my polecat kebabs with satay sauce.

Name: Anonymous 2012-10-18 12:47

>>91
militant feminist
So you are supporting female sexism bullshit (as opposed to actual feminism) just to get sex?  Fuck you, faggot.

Name: Anonymous 2012-10-18 13:11

>>94
Back to Reddit, please.

Name: Anonymous 2012-10-18 13:14

>>92
My goal is not to not eat meat at all, but rather to strike a balance between environmental impact, my craving for the taste of meat, and my tiny financial resources.

Name: Anonymous 2012-10-18 13:15

>>95
Fuck off and die, shitstain.

Name: Anonymous 2012-10-19 5:50

>>96
strike a balance between environmental impact, my craving for the taste of meat, and my tiny financial resources.
So, almost-expired chicken meat?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List