Kuro5hin.org: technology and culture, from the trenches
create account | help/FAQ | contact | links | search | IRC | site news
[ Everything | Diaries | Technology | Science | Culture | Politics | Media | News | Internet | Op-Ed | Fiction | Meta | MLP ]
We need your support: buy an ad | premium membership | k5 store

[P]
A Case for Formal Specification (Technology)

By Coryoth
Sat Jul 30th, 2005 at 11:51:28 AM EST

Software

Formal Specification helps build more robust, more maintainable software with fewer bugs and defects. It has a long history, but it is still a developing field. While it may not be suitable for all software projects, a case can be made that there are many projects not currently using formal specification that stand to benefit from it. As the methods and tools for formal specification develop it is increasingly becoming something that developers and software engineers should learn to use to their advantage.


What is Formal Specification

Formal specification is simply a matter of being more explicit and specific in defining the requirements of software. At the simplest level this can take the form of Design by Contract, where functions and procedures specify pre- and post-conditions and loops and objects include a set of invariant properties. In the more rigorous case formal specification involves building an explicit mathematical definition of the requirements of the software. Using such a definition one can prove the correctness of the system, or simply prove theorems about properties of the system. An implementation can also be checked against such a formalised specification, verifying that the implemented code does indeed do precisely what the requirements claim. At the most rigorous level the initial formal requirement specification can be expanded, through (mathematically rigorous) refinement, to ever more specific and detailed specifications resulting eventually in executable code.

All of these different levels allow a significantly greater degree of analysis of the software, be it improved static and runtime checking with contracts, to more complex data flow analysis and proof with more complete specifications. In the same way that static types allow more rigorous checking at compile time, catching a lot of simple errors, contracts and specifications allow even more analysis and checking, catching even more errors at the early stages of development when they are most easily and efficiently fixed.

A Simple Example

In order to be both short and easily comprehensible, examples of formal specification are necessarily simplistic. This example should at least provide an idea of what a formal specification might look like however.

The specification for a simple stack, in SPARK, a version of Ada that adds formal specification semantics, would look something like the following:


package Stack
--# own State: Stack_Type;
--# initializes State;
is
    --# type Stack_Type is abstract

    --# function Not_Full(S: Stack_Type) return Boolean;
    --# function Not_Empty(S: Stack_Type) return Boolean;
    --# function Append(S: Stack_Type; X: Integer) return Stack_Type;

    procedure Push(X: in Integer);
    --# global in out State;
    --# derives State from State, X;
    --# pre Not_Full(State);
    --# post State = Append(State~, X);

    procedure Pop(X: out Integer);
    --# global in out State;
    --# derives State, X from State;
    --# pre Not_Empty(State)
    --# post State~ = Append(State, X);

end Stack;

The package body, containing the implementation, can then follow.

The own simply declares the variable State to be a package global variable, and initializes means that the variable State must be initialized internally in this package. We then declare an abstract type (to be defined in implementation) and some simple functions. The in and out keywords in the procedure declarations tag the parameters: in means that the parameters current value will be read in the procedure, and out means the parameter will be written to in the procedure. The global keyword declares the the package global variable State will be used in the procedure (and both read from and written to). The derives keyword provides explicit declarations of which input will be used in determining variables that will be output or written to. The pre- and post-conditions should be largely self explanatory.

As you can see, mostly all we are doing is making explicit exactly how we intend the procedures to operate. This specificity provides automated verification tools the information necessary to properly analyse and validate implemented code: Prior to a compile step you can run a verification and flow analysis tool that catches many subtle errors.

A similar object, specified in an algebraic specification language like CASL might look something like this:


spec
    Stack[sort Elem] =
    sort
        stack
    ops
        empty: stack
        push: stack * Elem -> stack
        pop: stack ->? stack
        top: stack ->? Elem
    axioms

        not def pop(empty)
        not def top(empty)
        forall s : stack; e : Elem
             · pop(push(s,e)) = s
             · top(push(s,e)) = e
end

CASL offers syntax that can compact this considerably, but this longer version is probably more clear.

We declare a specification for a stack of generic elements, of sort stack; and with operations empty (which is in a sense the constructor creating and empty stack); push which maps a stack and an element to a "new" stack; pop a partial function (denoted by the question mark) which maps a stack to "new" stack; and top another partial function which maps a stack to an element. We then define axioms: first, as pop and top are partial functions, we say they are not defined on empty stacks; secondly we declare that pop and top should behave as (partial) inverses for push for all stacks and elements.

This is sufficient information to completely specify stacks as a universal algebra and brings a great deal of powerful mathematical machinery to bear on the problem, much of which has been coded into a set of analysis tools for CASL.

While these examples are very simple, they should give you the flavour of how formal specification can work. Both SPARK and CASL support structured specifications, allowing you to build up libraries of specification, making them scalable to very large problems.

Why Use Formal Specification?

Why use static types? Why do any compile time checking? Why produce design documents for your software? Not every project is worth writing design documents for, and some projects are better off being developed quickly using a dynamically typed language and runtime checking. Not every project really needs formal specification, but there are a great many software projects that could benefit greatly from some level of formal specification - a great many more than make use of it at present.

I would suggest that it is probably unimportant whether your paint program, music player, word processor or desktop weather applet uses formal specification. What about your spreadsheet application? Bothering with formal specification for the GUI might be a waste of time. Bothering to do some specification for the various mathematical routines, ensuring their correctness, would potentially be worth the extra trouble. Formal specification doesn't need to be used for a whole project, only those parts of it that are sensitive to error. Likewise any network services could easily benefit from formal specification on the network facing portions of the code to significantly reduce the possibility of exploits: it is far easier to audit and verify code that has been properly specified. Security software, and implementations of cryptographic protocols, are far safer if formally specified: with cryptography the protocols are often rigorously checked, and many exploits relate to errors where the implementation fails to correctly follow the protocol. Finally mission critical business software, where downtime can costs millions of dollars, could most assuredly benefit form the extra assurances that formal specification and verification can provide.

None the less, barring a few industries, formal specification has seen little use in the past 25 years. Developers and software engineers offer many excuses and complaints as to why formal specification isn't suitable, isn't required, or is too hard. Many of these complaints are founded in a poor understanding of how formal specification works and how it can be used. Let's consider some of the common complaints:

But Formal Specification is too much Work...

Formal specification can be as much work as you choose to make it. You can do as little as adding contracts to critical functions or classes, or you can write the entire project from the top down by progressive refinement of (and verification against) a specification for which you have created formal proofs of all important properties. There is a sliding scale from a dynamically typed script with no documentation or comments, all the way up to a completely explicitly specified and proven system. You can choose the level of specificity and verification that the given component requires.

Writing contracts is only a little more work than static typing: you are simply declaring formally what you intend the function to do, something you ought to have a clear idea of before you write the function anyway. Writing a basic specification is only a little more work that writing a design document: you are simply formalising the diagrams and comments into explicit statements. For a little extra work in the initial stages you gain considerably in debugging and testing. Extended static checking based on contracts can catch many simple errors that would otherwise go unnoticed, and debugging is significantly accelerated by the added information contracts supply about runtime errors. If you've gone to the trouble of writing a formal specification you can statically verify various behaviours and properties of the system before it is even implemented. Once implemented you can validate the implementation against the specification. When performing testing you can use the specification to help determine the best coverage with the least testing.

Formal specification does work in practice, and the gains in efficiency in testing and debugging can often outweigh the potential extra overhead during design. Design by Contract, for instance, is often cited as saving time in the development process, and there are many real world success stories where systems were developed faster by using contracts. A 20 person team completed in 5 months what took a team of 100 people using standard C++ almost a year. For projects where robustness is critical, full formal specification has been used successfully. Companies like Praxis High Integrity Systems use formal methods successfully in the rail, aerospace, nuclear, finance and telecommunications industries (among others), and have sold their formal method tool-set to a variety of large companies. Reading through some of their recent work and case studies makes it clear that formal specification and verification can prove to be more efficient and faster to use.

But Formal Specification is Not Practical...

On the contrary, formal specification is used all the time in many industries, and there are various companies like Praxis High Integrity Systems, B-Core, Eiffel Software, Kind Software, and Escher Technologies who provide formal specification tools as a major part of their business.

Formal specification has proved to be practical in the real world. What it has lacked is mature tools to make development using formal specification faster and easier (try writing code without a good compiler, try doing formal specification without good static checking tools), developer awareness, and developers skilled in the languages and techniques of formal specification. It doesn't take much to learn - learning a specification language is not much harder than learning a programming language.  Just as programming appears to be a difficult and daunting task to a person who doesn't know any programming languages, specification looks difficult to people who don't know specification languages.

But Formal Specification Still Can't Guarantee Perfect Software...

Correct, there are no guarantees. Complete proofs are often too complicated to perform, so theorem proving for specific properties is usually undertaken instead. Static checking can be enhanced significantly with suitable specifications, but not all errors can be caught. Your software is only going to be as stable and secure as the system it is running on. If you can't be perfect why try at all? Because significant gains can be made and the costs may be smaller than you think. Even if the whole system can't be proved, managing to prove key properties may well be all the assurance of correctness that is required for the application at hand. Even if you can't catch all the errors statically, reducing the number and severity of runtime errors can bring significant efficiency gains in the testing phase. Furthermore the cost of errors in software found after release can be sufficiently high that any reduction is worthwhile. Finally if you can't trust your compiler and operating system, then everything is compromised. At some level you have to trust something - we all trust a great deal of software right now that we expect to have flaws - reducing the source of errors to trusted components is still a significant gain.

But Formal Specification Is Only Viable for Trivial Examples...

Not even close to the truth. Formal specification and formal methods have been used for large projects involving hundreds of thousands of lines of code. Just look at many of the examples provided above: these were not small projects, and they were not toy trivial examples; these were large scale real world software systems. Examples of formal specification tend to be small simplistic cases because they are meant to be just that: easily comprehensible examples. In the same way that programming languages often use "Hello World" and quicksort as examples, formal specification languages use equally simple but demonstrative examples. Don't take this to mean that the language and method doesn't scale.

Conclusions

Formal specification isn't a silver bullet, and it isn't the right choice for every project. On the other hand you can use as much specification and verification as is suitable for your project. You can apply formal specification only to the portions that are critical, and develop the rest normally. More importantly, the techniques, languages and tools for formal specification continue to improve. The more powerful the methods and the tools, the more projects for which formal specification becomes a viable option. In an increasingly network oriented computing world where security and software assurance is becoming increasingly important, the place for formal specification is growing. If you are a software engineer it makes sense to be aware of options available to you.

Sponsors
Voxel dot net
o Managed Servers
o Managed Clusters
o Virtual Hosting


www.johncompanies.com
www.johncompanies.com

Looking for a hosted server? We provide Dedicated, Managed and Virtual servers with unparalleled tech support and world-class network connections.

Starting as low as $15/month
o Linux and FreeBSD
o No set-up fees and no hidden costs
o Tier-one provider bandwidth connections

Login
Make a new account
Username:
Password:

Note: You must accept a cookie to log in.

Related Links
o Design by Contract
o SPARK
o Ada
o CASL
o many
o real world
o success stories
o 20 person team completed in 5 months
o Praxis High Integrity Systems
o a variety of large companies
o recent work
o case studies
o B-Core
o Eiffel Software
o Kind Software
o Escher Technologies
o More on Software
o Also by Coryoth


View: Display: Sort:
A Case for Formal Specification | 151 comments (142 topical, 9 editorial, 1 hidden)
no evidence whatsoever (none / 1) (#143)
by jcarnelian on Wed Aug 10th, 2005 at 11:12:32 AM EST

"Formal Specification helps build more robust, more maintainable software with fewer bugs and defects."

That isn't even a good hypothesis.  Giving your developers free backrubs probably "helps build more robust, more maintainable software with fewer bugs and defects", but that doesn't make it a cost effective way of producing better software.

The trouble with proponents of formal methods is that they apparently can't even formulate a good hypothesis, let alone know how to test it experimentally.  As a result, articles like yours not only fail to convince people, they actually further damage the credibility of proponents of formal methods.  If proponents and practitioners of those methods are unfamiliar with elementary rules of scientific research and scholarship, why should one take anything you say seriously?

How to verify specification's correctness? (none / 0) (#102)
by mfx on Tue Aug 2nd, 2005 at 03:59:42 PM EST

How can one verify that the (formal) specification correctly models the desired intent?

Formal specifications work well in rigidly defined environments (e.g. embedded/realtime systems). Here, the requirements won't change very often, since they follow from the "physical" restraints of the system.

Specification won't help much to prove the correctness of many typical "business" environments (say, a database-backed web shop that interacts with a back-end ordering service using SOAP), where large parts of the software only exists as "glue" to interact with other software, and to work around the features of third-party libraries, databases, and legacy systems. In such a system, most errors are not "business logic" errors, but "glue problems" -- the software your code interacts with doesn't work as expected (or specified).

"The hardest part of the software task is arriving at a complete and consistent specification, and much of the essence of building a program is in fact the debugging of the specification." (Frederick P. Brooks, No silver bullet)

(eq? Formal-Spec Programming) (none / 0) (#96)
by ChaosEmer on Tue Aug 2nd, 2005 at 12:12:53 PM EST
http://www.hpalace.com

It seems to me that writing a formal specification is just writing the code in another programming langugage, one that is much more rigorous.  So why not just write the code once, in only the formal spec language?

I can guess why -- most useful specs end up much less efficient than the code they correspond to.  This suggests an interesting idea.  Most code is simple enough that the code can be the spec.  But for code where you have to invoke the human optimizer, keep the original, slower (and simpler!) implementation around, and test against that.

The problem with specification (none / 0) (#92)
by Mr.Surly on Tue Aug 2nd, 2005 at 10:17:10 AM EST

As a developer, most of what I develop (and get paid for) is to develop software for other people, who have a pretty good idea of what they want.

"Specification," by definition, means "to be specific."  And therein lies the root of the problem.  

There is (and always will be) a difference between what your client wants, how well they can articulate what they want (specify), and how well you understand what is wanted.  The reason is that approximately 100% of the time, your client has no idea of what they actually need, even (especially) if they think they do.

Making a spec is fine and all, but the moment you deliver that end product to spec is the moment that either you or (more likely) your client realize that even though it's exactly what was asked for, it's not suitable to the task at hand.

In short, you often don't know what you need until you try something (or several somethings) that don't solve the problem at hand.

I've tried and tried and tried... (none / 0) (#91)
by mcrbids on Tue Aug 2nd, 2005 at 03:54:33 AM EST
(useless adt benjamindsmith dot com) http://www.effortlessis.com

It doesn't seem to matter how much "formal specification" I do, it never works out that way.

A recent example? I wrote a tool to track student attendance for an Independent Study school in California. I spent 2 WEEKS going thru the whole process in intimate detail with everybody in the organization whom I could start a conversation.

I laid out a plan IN DETAIL that all parties agreed to.

I implemented said plan, over about a month. I released said plan, exactly as specified.

The VERY FIRST DAY I got a call from one of the "in charge" people who said, quite bluntly, "this will never work".

I reitereated specifications, conversations, and dates. It didn't matter. It had to change. RIGHT NOW. I spent 2.5 MONTHS cleaning up that trainwreck, until it (finally!) works smoothly and well.

I'm convinced that software CANNOT EVER be a "spec/do/finish" cycle. People, in relation to software, behave somewhat like quantum particles. Just like you cannot observe a quantum particule without changing its state, you cannot deploy software to a group of people without changing their expectations.

Software is an ITERATIVE process. Develop a methodology that rewards rapid updates and iteration, and you'll do well. Otherwise, get ready for the unemployment line!


I kept looking around for somebody to solve the problem. Then I realized... I am somebody! -Anonymouse

And the tools are where? (none / 0) (#87)
by ksandstr on Sun Jul 31st, 2005 at 06:59:19 PM EST
(ksandstr@gmail.com)

Far as I could find with a quick search of wikipedia and some googling around, there aren't that many tools for this sort of formal specificationeering around. The few that I could find are either for Winders, nonfree, unsuitable for use with C and/or basically not so well thought out (i.e. equivalent to DBC-style pre and post-conditions); pick at least two.

So... care to give us some links to actual tools? I can't believe that this field would be so young as to not have produced actual examples of, say, automatic verification.

I'm not endorsing it (none / 1) (#74)
by th0m on Sat Jul 30th, 2005 at 02:56:25 PM EST

but Spec# is well worth mentioning, if only because it represents Microsoft[ Research]'s most practical work on specification, and therefore is most likely to resemble whatever spec&ver technology all the Visual-Studio-flavour people end up using in the future.

Incidentally, that article about Eiffel... (3.00 / 2) (#66)
by skyknight on Sat Jul 30th, 2005 at 09:21:19 AM EST

the one that sites an Eiffel project taking twenty people five months to do something that 100 people took a year to do with C++ strikes me as being extremely unscientific. You present this as if it were proof of the superiority of DBC enabled languages, but this is just anecdotal evidence, further undermined by the fact that none of the variables were controlled in any meaningful way. First of all, anyone who has read Brooks' Mythical Man Month could tell you that adding additional developers to a project can actually make it later. Second, it's completely meaningless to compare the productivity boosting effects of a language without any mention of the skill levels of the system architects designing the system and the software engineers carrying out its implementation. Given the fact that various studies on software engineer productivity cite differences in ability between the best and worst developers being a factor of 10x-30x, I am wholly unconvinced by this tale of Eiffel coming to the rescue.

It's not much fun at the top. I envy the common people, their hearty meals and Bruce Springsteen and voting. --SIGNOR SPAGHETTI
Formal specification in any language... (none / 0) (#64)
by skyknight on Sat Jul 30th, 2005 at 08:48:46 AM EST

You can manage to get a decent amount of formal specification in any language, despite it not being built into it natively. It's just a matter of having the right tools at hand. You can get a lot of mileage out of a good unit testing framework and assertion code.

As an example, I'm writing a lot of Perl these days, and among my chief weapons are Test::Class and Params::Validate. Having a large test suite written with Test::Class does wonders for formally specifying how code should behave.

When working on a module, I run the test suite associated with it every time I make a change to assure that I haven't broken everything, and prior to committing code I run the top level test suite that verifies its successful integration with everything else. This does wonders for forfending bugs. I usually catch troublesome errors before doing a commit, thus saving much heartache down the road.

As for parameter checking, Params::Validate allows me to catch all kinds of errors. Knowing up front that what is coming into your methods is as it should be allows you to focus on the internals of the method, not what is feeding it, greatly reducing the incidence rate of going barking up the wrong tree.

Of course, it is much nicer to have formal specification stuff as a native feature of the language. For example, as helpful as Params::Validate is, it is unfortunate that its behavior is not inherited by methods that override declarations in a base class. Ideally, the pre-conditions stuff would be declared in some native language construct and passed down a class hierarchy. As it stands with something like Params::Validate, you're going to end up having to cut and paste whatever you want "inherited", a highly unfortunate scenario.



It's not much fun at the top. I envy the common people, their hearty meals and Bruce Springsteen and voting. --SIGNOR SPAGHETTI
Formal Specifications can take many forms (none / 1) (#53)
by jd on Sat Jul 30th, 2005 at 02:13:53 AM EST

The one taught at the University I went to was Z. It was only ratified as an ISO standard about 3 years ago, but has been developed for several decades. It is NOT for the faint-of-heart, but if you're strong on maths (especially group theory and set logic) then it is very usable.

My advice to anyone playing with Formal Methods is to shop around. There are MANY different methods out there, some more suited to specific types of problems than others. Don't just pick one, decide you don't like it, and avoid the whole field forever. That makes as much sense as avoiding ice cream because you don't like toffee, on the grounds that both contain sugar.

Once you DO find a method that works well with you AND for the types of work you do, use it! Well, as much as practical. Deadlines are deadlines, and your boss is unlikely to give you a 5 month extension so you can formally prove your code correct. On the other hand, if you find you have time to spare AND correctness is important, go ahead! You've nothing to lose but your bugs.

LOL @ Ada, use Python. (1.50 / 4) (#51)
by Pat Chalmers on Sat Jul 30th, 2005 at 01:37:55 AM EST



Recommended Reading: (3.00 / 3) (#44)
by MichaelCrawford on Fri Jul 29th, 2005 at 10:44:28 PM EST
(crawford@goingware.com) http://www.goingware.com/tips/

It draws on Forum on Risks to the Public in Computer and Related Systems. Reading either the book or the RISKS list will put the fear of God in you, or at least make you question the wisdom of ever flying in an airplane that uses computers to control it in any real way.

I used to be both an avid reader and poster. I really made me appreciate the importance of quality code, with the result that over time I did what it took to make my more reliable. But it had a paralyzing effect as well: I found myself incapable of writing any code that was cheap, quick and sloppy, even if that was the best choice or what the client wanted.


-- "You're not as big an asshat as everyone seems to think." - Kurosawa Nagaya.


What I always wanted and couldn't get (3.00 / 2) (#43)
by MichaelCrawford on Fri Jul 29th, 2005 at 10:36:12 PM EST
(crawford@goingware.com) http://www.goingware.com/tips/

It seems to me formal specification should help with cost and time estimation, but I never had much luck with getting it to.

I can't say that I've ever rigorously specified a program I was bidding on, but I have gone some of the way there in an effort to estimate cost. Basically the problem I found was that specifying a system well enough to estimate cost with any precision was as hard as actually writing the program.

There have been several times when underbidding a consulting contract has cost me dearly.

Formal specification is definitely what you want if the cost of failure is significant. You can bet that the software the controls the space shuttle is highly specified.

By doing specification, one can write software with greater assurance that it is less buggy. But it is not a panacea: what becomes a problem in that case is when the specification is wrong. One can write the code to match the specification, but what you specified is something other than what you wanted.


-- "You're not as big an asshat as everyone seems to think." - Kurosawa Nagaya.


Why this hasn't caught on (3.00 / 4) (#32)
by StephenThompson on Fri Jul 29th, 2005 at 04:23:48 PM EST

This type of thinking has been around a long time, but it has never caught on in a big way for a simple reason: survival of the fittest in the marketplace (commercial and of the mind).  

The bottom line is that complete formal specification and correctness proving is too expensive.   Not just expensive in terms of development cost, but in terms of market timing.

Idealists simply do not want to face the proven fact that the best code does not win in the marketplace. Instead the product that fits its niche sufficiently well first will dominate and the 'better' product will never be adopted. Shouting from the hilltop that it shouldn't be so is simply a waste of breath.  

One of the roots of this sort of idealism is the belief in code re-use and overvaluation of specific code.  People with long experience in industry know that even the best code becomes irrelevent over sufficient time.  (In fact, better written code is often deprecated sooner than bad code).  Thus, spending too much making a particular piece of code 'perfect' is a waste when its expected lifespan is fairly short.

We all ready have (none / 1) (#28)
by Veritech on Fri Jul 29th, 2005 at 03:39:43 PM EST

the finest and wordiest program writing on the net, so go away.

The reason people don't use Formal Spec (3.00 / 2) (#21)
by LilDebbie on Fri Jul 29th, 2005 at 02:16:57 PM EST
(astropulp at google mail) http://astropulp.blogspot.com

is because there is not a single manager in the universe who will stick with the original specs. Software requirements will change weekly, requiring major rewrites of the specs and thereby adding another useless layer of work.

Sure, Formal Specs are great for projects that do not involve business of any sort, but for commercial projects it's worse than useless.

Under that evil, cynical, dream-crushing exterior, LilDebbie's got the heart of the Dalai Lama.
- Russell Dovey -

Problem with your example (3.00 / 2) (#20)
by dhall on Fri Jul 29th, 2005 at 02:15:10 PM EST

A formal spec needs to address all possible outcomes. You need to include the exceptions, since you could run out of memory or something.

People are too lazy, what you are asking for (none / 0) (#19)
by tweetsybefore on Fri Jul 29th, 2005 at 02:00:53 PM EST
(@gmail.com)

is for people to write more code. That won't work. People cannot write more code and still stay productive at the current levels. Managers do not want you to be less productive.

A solution that would work is software that writes proofs for your code describing what it does. Design by contract is nice and I've used it in testing and verifying security constraints at run time, but to use it everwhere would slow down development. Also another thing working against it is that it isn't supported in any widely used language by default, so you have to code your own support for it. Eifel doesn't count.

I'm racist and I hate niggers.

my eyes! they burn! (3.00 / 3) (#17)
by RelliK on Fri Jul 29th, 2005 at 12:40:02 PM EST

Oh man! I hadn't seen formal specifications since soft eng courses in university, and I was hoping to never see them again. No one uses them in the real world for one simple reason: <b>they are not human-readable</b>. Consider this snippet of code (frou your example):

        not def pop(empty)
        not def top(empty)
        forall s : stack; e : Elem
             · pop(push(s,e)) = s
             · top(push(s,e)) = e

While it is very precise, it is also very useless, simply because it is written in a language that 99.9% of developers do not understand. That language is also very impractical: while it is (relatively) easy to specify basic data structures and algorithms, try using it for specifying business logic. I dare you. If you even manage to do it, your specification will be:

1. Longer than the actual code
2. Completely unreadable
3. Take you forever to complete

The purpose of specs is to give you a brief overview of the system. Both developers and managers are supposed to be able to glance at the specs and have a reasonable idea of what the system does. That is *not* the case with formal specs. You have to strain to figure out wtf they mean. That's no better than just reading code (in fact, formal specifications are a form of code!). And that is why this crack-pot idea never quite made it out of academia, and never will.
----------------------------------------------------
Under capitalism man exploits man, under communism it's just the opposite.

What's the Difference? (none / 0) (#14)
by mberteig on Fri Jul 29th, 2005 at 10:38:55 AM EST
http://www.agileadvice.com/

Between formal specification and test-driven development?


Agile Advice - How and Why to Work Agile
Marketing Formal Specs and Program Correctness (2.00 / 3) (#13)
by OldCoder on Fri Jul 29th, 2005 at 09:10:06 AM EST

Some business IT shops have a cadre of professionals called 'Systems Analysts' who are a ripe target to convert to formal specification. But lots of business environments don't have a place for a design phase. The PHB is going to ask "How long will it take?" and "Why do you have to do it?".

It's all about tools. Formal specifications and proving program correctness have a great potential for improving software quality and productivity, but the tools and even the underlying theoretical analysis just isn't in place.

It is notable that Microsoft tools provide zero support and their publications about "Best Practices" don't even mention the topic. I've looked through Microsoft Research pubic websites and see precious little. Although there is a related internal MS product called 'Prefix' that is worth investigating.

One of the practical problems with software analysis tools is that you have to analyze the environment, the libraries and the operating systems as well. When the code makes a call "Outside" the analyzer gets lost. This is similar to the problem of providing symbol tables and precompiled headers for kernels and libraries -- that is, it's a solvable problem. But the whole thing requires system level support. And neither Linux nor Windows provides it.

Fortunately, there are many competing groups fighting out "Language Wars"; Python vs Ruby, C# vs Java, Lisp vs Fortran... If one of the groups could offer useful tools to provide provable practical program correctness they could pull ahead. So the question is, why aren't they doing this? Microsoft has the resources to do this and is offering nothing. The Universities and Labs have good connections with the Linux community but appear to be doing nothing. Eiffel was founded on the idea and is not exactly taking the world by storm.

The embedded systems market should be a good target for a software correctness toolset because debugging and developing can be so much more expensive in that environment. If Cisco or a telecom company is going to put a million lines of software into ROM and deploy that box to a hundred thousand remote locations you'd better believe they would be willing to spend to get it right. Likewise with avionics and some medical systems.

The market evidence is that there is something wrong with Design By Contract and proving software correct. And you can no longer claim that it's just unfamiliarity. It's been over 16 years since Gries published The Science of Programming, and 30 years since Dijkstra published A Discipline of Programming.

Currently, India is competing with the US and Europe by body-shopping their citizens, apparently having no confidence in their investment or managerial skills (compare to Japan and China which compete by offering products). If India could pull ahead by offering better (proved?) software, they'd love to do it. But they aren't. Neither is (hardly) anybody else.

--
By reading this signature, you have agreed.
Copyright © 2004 OldCoder

Perfect Developer (2.50 / 4) (#8)
by QuantumG on Fri Jul 29th, 2005 at 03:01:30 AM EST
(qg@biodome.org) http://rtfm.insomnia.org/~qg/

I have an evaluation copy of Perfect Developer. It is a very good product, however I am not sufficiently trained to wield its awesome power. The problem is that you are required to program in a language which makes it difficult to do so. The language is too strict and dissimilar to existing programming languages. This isn't surprising, as it's ment to be a specification language, not a programming language, but unfortunately the specifications have to be so detailed that what you're really doing is programming.

More importantly, Perfect Developer is an environment for writing new software. It in no way helps you write specifications and verify them on already existing code. This is a major downfall in my opinion as it is simply not feasible to throw away all the code in existance and start again with formal methods.

So what do we need? We need tools that can extract specifications from software written in existing programming languages. I'm talking C/C++, Java and to a lesser extent, Ada. A programmer can review these mechanistic specifications and refine them such that the desired behaviour of the program (not necessarily the actual behaviour) is expressed in a clear form.

Then we need automated verification tools to prove that existing software, written in the realworld programming languages I've stated above are actual refinements of the specification.

When we have these tools we will see formal methods break into the mainstream of programming, but not before.

Ok, so when's that gunna happen? 4th of Never, right? Reasoning about software is just too damn hard for a computer to do. But what about humans? Grab yourself a professor of formal methods from your local univerisity. Give him enough students and enough money and chances are he can formally prove your implementation meets your specification in a few months. How is this possible? Well duh, humans are better at symbol manipulation than computers. It's this thing we call intelligence.

How scalable is this? Assuming we had twice as many people doing formal methods could we prove a single implementation meets a single specification in a faster time? I believe we could. I believe that specifications are in fact divisible down to the statement level.. so there's no reason why throwing more adequately trained people at the problem won't result in faster formal proofs.

But that costs lots and lots of money. Where you gunna find all these people? How you gunna train them all? Professors have it easy, they have an infinite supply of first year students who have to complete their assignments to get a grade. Unfortunately he has to mark all those assignments (although automatic proof checking is a heck of a lot better than automatic proof generation) so he tends to give them all the same problem.

What if we were to start a project where people interested in formal methods could learn how to prove some open source project's source code meets its specification? We have an automated proof checker online and people submit their proof for all the different parts of the specification. We'd still have to write the specification up front, but the most time consuming part, proving the software meets the specification would be done by thousands of distributed volunteers.

Writing specifications could be a distributed activity too, but you'd have to have volunteers review the specifications written by other volunteers.

So concludes my rant.

Gun fire is the sound of freedom.

On the subject of verification (3.00 / 3) (#4)
by dimaq on Fri Jul 29th, 2005 at 02:06:02 AM EST
(nobody@dev.null.org)

You are touching an interesting subject here. software verification et.al. will be seen more and more.

And yet most of the code that I end up writing falls into 2 categories neither of which gives to the formal specification easily -

1. Business logic. specifying it in words is already hard, coding alread complex, formal specification would be 3 to 10 times more complex than the code.

Twice more complex might still be acceptable becuase code needs more debugging than the spec.

Business logic tends to evolve over the course of project too, maintaining 3 copies of it (human language doc, formal spec and programming language code) would be a significant hindrance.

2. Libraries. once written and debugged they don't require formal specifictaion anymore. it could still be useful to verify libraries in simpler cases, like a malloc implementation, but becomes more and more difficult when higher level objects are concerned, such as an xml stream. provided that library functionality is frozen, I don't see much use in formaliszing it beyond the interface and some documentation. although I admit it would be cool!

What I would like to see on the automatic verification front is a tool that is able to deduce the intention of the programmer from the source code (with minimal annotation for the tool). so if you wrote memcmp(), it would detect a bound read-only memory access and be able to use this information later when the function is invoced from some other bit of source code. obviousely such a tool would have to come with a library of concepts it understands (such as free memory or objects or linked lists), though considering how often we reinvent the wheel in programming, I guess the variety of programming concepts is still orders of magnitude smaller than the number of implementations or pieces of code written.

Someone once wrote a demo compiler that outputs binary (for a library or function) together with a proof that the code won't do anything illegal (like reading random memory address). I suppose it cannot handle complex functions/libraries, but it's a start. And it's only a security thing, it doesn't prove the correctness of the results.

An alternative is to write in ever higher level programming languages which (through some inefficiency) guarantie safety from ever wider range of mistakes.

A Case for Formal Specification | 151 comments (142 topical, 9 editorial, 1 hidden)
View: Display: Sort:

kuro5hin.org

[XML]
All trademarks and copyrights on this page are owned by their respective companies. The Rest � 2000 - 2005 Kuro5hin.org Inc.
See our legalese page for copyright policies. Please also read our Privacy Policy.
Kuro5hin.org is powered by Free Software, including Apache, Perl, and Linux, The Scoop Engine that runs this site is freely available, under the terms of the GPL.
Need some help? Email help@kuro5hin.org.
If you can read this, you are sitting too close to your screen.

Powered by Scoop create account | help/FAQ | mission | links | search | IRC | YOU choose the stories! K5 Store by Jinx Hackwear Syndication Supported by NewsIsFree