We do not believe that David, in any sense whatever, was here claiming to be absolutely perfect and sinless in the sight of God, but that he had been forgiven of all sins he had committed and that, at the moment of his deliverance, he was "clean" in "God's eyesight" (Psalms 18:24). Of course, all forgiveness during the dispensation of the Mosaic Covenant was dependent, in the final analysis, upon the ultimate sacrifice of the Christ upon Calvary. However, in the practical sense, "God passed over the sins done aforetime" (Romans 3:25), and that was the practical equivalent of divine forgiveness.
The explanation we have offered here is the only way we are able to think of David as "clean," "perfect," "righteous," and the keeper of" all God's ordinances." Of course, if the words are understood as descriptive of the "Son of David," even the Christ, then there is no problem.
Addis, rejecting the Davidic authorship of this psalm, did so, partially, upon the grounds that David could not possibly have described himself as one "Who kept the ways of Jehovah," However, we believe that Addis misunderstood what that verse really means. Rawlinson has the following very enlightening comment on that passage: "I have kept the ways of the Lord." The parallel line here is, "And have not wickedly departed from my God." "Departed wickedly" implies willful and persistent wickedness, an entire alienation from God. Not even in the humblest of the penitential psalms, in which David bewails his offenses against God, does he use such terms as `departed wickedly' concerning himself.
This means that in all the protestations of David here to the effect that he is clean in the sight of God, there is not a claim of never having done anything sinful, but a claim, which was true, that he had never "wickedly departed from his God," nor renounced his allegiance to the Lord. This is a very important distinction.
In the lives of two of Jesus' apostles, we find the distinction exemplified. (1) Judas "wickedly departed" from Christ, being terminally alienated from Him. (2) Peter, who shamefully and profanely denied the Lord, nevertheless, did not forsake Him, did not "wickedly depart" from Him; and, consequently was permitted to continue, after his repentance, as a faithful apostle.
The great consolation for Christians in these observations is that "Not even gross sins can prevent their ultimate and final salvation," provided only that they do not "wickedly depart" from the Lord, but repent of their lapses and forsake him not.
"I was also perfect with him" (Psalms 18:23). Leupold called attention to the fact that this should have been translated, "And so I was blameless (or perfect), etc."Also, in the very next verse, the text should read, "And so the Lord requited me." This has the effect of indicating that, therefore, David was blameless; therefore, the Lord recompensed him as perfectly clean and righteous. In other words, it was because David had never in any sense whatever "wickedly departed from God," but had clung to him even in the face of shameful sins and mistakes, God requited him on the basis of his fundamental love of God, and not upon the basis of human sins and mistakes of which he was most certainly guilty.
"I kept myself from mine iniquity." "It appears here that David had an inclination to some particular form of sin, against which he was continually on guard. We have no way of determining just what that sin was."
A fact not often stressed is that any Christian still in fellowship with the Lord may say anything that the psalmist here has said of himself. How so? "That I may present every man PERFECT in Christ" (Colossians 1:28). How wonderful, how glorious, how absolutely precious above everything else is the privilege of being "perfect" in Christ Jesus, as David claimed in these passages! Perhaps we should be a little more eager in our stress of this magnificent truth. But, don't Christians make mistakes, and sin? Indeed yes; but, "If we walk in the Light as he is in the Light, then we have fellowship one with another; and the blood of Jesus Christ his son cleanseth us from all sin" (1 John 1:7). The present participle "cleanseth" is an indication that the cleansing is constant, continual, and never-failing, thus keeping the child of God in a state of holy perfection.
The way in which all of this is deployed upon the sacred page is a providential arrangement designed to constitute also a prophetic indication of the absolute and genuine perfection of Our Lord Jesus Christ.
From Dale Ralph Davis' book on 2 Samuel, Out of Every Adversity, page 238-240., focusing on the parallel verses in chapter 22:
David makes some readers nervous as he continues:
Yahweh requites me as I act justly,as my hands are pure so he repays me (v 21, Jerusalem Bible)Is David in verses 21-25 dragging in a Santa Claus theology of works-righteousness? Does he claim too much for himself? Has he become blind to his sinfulness? Or do these words reflect a self-righteous attitude and a weakening of the sense of sin? These verses baffle thoughtful believers: how can David who had Uriah's blood on his hands and Uriah's wife in his bed even dream of saying anything like verses 21-25?
...In verse 22 David maintains, 'I have kept the ways of Yahweh, and I have not acted wickedly in departing from my God.' That can hardly be pressed as a claim to perfection. What he does claim, especially in the second half of the verse, is a general, overall fidelity to Yahweh. He has not, after all, committed apostasy, not turned his back on Yahweh. ('Though he had sometimes weakly departed from his duty, he had never wickedly departed from his God.' Matthew Henry...)
Verse 23 is another general statement: Yahweh's ordinances are 'before' David and he does not turn away from Yahweh's decrees. Then, it seems to me, in verse 24 David interprets all this. 'So I proved wholehearted towards him.' The Hebrew [word] does not claim perfection in life's particulars but wholeheartedness in life's commitment, Then note verse 24b: 'And I kept myself from iniquity.' He knows his nature, his tendencies. He has, however, guarded himself from giving way and giving in to the pull of his iniquity.
When David speaks of his righteousness and purity he does not point to sinless perfection but life direction; he is not sporting a pharisaical pride over errorless obedience but expressing a faithful loyalty via consistent obedience. All this is important, for it is such faithful, wholehearted (though afflicted) servants that Yahweh delights to rescue and who can then revel in the power and safety that Yahweh has provided.
The teaching of verses 21-31 is not some strange new wrinkle on your Bible page. It's been there all along. It is mainstream doctrine. Those who faithfully follow Yahweh and esteem his word by obeying it are those who can expect his blessing; those who don't can't. One can catch the flip side of 2 Samuel 22:21-31 in Judges 10: 6-14, Psalm 50: 16-23, or Jeremiah 2: 26-29. Why should those who reject Yahweh's lordship and despise his law (and therefore despise him) expect his rescue? Such folks have no ongoing commitment to Yahweh, only a temporary need for him. They no covenant relation with Yahweh; they only crave his prostituting himself for their immediate crisis. They do not seek God but a bomb shelter.