Rambam’s Yehareg V’Al Ya’avor In Pseudocode

Last night in my weekly Rambam havruta, we started chapter 5 of Yesodei Hatorah. Rambam begins the chapter by discussing the obligation to sanctify God’s name (kiddush hashem) and its corollary prohibition against desecrating God’s name (hillul hashem). In providing examples, Rambam segues into the laws of yehareg v’al ya’avor – the conditions under which someone should allow himself to be killed rather than violate a commandment under duress.

But while the laws in Rambam are usually straightforward, the laws of yehareg v’al ya’avor have several qualifiers and criteria to evaluate, to the point that it became difficult to keep track of all of them in proper sequence. Being the computer geek that I am, I figured that pseudocode could come in handy. The following snippet assumes the functions do(); which entails preforming the sin in question and die(); means to allow oneself to be killed. It’s not necessarily the most efficient code mind you, but I’m going for maintainability.1

big3[] = {murder, idolatry, illicitSexualRelations};
if (governmentDecree == true){
else {
    if (big3[].contains(sin)){
        if (nonJewBenefits == true){
        else if (numJews < 10){             do();         }         else {             die();         }     } }

There, that should make everything perfectly clear.
Update: Seth Berger contributes the following optimized code:

if( (!governmentDecree || !big3[].contains(sin)) && ( nonJewBenefits || numJews < 10)) {     do(); } else {die();}

Update 2: Reuven Weiser corrects Seth's optimization since in Seth's code a non-big 3 sin could still result in do(); if a non Jew benefits. This is incorrect and should rather be:
if( (!governmentDecree && !big3[].contains(sin)) && ( nonJewBenefits || numJews < 10)) {     do(); } else {die();}
This sort of confusion often comes up with too much negative logic. We can flip things around to create a slightly more readable optimization:

if ( (governmentDecree || big3[].contains(sin)) || (!nonJewBenefits && numJews >10)){
else {do();}

1. For Brisker’s, of course

Send this to a friend