How the Spirit of Ghost Code prevents your code from failing.
SCALER USA
A transformative tech school, creating talent with impeccable skills. Upskill and #CreateImpact
The art of spotting errors before they happen.
Ready to build the software of your dreams? The one that aims to make the world a better place. You need a team to do that. There is something you need to know before you start. The best software architects and engineers are needed when creating a software system, however, the system still might not work. Therefore, before building anything, a plan or blueprint is absolutely necessary.?
Here program verification is the blueprint your program needs. It asks the question, "Are we building the product right?"; that is, does the program conform to its specifications? It helps you catch those bugs even before they show up. Now, with the rise in complexity of software and the need to ensure that they are reliable, it has become more important than ever to have programs verified.
If you're wondering where our friendly ghost comes into all this, just hang in there. First, let's understand verification.
What is Formal Verification?
If you think the chicken and the egg debate is a bit too much, here's something that is much more heated.
Is computer science modeled after mathematics or is it an independent discipline??
Some think that computing is a mathematical endeavor and that computer science ought to be modeled after mathematics. Others oppose formal techniques and contend that programming is the activity that is fundamental to computer science and that there are significant distinctions between it and mathematics. Making it incapable of producing a paradigm that is appropriate.
In all this, formal verification is a process of mathematically proving that a program meets its specifications. With the rise in complexity of software and the need to ensure that it is reliable, it has become more important than ever to have programs verified. This process can be used for various purposes, such as:
- Ensuring that the program will produce correct output for any input?
- Confirming that a program meets its specifications and is free from bugs or errors?
- Verifying that the code is secure against malicious attacks
How does it work?
Essentially, verification is a specification that is added to the main code. But these codes or algorithms do not alter the output of the program. They are only there for the purpose of verification. These are called Ghost Codes.??
The Soul of a Ghost Code?
Relax. Despite how terrifying they may sound, they are your friends. Ghost Codes are bug busters.?
They are called Ghost Codes because they remain hidden in our primary code. They are like check posts, that only let a program pass if the specifications are met.?
Ghost Codes are documented with comments that state conditions that should be true when program execution reaches the point where the comment is located. These comments are called preconditions, invariants, or postconditions, depending on their placement relative to a code or algorithm segment.
Preconditions: A statement put before the segment is referred to as a precondition. The condition must be met before entering the segment for the code to function properly. Preconditions are added at the beginning of functions and processes.
领英推荐
Postconditions: A statement positioned after the segment's conclusion is known as a postcondition. When the segment execution is finished, it ought to be true. Postconditions are added either following loops or at the point where a function or procedure exits.
Invariants: A statement placed in a code segment that is repeated and should be true each time the loop execution reaches that point is called an invariant. Invariants are often used in loops and recursions.?
Luckily, there exists a language that helps us automate the whole process of verification. Introducing…”GhostML”.
What is GhostML?
Ghost Code has been stumbling around to help coders for ages.?
ML here is not to be confused with Machine Learning. ML is a Meta Language, a language of description, specification, and verification.?
GhostML is a specialized language inspired by standard ML. Here, each functional variable is assigned the value of a ghost code to justify the parameters used by the coder. This basically means that the GhostML is present like a shadow everywhere. Almost like your embarrassing pictures on social media.
With the help of the type system, it is made sure that the Ghost Code stays far away from the regular code (making sure even its footsteps aren’t heard!). The essence of the job of the Ghost Code is to terminate, and not interfere. Why3 is a verification tool that implements GhostML.
Dafny, this language was developed at Microsoft Research is another example of a verification language. It is an imperative and functional compiled language that compiles to other programming languages. Some Dafny features have helped solve complex algorithms at Microsoft in VCC, a verifier for C programming language. It is also a great tool to teach reasoning about programs because of its simplicity and instant feedback mechanism.
Conclusion
Verification is a best practice that is yet to become mainstream. There are several developments happening in this realm and things will get better every day with research.?
Sometimes, even after all the careful considerations, there are programs that are so tricky that nobody knows why they work and why they don’t. They just exercise their power to haunt.
So no matter how great a developer you may be, sometimes you just need a friendly ghost who's got your back.?
Sources: