Теологическое программирование

топ 100 блогов lex_kravetski06.06.2018 Этот рассказ написан в совершенно новом, неизведанном и оригинальном жанре — повествование в коде.

Уверен, в будущем этот жанр овладеет умами, однако сейчас он может отпугнуть новизной подхода.

Кроме того, в рассказе речь идёт ещё и о всяких там теологических вопросах, поэтому от читателя потребуется не только понимание языков программирования, но ещё и знание нюансов христианских религий.

Вдобавок весь текст на английском языке, хотя и не на очень сложном. Это ещё один фактор, затрудняющий чтение — по крайней мере, для большинства русскоязычной аудитории.

Однако владеющий этими навыками, вдумчивый, внимательный читатель несомненно сумеет проследить весь драматизм, развернувшийся внутри этих, поначалу незамысловатых, строк кода, которые лирический герой снабдил небольшими комментариями.

Вперёд, читатель. Вперёд в неизведанное.


trait Person {
     val isMale: Boolean
}

trait Male extends Person {
     val isMale: Boolean = true
}

trait Female extends Person {
     val isMale: Boolean = false
}

trait Parent extends Person {
     val children: List[Child]
}

trait Child extends Person {
     val parents: List[Parent]
}

trait Father extends Parent with Male

trait Mother extends Parent with Female

trait Son extends Child with Male

trait Holy {
     val proceedsHolySpirit: Boolean
}

trait HolySpirit extends Holy {
     override val proceedsHolySpirit = false
}

trait HolySon extends Son with Holy {
     // I really tried to implement it in this way, but, you see later, it's impossible.
     // val parents = List(God, Mary)
}

trait HolyFather extends Father with Holy {
     val proceedsHolySpirit = true
}

trait CatholicHolyFather extends HolyFather {

     // TODO: Is he really need to be child of himself?
     val children = List(CatholicGod)
}

trait OrthodoxHolyFather extends HolyFather {
     val children = List(OrthodoxGod)
}

// TODO: He is not the father of Christ technically. Do we really need to mention him?
object FakeFather extends Father with Holy {

     // TODO: Had Joseph other children? From previous marriage, I don't know, or so?
     // TODO: There is symmetry violation with Holy Son's parents here. It may be a problem.
     val children = List()

     val proceedsHolySpirit: Boolean = false
}

trait Mary extends Mother with Holy {
     val proceedsHolySpirit = false
}

// TODO: Jesus Christ! You should have only one mother. But…
object CatholicMary extends Mary {
     val children = List(CatholicGod)
}

object OrthodoxMary extends Mary {
     val children = List(OrthodoxGod)
}

trait CatholicHolySon extends HolySon {

     // TODO: How many parents He has? Should we believe in 3 of them?
     // TODO: Or, maybe, we need another list for fake parents?
     val parents = List(CatholicGod, CatholicMary, FakeFather)

     // That's the case, which broke the party.
     override val proceedsHolySpirit = true
}

// TODO: Jesus! Now we have two copy of you too.
// TODO: And you are trait now, not the object, because the God is the object.
trait OrthodoxHolySon extends HolySon {
     val parents = List(OrthodoxGod, OrthodoxMary, FakeFather)

     override val proceedsHolySpirit = false
}

object CatholicGod extends God with CatholicHolySon with CatholicHolyFather

// TODO: It needs to be only one singleton. It is the Christian law, after all.
// Please, forgive me. But it was not me, who's done it in real world.
object OrthodoxGod extends God with OrthodoxHolyFather with OrthodoxHolySon {

     // TODO: Otherwise OrthodoxHolySon value overrides OrthodoxHolyFather value.
     // TODO: But HolySons are traits, not objects.
     // TODO: So, who does not proceed HolySpirit in this case?
     // TODO: Probably, we should use ChristianBoolean instead.
     override val proceedsHolySpirit: Boolean = true
}

trait God extends HolyFather with HolySon with HolySpirit {

     // TODO: Oh, yes. We have several singletons, which all are the only one.
     val isTheOnlyOne = true

     // TODO: It is very hard to make it works. Some helper is needed.
     // Please, God, help me.
     override def equals(obj: Any) = christianEquals(obj).boolValue

     def christianEquals(obj: Any) = {
         obj match {
              case _: this.type => ChristianReallyTrue

              // The other God case. Forgive me, The God.
              // It doesn't work with normal booleans. I've tried.
              case _: God => 
                  !ChristianTrue && !ChristianFalse && 
                        ChristianTrue && ChristianFalse

              case _ => ChristianReallyFalse
         }
     }
}

object ChristianTrue extends ChristianBoolean

object ChristianFalse extends ChristianBoolean

object ChristianReallyTrue extends ChristianBoolean {
     override def boolValue = true

     // TODO: That's the two rules, I can understand. But I'm not sure.
     override def unary_! = ChristianReallyFalse
}

object ChristianReallyFalse extends ChristianBoolean {
     override def boolValue = false

     // TODO: Here is the second one.
     override def unary_! = ChristianReallyTrue
}

// TODO: Please, God, help me to make this less abstract.
abstract class ChristianBoolean {

     // TODO: Oh, Christ! How it should work not for ChristianReallyTrue and ChristianReallyFalse?
     def unary_! = thatsTheLogic(this)

     // TODO: You can't understand this, can you?
     def ==(x: ChristianBoolean) = thatsTheLogic(x)

     // TODO: I am too. But I've found the Way. This is the Way. Yes. The Way.
     def !=(x: ChristianBoolean) = thatsTheLogic(x)

     // TODO: Should I do it. Why I do it?
     def ||(x: ChristianBoolean) = thatsTheLogic(x)

     // TODO: Because fuck, that's why!
     def &&(x: ChristianBoolean) = thatsTheLogic(x)

     // TODO: Now you know, how it works.
     def thatsTheLogic(x: ChristianBoolean): ChristianBoolean =
         Random.nextBoolean() match {
              case true => ChristianTrue
              case false => ChristianFalse
         }

     // TODO: Welcome to the real world, motherfuckers.
     def boolValue: Boolean = Random.nextBoolean()
}




doc-файл

Оставить комментарий

Предыдущие записи блогера :
Архив записей в блогах:
Денис Пушилин покинул пост спикера Верховного совета самопровозглашенной Донецкой народной республики. Об этом со ссылкой на вице-спикера Владимира Маковича сообщает «Интерфакс». «Денис сейчас находится в Москве. Он прислал на мое имя письмо с просьбой об уходе с занимаемой должнос ...
Вчера в одном питейном заведении разговорилась с американской тетушкой со следами бурного празднования Нового Года на лице. Слово за слово: "Вы откуда? А что за акцент? Из России?" Потом почему-то нестандартный поворот: "Вы не обидитесь, если я скажу, что Россия не должна была лезть в ...
Работы Прафулла Саванта ...
В субботу делал пули. Наделал на глаз штук 60-80, не считал еще. Всем, кто много стреляет пулями - рекомендую. Пуля Lee на 1 унцию, снаряжать на прессе Lee, пыж-контейнер на 24 грамма, навеска пороха - как на 28 грамм дроби. Можно стрелять с сужениями, но из ...
По Кузьминову ещё, который перелетел к врагу, подставив верных присяге сослуживцев. Тут, говорят, якобы получен приказ "сверху" на его физическое устранение. Но это один из тех случаев, когда подобное решение является не лучшим вариантом. Устранить его могут (и, кмк, почти наверняка ...