Article
PR #1: Is Eating Animals Cruel?
Bump on this PR
I have some code that needs reviewing. Don’t know how to code? No problem, I try and explain every line but let me know if anything jumps out as a mistake!
Cruel and Unusual
// Every Action we take has two properties
type Action = {
isSuffering: boolean; // does it cause suffering?
isNecessary: boolean; // do we need to do it?
};
type Animal = { species: string };
// An Action is cruel if it causes suffering AND isn't necessary
const isCruel = (action: Action): boolean => action.isSuffering && !action.isNecessary;
// Kicking an animal will cause it to suffer
// For simplicity, it's never really necessary unless it's self-defence
const kick = (animal: Animal, isSelfDefence: boolean): Action => ({
isSuffering: true,
isNecessary: isSelfDefence,
});
const dog: Animal = { species: "dog" };
const cat: Animal = { species: "cat" };
// A concrete example of animal cruelty: kicking a dog or a cat for no reason.
const animalCruelty: Action = kick(dog, false) || kick(cat, false);
console.log("Is animal cruelty cruel? " + isCruel(animalCruelty));
We have an Action type that has two properties: isSuffering and isNecessary.
The isCruel function checks if an action causes suffering and isn’t necessary, returning true if both conditions are met.
So in this block I’m just checking the isCruel function works with something obvious. Let’s randomly pick animal cruelty for absolutely no reason in particular. We define it real quick and then make the check. No surprises that animal cruelty is cruel in case you were wondering! Off to a good start!
ME!
type Person = {
values: {
against: Action[];
pro: Action[];
};
diet: "vegan" | "omnivore" | null;
};
const me: Person = {
values: {
against: [animalCruelty, slavery, scalping, ...],
pro: [worldPeace, allBasicNeedsMet, fourDayWorkWeek, ...],
},
diet: null
};
Here’s me as an object with my values and diet. Within values, I have what I’m against and what I’m pro.
I’m against animal cruelty! That goes in my against list within values.
My diet will start off as null, and we’ll use the function determineDietFromValues to figure it out based on my values.
Debugging values (i.e. console logging)
type Industry = { isSuffering: boolean };
// Funding an industry takes on whatever suffering it causes
const fund = (industry: Industry): boolean => industry.isSuffering;
// Factory farming directly causes suffering for animals
const factoryFarming: Industry = { isSuffering: true };
// Buying animal products funds factory farming,
// and these days we know we don't need to eat animals to survive
const eatingAnimals: Action = {
isSuffering: fund(factoryFarming),
isNecessary: false,
};
// Does factory farming cause suffering for the animals?
console.log("Factory farming causes suffering? "
+ factoryFarming.isSuffering); // true
// So does eating animals?
console.log("Eating animals causes suffering? "
+ eatingAnimals.isSuffering); // true
// Is eating animals necessary for survival?
console.log("Eating animals is necessary? "
+ eatingAnimals.isNecessary); // false
// isCruel checks isSuffering is true and isNecessary is false
// eatingAnimals.isSuffering === true
// eatingAnimals.isNecessary === false
// Therefore, isCruel(eatingAnimals) === true
console.log("Eating animals is cruel? "
+ isCruel(eatingAnimals)); // true
A bit of a long block but we start off with a fund function which will return the isSuffering property from that industry.
We have our factoryFarming industry defined which we know undeniably causes suffering for animals, and so isSuffering is true for it.
Now we define eatingAnimals as an action. We know that it is not necessary to eat animals to survive or thrive and therefore isNecessary is false.
Then we can determine its isSuffering value by using the fund function on factoryFarming which will return true since factoryFarming.isSuffering is true.
Then we check whether eatingAnimals is cruel by using the isCruel function, which combines the suffering and necessity checks.
Output
const determineDietFromValues = (person: Person): void => {
const against = person.values.against;
if (against.includes(animalCruelty) && isCruel(eatingAnimals)) {
person.diet = "vegan";
} else {
person.diet = "omnivore";
}
};
To determine our output, we have a function determineDietFromValues that takes a person object and determines their diet based on their values.
If the person is against animal cruelty, and eating animals is cruel, then the function will set their diet to "vegan". Otherwise, it will set their diet to "omnivore".
Run it
Let’s run myself through the diet determination function and see what diet I get based on my values.
type Action = {isSuffering: boolean;isNecessary: boolean;}; type Animal = { species: string }; type Industry = { isSuffering: boolean }; type Person = {values: { against: Action[]; pro: Action[] };diet: "vegan" | "omnivore" | null;}; // cruel = causes suffering AND isn't necessaryconst isCruel = (action: Action): boolean => action.isSuffering && !action.isNecessary; const kick = (animal: Animal, isSelfDefence: boolean): Action => ({isSuffering: true,isNecessary: isSelfDefence,}); const dog: Animal = { species: "dog" };const cat: Animal = { species: "cat" };const animalCruelty: Action = kick(dog, false) || kick(cat, false); console.log("Is animal cruelty cruel? " + isCruel(animalCruelty)); const me: Person = {values: {against: [animalCruelty, slavery, scalping, ...],pro: [worldPeace, allBasicNeedsMet, fourDayWorkWeek, ...],},diet: null,}; console.log("Current diet: " + me.diet); const fund = (industry: Industry): boolean => industry.isSuffering; const factoryFarming: Industry = { isSuffering: true };const eatingAnimals: Action = {isSuffering: fund(factoryFarming),isNecessary: false,}; console.log("Factory farming causes suffering? " + factoryFarming.isSuffering);console.log("Eating animals causes suffering? " + eatingAnimals.isSuffering);console.log("Eating animals is necessary? " + eatingAnimals.isNecessary);console.log("Eating animals is cruel? " + isCruel(eatingAnimals)); const determineDietFromValues = (person: Person): void => {const against = person.values.against;if (against.includes(animalCruelty) && isCruel(eatingAnimals)) {person.diet = "vegan";} else {person.diet = "omnivore";}}; determineDietFromValues(me); console.log("You're a " + me.diet + ", Harry");- Is animal cruelty cruel?
- Current diet:
- Factory farming causes suffering?
- Eating animals causes suffering?
- Eating animals is necessary?
- Eating animals is cruel?
- You're a , Harry
After running the code, we can see that based on my values, I gots to be a vegan!
Can you please see if there is a bug in my code? I would really love the result to be omnivore!