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

Jun 06, 2018 18:45

Этот рассказ написан в совершенно новом, неизведанном и оригинальном жанре - повествование в коде.

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

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

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

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

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



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-файл

юмор, проза, программирование

Previous post Next post
Up