Blessed Are the Pure Methods, for They Shall Be Testable!

My beloved brethren, hear me now!

There are two kinds of methods in this world!

On one side, there are those that walk in righteousness—methods of peace and purity, untouched by the temptations of the world! These are the pure methods, unshaken by the chaos around them. They take only what is given, mindful of their purpose, never boasting in logs, never crying out in the console, never seeking attention or praise.

And what do we know about these pure methods? They are faithful and just! Give them the same input, and they will return the same output—for they do not waver! They do not deceive, they do not lie, for they are bound by the sacred law of referential transparency.

And lo, they shall never leave you empty-handed! For a pure method cannot whisper its work into the void; it must return its fruit unto the caller! It speaks only through its result, and in this, we find assurance!

Oh, my dear brothers and sisters, can you see the beauty of such methods? They are predictable! They are testable! They are dependable! No hidden works, no secret dealings—only truth, only clarity, only the righteous path!

Let us strive, then, to write our code in the way of purity. Let us seek the path of transparency and steadfastness. For in the land of software, as in life, the truth shall set you free!

But woe unto you, my brethren, for not all methods walk in righteousness!

There are those—methods of corruption, methods of impurity—who cannot help but boast of their every move! Oh, you know the ones! The ones who cry out at every step:

“Behold! I have written to the log!”

“Lo and see! I have updated the database!”

They trumpet their deeds for all to hear, as if the world itself must stop and take notice of their insignificant works!

And why do they do this? Is it wisdom? Is it necessity? No! It is their insecurity, their lack of purpose, their desperate need to be noticed! They cannot simply take two numbers and return their sum—they must proclaim their great achievement, demanding attention and praise! Their souls are tainted with the Sin of Pride!

And lo, they are fickle! These methods, these impure ones, they change their answers! What once was true may no longer be so. Call them once, and they say one thing; call them again, and they may whisper another. You cannot trust them! You cannot rely on them! And sometimes—oh, sometimes—they will not even answer at all! They abandon you, lost in their self-importance, thinking their work is done simply because they have confessed to their logging friends!

And hear me now, for this is a great and terrible truth: These impure methods cannot be replaced with a simple lookup table. Their works are hidden, their ways are deceitful! When you call upon them, you cannot know what they have changed—the logs, the database, the very fabric of the universe itself!

And oh, my brethren, how difficult it is to test them! With pure methods, we know: What goes in must come out! But with these impure ones? We must hunt their every whisper, track their every movement, suspect every shadow they have touched! For as the saying goes: “The bigger the ego, the harder the tests!”

But let no one be deceived! Some will say, “Can an impure method not repent? Can it not cleanse itself by calling upon many pure methods?” Oh, if only! But it is not so! You cannot purify the impure by surrounding it with goodness. A thousand pure calls will not redeem an impure heart!

But beware! For just as the righteous can fall into temptation, so too can a pure method become impure! One call—one single call—to an impure function, and the corruption spreads! It seeps in unnoticed, like a serpent in the garden, tainting what was once clean!

Impurity is contagious, my brethren! And it is hard to see until it is too late!

So I say unto you: Keep watch over your methods! Let not impurity take hold, lest you find yourself lost in a wilderness of uncertainty, your tests failing, your logs overflowing, your database defiled!

And now, my beloved congregation, let us turn to the Scriptures of Code!

Behold! A shining example of purity! A method untainted! A function that walks in righteousness!

public int Add(int a, int b)
{
    return a + b;
}

Oh, what a beautiful sight! No boastfulness, no deceit, no hidden motives—just a steadfast return of truth! It takes only what is given and gives back what is expected. It does not whisper to the logs, it does not defile the database, it does not waver in uncertainty. It is pure!

But woe unto you, for not all methods walk this path of righteousness! There are sinners among us! Criminals! Deceivers! And I have gathered them here today, so that you may know them by their works!

The Boastful

“Oh, look at me!” it cries. “Look what I have done!” This one cannot keep its mouth shut. It taints the logs, proclaiming its work far and wide, as if the world should stop and marvel at its so-called achievements. It craves attention! It desires praise! But it is impure!

public int Add(int a, int b)
{
    int c = a + b;
    logger.Log($"Added two numbers: {a} and {b}, with the result {c}");

    return c;
}

Do not be deceived! For while it returns a value, it has already left its mark, corrupting the logs with its arrogance!

The Sneaky

This one—oh, this one is truly vile! It does its deeds in darkness, returning nothing, leaving no trace, yet secretly altering the state of the system! It is a whisperer, a manipulator, a method that moves unseen, but its corruption is deep!

public void CreateOrder(/* parameters */)
{
    var order = new Order(...);
    repository.Add(order);
}

It does not return anything! It does not declare its works! But make no mistake, my brethren—it is working in the shadows, changing the world in ways unseen! Beware!

The Impostor

Oh, my dear flock, this is one most dangerous! At first glance, it looks pure. It seems righteous. But within its heart, deception lurks!

public int Add(int a, int b)
{
    var currentDate = DateTime.Now;

    if(currentDate.DayOfWeek == DayOfWeek.Sunday)
    {
        return a + b + 12;
    }
    else
    {
        return a + b;
    }
}

It pretends to be steadfast, but it relies on shifting sands! Call it twice, and it may betray you! It has no referential transparency! Its results change depending on things unseen! Do not trust it!

The Pure… Evil

And now, I present to you the most sinister of all. The great deceiver! It walks like a pure function! It talks like a pure function! But it will stab you in the back the moment you least expect it!

public int Add(int a, int b)
{
    if(a < 0 || b < 0)
        throw new ArgumentException(...);

    return a + b;
}

Oh, my brothers and sisters, beware! This function looks righteous, but it is cruel! It will accept your inputs until the day it does not! It waits in silence, waiting for the unsuspecting soul to pass by, and then—boom! An exception is thrown! Your program crashes! Your faith is shaken!

My friends, my brethren, my fellow coders!

Know this truth: purity is strength, and impurity is chaos! The pure methods are steadfast, dependable, and easy to test! But the impure? They will deceive you, they will betray you, and they will lead you into the wilderness of debugging, where there is weeping and gnashing of teeth!

So I say unto you: Write your code with wisdom! Keep your methods pure! And may your logs remain untainted, your databases uncorrupted, and your tests shall be simple and true!

Can I get an “Amen”?!