We read in Job, "He setteth an end to darkness"- but what was the darkness for? The verse continues, "and searcheth out all perfection: the stones of darkness, and the shadow of death."
"Darkness" here refers to the shadows of death. These are the suffering and the trials that God allows us to go through to make us aware of the shortness of our lives. While we think we are living in the shadow of death, the Lord is searching the depth of our maturity.
When God sees that we are mature and that we will go from faith to faith, trusting His character and His love no matter what happens, He gives us a glimpse of the shadow of death.
Another reason that God hides Himself is so we will discover the deep things of darkness. "He discovereth deep things out of darkness, and bringeth out to light the shadow of death" (Job 12:22).
What are the deep things of darkness? In the midst of pain, there is a purpose behind the pain. Even in the midst of dying, there is dying grace.
Behind whatever God does, there is something that He is going to teach us.