Forgot your password?
typodupeerror
Programming Books Media Book Reviews IT Technology

High Integrity Software 238

Posted by timothy
from the tensegrity dept.
Jack Ganssle writes "High Integrity Software: the title alone got me interested in this book by John Barnes. Subtitled "The SPARK Approach to Safety and Security," the book is a description of the SPARK programming language's syntax and rationale. The very first page quotes C.A.R Hoare's famous and profound statement:'There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.' This meme has always rung true, and is one measure I use when looking at the quality of code. It's the basis of the SPARK philosophy." Read on for more of Ganssle's review of the book, and some more on the SPARK language.
High Integrity Software
author John Barnes
pages 448
publisher Addison-Wesley
rating 8
reviewer Jack Ganssle
ISBN 0321136160
summary The book describes a language that insures programs are inherently correct.

What is SPARK? It's a language, a subset of Ada that will run on any Ada compiler, with extensions that automated tools can analyze to prove the correctness of programs. As the author says in his Preface, "I would like my programs to work without spending ages debugging the wretched things." SPARK is designed to minimize debugging time (which averages 50% of a project's duration in most cases).

SPARK relies on Ada's idea of "programming by contract," which separates the ability to describe a software interface (the contract) from its implementation (the code). This permits each to be compiled and analyzed separately.

It specifically attempts to insure the program is correct as built, in contrast to modern Agile methods which stress cranking a lot of code fast and then making it work via testing. Though Agility is appealing in some areas, I believe that, especially for safety critical system, focus on careful design and implementation beats a code-centric view hands down.

SPARK mandates adding numerous instrumentation constructs to the code for the sake of analysis. An example from the book:

Procedure Add(X: In Integer);

--#global in out Total;

--#post Total=Total~ + X;

--#pre X > 0;

The procedure definition statement is pure Ada, but the following three statements SPARK-specific tags. The first tells the analysis tool that the only global used is Total, and that it's both an input and output variable. The next tag tells the tool how the procedure will use and modify Total. Finally a precondition is specified for the passed argument X.

Wow! Sounds like a TON of work! Not only do we have to write all of the normal code, we're also constructing an almost parallel pseudo-execution stream for the analysis tool. But isn't this what we do (much more crudely) when building unit tests? In effect we're putting the system specification into the code, in a clear manner that the tool can use to automatically check against the code. What a powerful and interesting idea!

And it's similar to some approaches we already use, like strong typing and function prototyping (though God knows C mandates nothing and encourages any level of software anarchy).

There's no dynamic memory usage in SPARK -- not that malloc() is inherently evil, but because use of those sorts of constructs can't be automatically analyzed. SPARK's philosophy is one of provable correctness. Again -- WOW!

SPARK isn't perfect, of course. It's possible for a code terrorist to cheat the language, defining, for instance, that all globals are used everywhere as in and out parameters. A good program of code inspections would serve as a valuable deterrent to lazy abuse. And it is very wordy; in some cases the excess of instrumentation seems to make the software less readable. Yet SPARK is still concise compared to, say, the specifications document. Where C allows a starkness that makes code incomprehensible, SPARK lies in a domain between absolute computerese and some level of embedded specification.

The book has some flaws: it assumes the reader knows Ada, or can at least stumble through the language. That's not a valid assumption any more. And I'd like to see real-life examples of SPARK's successes, though there's more info on that at www.sparkada.com.

I found myself making hundreds of comments and annotations in the book, underlining powerful points and turning down corners of pages I wanted to reread and think about more deeply.

A great deal of the book covers SPARK's syntax and the use of the automated analysis tools. If you're not planning to actually use the language, your eyes may glaze over in these chapters. But Part 1 of the tome, the first 80 pages which describes the philosophy and fundamentals of the language and the tools, is breathtaking. I'd love to see Mr. Barnes publish just this section as a manifesto of sorts, a document for advocates of great software to rally around. For I fear the real issue facing software development today is a focus on code ueber alles, versus creating provably correct code from the outset.


You can purchase High Integrity Software from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, carefully read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

High Integrity Software

Comments Filter:
  • hmmm (Score:5, Funny)

    by Anonymous Coward on Wednesday May 19, 2004 @03:02PM (#9197478)
    The very first page quotes C.A.R Hoare's famous and profound statement

    Not to be confused with C.A.M. Hoare's famous and profound statement: "Want to see my boobies?"
  • question (Score:5, Insightful)

    by Anonymous Coward on Wednesday May 19, 2004 @03:04PM (#9197491)
    Do these authors actually employ the mentioned practices with any success on a daily basis?

    Or do they sit around thinking of methodologies to write books about?

    Those who can, do, those who can't, teach?

    • Re:question (Score:4, Insightful)

      by DrEldarion (114072) on Wednesday May 19, 2004 @03:28PM (#9197676)
      Those who can, do, those who can't, teach?

      Those who can't teach, teach theory.
    • Re:question (Score:5, Informative)

      by deepchasm (522082) on Wednesday May 19, 2004 @03:35PM (#9197732)
      Yes, they do.

      SPARK Ada came from Praxis Critical Systems. (http://www.praxis-cs.co.uk/). Go take a look. You can read about how SPARK Ada is used in things like aircraft, and (increasingly) in the automotive industry.
    • ...who endlessly pitch, "Come to my free seminar and my methods well make you a millionaire!" Well, you'd think that if the methods were so flawless, they'd have a lot better things to do with their time than standing in front of an audience blabbing about it.
    • Re:question (Score:2, Funny)

      by Anonymous Coward
      | Do these authors actually employ the mentioned practices with any success on a daily basis?

      Yes. And I regularly see job adverts specifying SPARK.
    • Re:question (Score:2, Interesting)

      by AdaDaddy (632047)
      Actually, yes.
      These people have successfully used SPARK on many projects. They also provide the tools making the SPARK approach feasible.

      The SPARK approach causes discomfort for many software developers because its approach diverges from that of the various agile development processes.

      If you read the book you will discover that the author's claims are supported by real data from real projects.

      The SPARK approach is extremely formal. It has frequently been used on the safety critical portions of larger sys
  • A _review_? (Score:5, Insightful)

    by Caine (784) on Wednesday May 19, 2004 @03:06PM (#9197499)
    Seriously, I'm not one to complain, but this isn't a review; it's a guy saying "WOW" repeatedly.
  • heheh (Score:4, Funny)

    by grub (11606) <slashdot@grub.net> on Wednesday May 19, 2004 @03:06PM (#9197501) Homepage Journal

    "High Integrity Software"

    SCO should adopt that as their motto. :)
  • But what.. (Score:4, Insightful)

    by Anonymous Coward on Wednesday May 19, 2004 @03:06PM (#9197506)
    ..if the contract itself is wrong?
    • Re:But what.. (Score:3, Insightful)

      by happyfrogcow (708359)
      that's not the implementors primary concern, really. but if you have a design to begin with, atleast you can backtrack and see why the contract is wrong. change it, and implement the right contract.

    • Re:But what.. (Score:5, Insightful)

      by AlecC (512609) <aleccawley@gmail.com> on Wednesday May 19, 2004 @03:33PM (#9197718)
      I agree that this is actually the problem. As I understand it, the high-reliability people have more-or-less solved the problem of enduring the code follows the specification (though at a cost that woul deter for less critical applications). But all this does is push the problem one level higher.

      In the early days of compilers, one of the claims for compilers was that they would make mistakes impossible. Of course, all they did was make one class of stupid assembler mistakes impossible.

      The reason for the verbosity of COBOL is the idea that it would be so like business English that management could read it, if not write it.

      Eash time we get a tool that removes one class of mistakes, all we do is increase the systen m complexity until the level of mistakes returns to the previous level of near-unacceptability. "Snafu" is the normal state of the programmers universe - it is only a case of how large a system you build before it all fouls up.

      Having said that, Design By Contract is a good idea. While accepting that it is always going to turn to ratshit, you might as well do so at a higher level as a lower one. However, it isn't new: look at Eiffel and Aspect Java for instance.
      • Re:But what.. (Score:5, Insightful)

        by bcrowell (177657) on Wednesday May 19, 2004 @03:45PM (#9197807) Homepage
        As I understand it, the high-reliability people have more-or-less solved the problem of enduring the code follows the specification (though at a cost that woul deter for less critical applications).
        Yeah, the article's statement, "The book describes a language that insures programs are inherently correct," is really misleading. Very few real-world programs have ever been proved correct, and the reasons for that are language-independent. Very few real-world problems even lend themselves to a precise mathematical statement of what "correct" would mean. What would it mean for mozilla to be "correct?" Even if your code is running a nuclear reactor, the code can only be as "correct" as the accuracy of the assumptions and engineering data that went into the spec.

        In many real-life projects, the nastiest bugs come from requirements that change after the first version has already been written. Proving that a program correctly implements a spec doesn't help if the spec changes.

    • Re:But what.. (Score:3, Insightful)

      by Waffle Iron (339739)
      ..if the contract itself is wrong?

      That's the beauty of this system. You can close out the issue in your bug tracking database anyway:

      "CLOSED: Not a bug; behavior as designed."

    • Re:But what.. (Score:3, Informative)

      by Mikkeles (698461)
      SPARK only covers programme verification. There are other formal methods which cover specification (e.g. Z) as well as various theorem provers which can link all these parts together to ensure no contradictions, etc.

      A search on Google for formal methods [google.com] will give you a lot of stuff. The first site [ox.ac.uk] that comes up is a good starting point.

      Note that at some point, one has to hope that what the client wants is what he has described. A tax calculation programme will not be of use if he really wanted a custom

    • Re:But what.. (Score:4, Informative)

      by Beryllium Sphere(tm) (193358) on Wednesday May 19, 2004 @07:23PM (#9200124) Homepage Journal
      >.if the contract itself is wrong?

      In real life that's what usually kills people.

      _Safeware_ by Nancy Leveson looked at several software-related disasters. Only one disaster, the Therac radiation machine that fried several patients, was the result of actual bugs (and those bugs were race conditions). The rest consisted of software obediently and disastrously doing exactly what it was supposed to do, like the black lab at #7 in http://www.dorsai.org/~walts/darwin.html.

      If you build safety-critical software be sure to have some organized way to flush out what-if questions and hidden assumptions.
  • Car Whores? (Score:2, Funny)

    by SirChris (676927)
    I thought car whores are the girl who pose for all the car magazines. Or the ones that sleep with the guy with the coolest car.
  • by Anonymous Coward
    Ok, I know nothing about SPARK, so forgive my ignorance. Why is the "contract" paradigm different from standard object oriented languages with public class interfaces?
    • by happyfrogcow (708359) on Wednesday May 19, 2004 @03:39PM (#9197769)
      Ok, I know nothing about SPARK, so forgive my ignorance.

      me neither, me too...

      my understanding is that the contract has hard requirements on specific input and specific output for results. all of which are defined prior to executing that code. something like "we require an incomming integer with a value that is between zero and fifteen. we gaurantee that an integer value will be returned that is either zero or one"

      with a public class interface you can write a peice of code that does this, but it won't gaurantee anything. it's up to the developer to exhaustively test all situations and make sure that it happens. in a contract based language, i would guess that the program either won't compile, won't run, or will fail in obvious ways in the development stage if the requirements are not met. i'm not sure how they handle requirements that aren't met.
    • by William Tanksley (1752) on Wednesday May 19, 2004 @03:54PM (#9197881)
      Design By Contract was not invented by SPARK; the name was popularised by Bertrand Meyer, who added it to his "Eiffel" language.

      Anyhow, DBC is totally distinct from object orientation. In DBC, each component in your software comes with a "contract" that states "if I am called when the _preconditions_ are true, I promise that after I run the _postconditions_ will be true."

      The preconditions and postconditions are a group of logical statements, hopefully ones which are useful to your program :-).

      Let me give a little example.

      function: sqrt( x )
      preconditions:
      - integer (x)
      - positive (x)
      postconditions:
      - result > 0
      - result * result x

      Do you see what's happening there? Without knowing /anything/ about how sqrt is computed, you can use it in powerful ways. Preconditions and postconditions can't always be as informative as the ones above are (the ones above define everything about the integer sqrt function), but they can give useful information.

      Adding in object orientation support to DBC is a little more complex, but I won't go into that unless asked.

      Traditional DBC systems, including Eiffel, couldn't verify your contracts, so most of them would translate the contracts into code, and include that code in the executable; if a contract failed, the code would throw an exception or otherwise fail. SPARK is interesting because it can detect contract failures without running the code; it can also detect when your contracts fail to promise enough.

      -Billy
      • Ugh. HTML zapped my pre and post conditions. Here they are...
        function: sqrt( x )
        preconditions:
        - integer (x)
        - positive (x)
        postconditions:
        - result > 0
        - result * result <= x
        - (result+1) * (result+1) > x
        -Billy
      • And how, exactly, does a static compiler prove that a certain code sequence correctly computes a square root?
        • by Suslik (59646) on Wednesday May 19, 2004 @05:31PM (#9199078) Homepage
          To prove the correctness of an (Integer) square root routine you would specify something like:

          procedure Sqrt(X : in Integer; Y : out Integer)
          --# derives Y from X;
          --# pre X >= 0;
          --# post (Y*Y <= X) and ((Y+1)*(Y+1) > X);

          i.e. Y, your sqrt, is no more than X when squared, but increase it by 1 and it is more than X. You require X to be non-negative.

          Assuming that your implementation implements an initial guess at Y and then repeatedly increments it, you would specify a loop invariant that shows that your guess at Y (say 'Z') is such that (Z+1)*(Z+1) For more information on what's practicable in a customer-specified system, read the peer-reviewed publications...

          Disclaimer: SPARK hacker for 6 years

      • I'm not so sure about Eiffel. In Eiffel, you can declare class invariants, which are contracts that must apply to your class and all inherited classes. Sounds like it includes OOPL contracts to me. Eiffel also has loop invarints.

        Anyway, I see nothing new in DBC in SPARK not already in Eiffel.
        • Er... Read my message again. I wasn't knocking Eiffel; on the contrary, I was giving Bertrand credit for having DBC nailed before SPARK came along.

          I also wasn't talking about Eiffel's support for DBC; I was describing DBC in general, or more accurately DBC without OO support. I didn't claim that OO isn't possible with DBC (on the contrary, I stated that it was, and I would explain it if asked). I didn't claim that Eiffel didn't have OO.

          And finally, the huge thing that's new in SPARK that isn't in Eiffel i
      • The problem with contract programming is that most people are incredibly bad at describing preconditions and postconditions. They either over specify or worse leave something out; the result is that the contract is invalid.

        The code gets written and it turns out to have bugs anyway. We go back to examine everything and notice missing details in the contracts. We fix those problems, the code gets re-written and the cycle continues. In the end we've not achieved much in the way of program correctness, efficie
        • Your point that "correctness isn't always necessary" is well taken. The more you need the more you have to pay, and not every project can afford the price.

          The rest of your post absolutely requires the absence of a tool like SPARK. Throw SPARK into the mix, and all your grounding assumptions are absolutely wrong -- the specifications _do_ describe the interfaces, and the interfaces _do_ work together, and the code _does_ implement the specifications, and there are no possible exceptions.

          Trivial examples a
    • You don't really mean public class interfaces (per se), you mean function prototypes, which are available in C (for example). The difference is really that you can specify arbitrary information about what the function is supposed to do, rather than just a few particular things. E.g., the usual API for mod is something like

      int mod(int num, int den)

      This lets you add

      den != 0

      (den = 0)

      Then the compiler could automatically write the check for division by 0, and could optimize it out in cases when it can stat
  • What horseshit (Score:4, Insightful)

    by Anonymous Coward on Wednesday May 19, 2004 @03:09PM (#9197522)
    The book describes a language that insures programs are inherently correct.

    Now, is there a language to ensure that your boss asks you to program the right thing?

  • by SamiousHaze (212418) on Wednesday May 19, 2004 @03:11PM (#9197546)
    In General, if you want info, RTFA. However for those of you who just want some links to check things out quickly:

    Here [praxis-cs.co.uk]is a PDF that contains samble chapters of the book reviewed.

    Also from the same site is the following text and links for those of you wanting "real world examples":

    "Industrial Experience with SPARK [praxis-cs.co.uk] (PDF 234kb) Dr. Roderick Chapman, Praxis Critical Systems Limted. Presented at ACM SigAda 2000 conference. This paper discusses three large, real-world projects (C130J, SHOLIS and the MULTOS CA) where SPARK has made a contribution to meeting stringent software engineering standards. "
  • by tcopeland (32225) * <{moc.dnalepoceelsamoht} {ta} {mot}> on Wednesday May 19, 2004 @03:12PM (#9197552) Homepage
    Cue Hitchhiker's Guide on the Sirius Cybernetics Corporation:
    In other words - and this is the rock solid principle on which the whole of the Corporation's Galaxy-wide success is founded - their fundamental design flaws are completely hidden by their superficial design flaws.
  • by tcopeland (32225) * <{moc.dnalepoceelsamoht} {ta} {mot}> on Wednesday May 19, 2004 @03:20PM (#9197612) Homepage
    modern Agile methods which stress cranking a lot of code fast and then making it work via testing.
    No, instead, they stress writing a test, then writing code to make the test pass. Big difference there.
  • Eurofighter (Score:5, Informative)

    by Anonymous Coward on Wednesday May 19, 2004 @03:21PM (#9197617)

    SPARK is used heavily in the safety critical software in the Eurofighter amongst other projects. It is a complete pain to type all of the annotation, takes forever to run the tool and it very rarely comes up with any real problems in the code. I would pay good money never to have to go near it again. It was used to meet contractual requirements, not engineering requirements.

    One neat trick is to generate a large proportion of the annotation from the output error messages. Sort of defeats using the tool though but since it doesn't find much anyway the time freed up can be used to do some real testing.

    • Re:Eurofighter (Score:4, Interesting)

      by tcopeland (32225) * <{moc.dnalepoceelsamoht} {ta} {mot}> on Wednesday May 19, 2004 @03:38PM (#9197761) Homepage
      > It was used to meet contractual
      > requirements, not engineering requirements.

      There be dragons.

      > One neat trick is to generate a large
      > proportion of the annotation from the
      > output error messages

      That's classic. It makes sense, though - kind of like running a code reformatter rather than running a "code format checker". Every night, the code gets reformatted to meet the style guide... no nagging emails, just silent enforcement.
    • Re:Eurofighter (Score:2, Interesting)

      by Anonymous Coward
      The people who wrote the contract might have a different opinion. It seems to me I could claim cutting corners on the kind of cement wasn't important and just a contractual obligation not a design consideration. Are you saying that you can get the exact same kind of fault tolerance as a correctly used spark affords, and have the same level of confidence?
      • It's just that the contracts don't add much value, compared to what they cost.

        In order to really ensure that the code does the right thing, the contract has to be about as detailed as the code itself. This means that you end up writing the same thing twice, with possibilities for errors in both copies.

        If you relax the contract to only partially describe what needs to happen, you create opportunities for bugs to go undetected, and lose the certainty the contracts were meant to provide.
        • Re:Eurofighter (Score:2, Interesting)

          by Theodrake (90052)
          The real nightmare comes when the specification changes. So instead of just changing your code. You have to also change this psuedo code, oops contract. Plus I'm guessing you still have end-to-end tests, all of which get rewritten. All this may eliminate are the unit tests, which for me were the easiest to code and in many cases a visual inspection would do. Now you have to maintain this contract and your code. Seems like more trouble then it is worth.
    • Re:Eurofighter (Score:5, Insightful)

      by SheldonYoung (25077) on Wednesday May 19, 2004 @04:07PM (#9198062)
      SPARK is used heavily in the safety critical software in the Eurofighter amongst other projects. It is a complete pain to type all of the annotation, takes forever to run the tool and it very rarely comes up with any real problems in the code.

      This type of unprofessional crap is the reason people have such low expectations of software. You didn't want to use the tool because it was a "pain to type"?! If the length of time it takes you to type your code is a bottleneck then you're not doing enough thinking before you type. The extar effort requierd to type more verbose code is close to zero. You're coming across like an aeronatical engineer would if they tightened a critical bolt to only 90% of the required torque because it was less effort.

      By saying very rarely comes up with any real problems" means it found some, and those problems may have been easily been overlooked by other types of testing. And what are problems wouldn't be "real" in saefty critical code?! Yes, there are other tools besides SPARK that could have been used but the principles should have been the same.

      Don't ever forget you're talking about a serious piece of hardware and there's a human being sitting in the pointy end. If I was a pilot of something that had a bug in it's safety critical software because of your lack of pride I would kick your ass.
      • Re:Eurofighter (Score:2, Interesting)

        by daksis (163887)
        This type of unprofessional crap is the reason people have such low expectations of software.

        I think people have such low expectations of software because for the most part, software doesn't meet their expectations, and the expectations people have of software are often unrealistic. Software is like everything else - built with the trade off of cost versus utility.

      • You didn't want to use the tool because it was a "pain to type"?!

        Boilerplate code, near cut-and-paste code, and highly verbose code produce greater errors, and induce programmer fatigue.

        In addition, they make the code harder to understand at first glance.

        That's quite important. Much is made of how unreadable Perl can be, but sitting down and trying to figure out the logic and nuances behind a bit of C code is often much, much worse. This is because the C is usually more verbose to do the same thing.

  • Great, just program in a really wordy subset of Ada, with NO dynamic memory allocation, and your program will be provably... ugly.

    Why not use a language that's smart enough to prove code written in a useful language, not just a toy?

  • by dioscaido (541037) on Wednesday May 19, 2004 @03:26PM (#9197656)
    I would have been interested if all this instrumentation had been grafted onto a language like Java, or C++. But to have to switch to Ada just to be able to add in instrumentation that helps in code analysis? It's also funny that he WOW's at the idea of no dynamic memory allocation... Why not just use a type safe language?
    • Re:Ok... (Score:4, Informative)

      by William Tanksley (1752) on Wednesday May 19, 2004 @04:06PM (#9198037)
      Two statements there.

      I would have been interested if all this instrumentation had been grafted onto a language like Java, or C++. But to have to switch to Ada just to be able to add in instrumentation that helps in code analysis?

      Switching languages is a tiny effort compared to the change required to design your code for static validation. The SPARK people strongly recommend against trying to "switch" to SPARK; if you want the benefits, you have to code with it from the start. It's kind of like taking a 100,000 line C program written by 30 programmers over 10 years and trying to "switch" it to C++ -- it's theoretically possible, but in practice it's easier to start over.

      And what they did in Ada would have been impossible in C++. It's significant that SPARK code will run EXACTLY the same on all compliant Ada compilers. No platform dependancies, no ambiguities, no undefined behavior... ALWAYS the same. You simply can't possibly define a subset of C++ which would be able to make those promises. I don't know if it would be possible with Java; since there's no formal specification of Java, probably not.

      It's also funny that he WOW's at the idea of no dynamic memory allocation...

      I felt that way too :-). Odd.

      The reason they did it is simple, though -- they wanted to be able to set absolute bounds on when a SPARK program will or will not fail (throw an exception). There's no way to do that with dynamic memory allocation as it's defined in Ada and most other languages.

      Yes, that's limiting; no argument. But for some problems, particularly ones solvable by programs managing their own memory, the limitation doesn't matter compared to the benefits -- a SPARK program can execute without any runtime support code.

      Why not just use a type safe language?

      No such thing -- type safety is an uncomputable problem.

      If you meant strongly typed, that's easy; Ada was already strongly typed. SPARK just guerantees that the programs will always run the same, and SPARK's verifier guarantees that the types are chosen and described correctly.

      -Billy
      • Re:Ok... (Score:3, Insightful)

        by wintermute42 (710554)

        And what they did in Ada would have been impossible in C++. It's significant that SPARK code will run EXACTLY the same on all compliant Ada compilers. No platform dependancies, no ambiguities, no undefined behavior... ALWAYS the same. You simply can't possibly define a subset of C++ which would be able to make those promises. I don't know if it would be possible with Java; since there's no formal specification of Java, probably not.

        I'm not sure what you meant by formal specification here. As I recal

        • So that fact that Ada had DoD funding for a denotational semantic specification and Java does not does have such a specification does not make Ada more portable and reliable (in the sense that a piece of code will produce the same result on different platforms).

          You're right that the phrase "formal specification" was a bad choice on my part. Ada doesn't have an official formal specification (although SPARK does); what Ada has is a highly formal official specification, automatically verified by an extensive
  • This sounds a bit like Alloy [mit.edu]. Alloy is both a code modelling language (like UML), but structured in such a way that the model can be analysed automatically using SAT solvers (yeah, I didn't know what those were at first either. Here's a site [princeton.edu] with some good info on them).

    Alloy's cool because you can use it to model code at a very abstract, high level (much like SPARK, it seems), although with Alloy you aren't tied to any specific language. The downside is that since the model isn't embedded in the code
    • It also sounds exactly like Eiffel.

      This industried ability to continually re-invent the wheel never ceases to amaze me.

      Let's go back to lisp and smalltalk every frikken language since then is just a rewrite of one or the other anyway.
      • It's actually quite different. Eiffel lets you embed contracts in your code which are (optionally) checked at run-time. Even with contracts, your program can pass all its tests and still have hidden bugs.

        Alloy lets you model a system (Alloy code isn't executable), and statically prove properties about the model. Once you verify the model, you prove that it's correct for all possible runs (but you still have to implement it correctly).
  • by RAMMS+EIN (578166) on Wednesday May 19, 2004 @03:30PM (#9197687) Homepage Journal

    SPARK mandates adding numerous instrumentation constructs to the code for the sake of analysis. An example from the book:

    Procedure Add(X: In Integer);

    --#global in out Total;

    --#post Total=Total~ + X;

    --#pre X > 0;


    This seems rather a waste of time. You either first describe exactly what the code does, then write the code, or you write a simplification of what the code does, then the code.

    In the first case, you write the exact same thing twice, in different languages. That sounds like an immense waste of time to me.

    In the second case, your specification does not cover every aspect, which introduces loopholes, defeating the purpose of the contract.

    In either case, you get in trouble if there are errors in the contract.
    • This is a very simple case, and so it is not surprising that the contract and the code look similar. The proof of the pudding is whether this works for non-trivial specifications and algorithms.

      For example, will this work with your favorite sorting algorithm? Presumably all sorting algorithms for sets drawn from a given domain will have the same pre and post conditions, but very different algorithms.

    • by Flamerule (467257) on Wednesday May 19, 2004 @04:10PM (#9198088)
      SPARK mandates adding numerous instrumentation constructs to the code for the sake of analysis.
      This seems rather a waste of time. You either first describe exactly what the code does, then write the code, or you write a simplification of what the code does, then the code.
      I'm not an expert on any of this stuff, but allow me to point out the misunderstanding I think you're operating under. Programming by contract isn't concerned with what the code does inside a function, per se. It simply tries to ensure that a function adheres to its contract conditions on expected input/output. Pre/post conditions... you know. So a function, on beginning execution, can expect the program state it is given to obey the precondition properties. In turn, on ending execution, the function must leave the program state as specified by the postcondition.
      In the first case, you write the exact same thing twice, in different languages. That sounds like an immense waste of time to me.
      No, you don't specify everything the code does.
      In the second case, your specification does not cover every aspect, which introduces loopholes, defeating the purpose of the contract.
      As I said, the contract isn't a "simplification" of the code. But anyway, you're kind of saying here that this technique doesn't totally prevent all mistakes, so it's worthless. Harsh.
      In either case, you get in trouble if there are errors in the contract.
      Clearly. I think it's useful to explicitly detail the contract, however. It forces you to think about something you might not have considered otherwise.
      • ``Programming by contract isn't concerned with what the code does inside a function, per se. It simply tries to ensure that a function adheres to its contract conditions on expected input/output.''

        And that's exactly where the loopholes are. In functional programming, all there is to a function is what goes in and what comes out. However, I SPARK being a subset of ADA, I think we can safely assume there will be lots of side effects, and reliance on side effects. This makes specifying only pre- and postcondi
    • by William Tanksley (1752) on Wednesday May 19, 2004 @04:13PM (#9198129)
      This seems rather a waste of time. You either first describe exactly what the code does, then write the code, or you write a simplification of what the code does, then the code.

      It's not a waste of time to describe what a function does. It's essential to keep "what" a function does distinct from "how" it does it. That's the whole point of interface versus implementation.

      Consider a function with the following contract:
      function: sqrt( x )
      preconditions:
      - integer (x)
      - positive (x)
      postconditions:
      - result > 0
      - result * result <= x
      - (result+1) * (result+1) > x
      Now, can you see how that's useful? And do you see that this tells you something _completely_ different than what you'd know if you read the actual source code for that function (perhaps an implementation of Newton's method)?

      In the second case, your specification does not cover every aspect, which introduces loopholes, defeating the purpose of the contract.

      That's what SPARK's automatic verifier is for -- to prove that there are no loopholes.

      -Billy
    • "In the first case, you write the exact same thing twice, in different languages. That sounds like an immense waste of time to me."

      That's like saying disk mirroring and ECC is a waste of time.

      The value of writing things twice or thrice is when it turns out it's not the same thing after all. Then you know you have a problem (whether you can fix it there and then is a different problem ;) ).

      If it's significantly easier to write one of the "checks" that'll be rather useful.
  • by Animats (122034) on Wednesday May 19, 2004 @03:35PM (#9197735) Homepage
    We did this twenty years ago, for a dialect of Pascal. See Practical Program Verification [acm.org]. Back then, you could do it, but it was rather slow. Today, with machines thousands of times faster than the VAX 11/780 we used back then, it's much more feasible. But you need a language suitable for verification. C and C++ are hopeless - the semantics of the language are ambiguous. (Casts, pointer arithmetic, and "void *", make the typing system unreliable.) The Pascal/Modula/Ada family are suitable, with modifications and limitations. Eiffel and Sather do well, but few use them. Java, though, is both verifiable and widely used.

    The best available modern system for formal verification is the Extended Static Checking system for Java [hp.com] developed at DEC SRL. This was developed at DEC before HP shut down that research operation. It's still available as a free download [compaq.com].

    What all this machinery does is put teeth into "design by contract". With systems like this, you can tell if a function implements its contract, and you can tell if a caller complies with the contract of each thing they call. Before running the program.

    Developing in this mode means spending forever getting rid of the static analysis errors. Then, the program usually just runs. That's exactly what you want for embedded systems. But it's painful for low-grade programming like web site development, where "cosmetic errors" are tolerable and time-to-market matters more than correctness.

  • Sounds like Resolve (Score:3, Interesting)

    by etcshadow (579275) on Wednesday May 19, 2004 @03:40PM (#9197774)
    This sounds very much like (looks very much like, as well) a project that some of my professors were working on a few years back at Ohio State University, called Resolve C++. I also recall that they were working with another university (can't remember which... maybe U Penn?) on Resolve Ada.

    The basic idea was that they added a whole ton of syntactic sugar to C++ (not by structured comments, but by adding a bunch of key words that were #defined into nothing). I'm curious if this is related to that work at all. (At the time I was convinced that it was total crap, but several years of experience have shown me what they were trying to accomplish, if poorly.)
  • Whatever the test application is doing to run those tests, why not just convert its output to an EXE/binary and use THAT as the program? Then you only have to write the tests to get both the test and the code that passes the test! That's copyright me, today, by the way.
    • > you only have to write the tests
      > to get both the test and the code that
      > passes the test!

      This came up on the Extreme Programming list a while back. I think the Java IDE IDEA [jetbrains.com] does something like this, in that you can write a test and it'll generate the source code for the method signatures that you're trying to test. Then you fill in the implementation. *Disclaimer - I haven't used that feature so I don't know how well it works*

      One problem with this, though, is that code can pass a test but s
  • by bigberk (547360) <bigberk@users.pc9.org> on Wednesday May 19, 2004 @03:45PM (#9197804)
    Crappy software is all around us (obviously). It may not seem like a huge tragedy that, say, Microsoft Windows has so many security problems but the unfortunate reality is that the entire Western Economy heavily relies upon software that is so fragile that fresh installations become compromised within minutes.

    Since so much of what we depend on these days is powered by software, I can't help but feel that industrial software development should be taken under the wing of Engineering. Why, you say? Well, professional fields like medicine, law, and engineering associate a duty to public safety with the job, and the regulatory bodies for the professions ensure that individuals who practice irresponsibly will lose their profesional status.

    There is no such accountability for software development. Look at Microsoft Windows, that our banks and governments rely upon! I think such a product would be much higher quality if the coders working on it were professionals and had to adhere to Codes; violating their professional duties would mean severe personal consequences. And the firm itself (Microsoft) would be legally liable if it produced a shoddy, dangerous product!
    • First off, Windows is the ONLY software that's used both in commercial, industrial, specialized applications, AND on Timmy's computer in his bedroom. Of course it's going to be attacked more than say, a program that runs a CNC machine. I'm betting that many more specialized programs are even MORE vulnerable, but they're not exposed to anywhere near the abuse that Windows is. (ie: I've never heard of anybody hacking or even attemting to hack an elevator's software).

      Secondly, we have the entire legal syst
      • Lot of good suing the software vendor does you when you're dead. Also you may not have been the person who purchased and there is no guarantee that the purchaser knew what they were buying.

        UNIX:
        runs databases (commercial)
        runs manufacturing equipment (industrial)
        runs handheld portable units (specialized) and I've seen it used on a SPRC box as a controller for BAS (big ass switches)
        and it is currently easy to get a copy of Linux, BSD or Solaris running in your bedroom.

        Your arguments do not hold water.
    • Ever notice how the services performed by such "professionals" as lawyers tend to cost a small fortune? People want their software to stay cheap...witness the whole outsourcing debacle - this is never going to fly.
      • Maybe the increased cost is worth it? If industry loses billions of dollars a day due to spam (which is carried through insecured Windows hosts) and associated viruses, worms, and intrusions, then aren't you paying for the cheap software in another way?
    • Engineers are a profession. They get paid like one, have legally protections and responsibilities, and are pretty picky about who they let in. Stuff developed with proper engineering method costs $$$. So, if we put software in this category, your web browser would cost $900, it would be updated once every year for another $400, and it might or might not interoperate with any other software. If the engineers (following proper engineering method and using design-for-testability or design-by-contract or inhe

  • Procedure Add(X: In Integer);

    --#global in out Total;

    --#post Total=Total~ + X;

    --#pre X > 0;


    1. Global vars: BAD.

    2. Borland Delphi has had some of this for while with the assert [about.com] function.

    It's basicly a way of making sure that all the things that can't go wrong, actually doesn't.
    • Assert also exists in VC++, and Java, and can be quite useful.

      I believe the instrumentation shown in the article is intended to be read in by an analysis tool, which should, in theory, find errors/inefficiencies that you as a programmer may not have noticed, and hence wouldn't have represented within asserts. But, as has been mentioned before in another comment, such errors are rare enough to not justify having to migrate to Ada and write so much extra instrumentation.

  • using ada is enough (Score:5, Interesting)

    by acomj (20611) on Wednesday May 19, 2004 @03:59PM (#9197946) Homepage
    I've been using ada for a little while now. Its actually a good language, with many features that provided self checking code. SPARK seems a bit excessive.

    For example ada already had constrained types (x :integer range 0..15) . If x goes above 15 or under 0 during runtime you get a constraint error.

    The ada compiler checks alot of things during compile time that I've never seen before.
  • Ummmmm... (Score:4, Interesting)

    by randombit (87792) on Wednesday May 19, 2004 @04:00PM (#9197958) Homepage
    One thing I note that the review does not mention is the fact that SPARK is, while Turing-complete, not very much fun to program in. Starting with Ada, a pretty B&D langauge to start with, SPARK removes all the remaining pointy bits, including: "the goto statement, aliasing, default parameters for subprograms (i.e. procedures and functions), side-effects in functions, recursion, tasks, user-defined exceptions, exception handlers and generics" (list taken from here [praxis-cs.co.uk], emphasis mine), plus dynamic allocation, which is mentioned in the review.

    Basically the only excuse you could possibly have for writing something in SPARK is extremely critical code (ie, if it fails, many people die). Even then I'd be skeptical it would provide much benefit, but at least it would provide some ass-covering ability. :)

    For a alternatve view of the practicality of correctness proofs, see chapter 4 [cypherpunks.to] of Peter Guttman's thesis. IIRC there was a book review of it on /. a while back (which I didn't read). Even if you did read it, read it again.

    "No programming language can save you from yourself."
    - Me
  • Newspeak (Score:2, Interesting)

    "Many computer scientists have fallen into the trap of trying to define languages like George Orwell's Newspeak, in which it is impossible to think bad thoughts. What they end up doing is killing the creativity of programming." --Larry Wall

    SPARK seems to be an extreme example. Though I've never used it, I venture to guess that in a quixotic effort to avoid all bugs SPARK only buries real bugs underneath a mountain of its own pedantry.
  • People interested in this should also check out Eiffel [eiffel.com] and Sather [berkeley.edu] as well.
  • by spun (1352) <loverevolutionary@nOSPAM.yahoo.com> on Wednesday May 19, 2004 @04:16PM (#9198179) Journal
    My last software project ran off with my wife, stole all my money, and crashed my new corvette. Damn! I really could have used this, instead I hired a bunch of Klingon programmers.
  • First thought I had here was another quote, probably saw it before somewhere on /.:
    "The true measure of a good coder is not how complex his code is, but how simple."

    Today's software systems become bigger, bigger, and bigger. Maybe single components are simplified, debugged or optimised, but not a system as a hole. The results we see today, in many systems, a single slip in one place, can screw up the entire system.

    IMHO the logical way to combat this, would be to design software using methods that can

    • Having (briefly) done some research in program verification, I'd have to disagree with you.
      Proving non-trivial programs correct is nearly always intractable, if not strictly speaking impossible. We simply don't have the computing power to do it for larger programs, and (IMO) we probably never will.
      • To expand on the point made above...

        Let us assume that we have a magic proof system that will prove that our software matches our specification.

        So what do we use to define the specification? Certainly not a natural language like english. Natural languages are full of ambiguity. So we'll use a formal specification language. However, such a language is basicly like a programming language, perhaps supporting more mathematical formalism (maybe single assignment). While our formal proof system can prove

  • Homeland Security (Score:2, Insightful)

    by yermoungder (602567)
    WRT: SPARK check out this report: http://www.cyberpartnership.org/SDLCFULL.pdf The report's task force was co-chaired by Microsoft and Computer Associates people and is being submitted to the DHS. It explicitly recommends SPARK as one method of increasing reliability/security. It also states "A programming language with significantly fewer possibilities for mistakes than C or C++ should be used where possible."
  • by KurtP (64223) on Wednesday May 19, 2004 @05:33PM (#9199097)
    "Beware of bugs in the above code. I have only proven it correct, not tested it."

  • Agile methods (Score:3, Insightful)

    by JacobO (41895) on Wednesday May 19, 2004 @07:54PM (#9200322)
    in contrast to modern Agile methods which stress cranking a lot of code fast and then making it work via testing

    I have to disagree here, the agile methodologies I'm aware of stress automated unit testing to ensure the code that follows meets the specifications. They are agile because the "contract" enforced by the unit tests allow you to see what you have broken easily after a change. If your unit tests pass then you've either not broken anything or your test coverage is insufficient. It seems that these SPARK "tags" have some of the benefits and all the problems that a good suite of automated unit tests provides.

    I do however like the idea that your assumptions and dependencies are explicitly mentioned nearby where they occur. These are things that definitely sting you, especially in code you are new to (written by someone else.) All the little interdependencies and unexpected side-effects that make their way into code can really make life difficult sometimes.

    I have a feeling though that this would take discipline, and if all team members were skilled and disciplined then you would likely have much of these things stated anyway.
  • Oracle's proprietary extension to SQL, PL/SQL, is based on Ada. Its "package" concept borrows the contract/implementation dichotomy. First the public interfaces to the package are declared in the PACKAGE object; then the implementation is defined in the matching PACKAGE BODY.

    This enables procedures to be public in scope (present in both PACKAGE and PACKAGE BODY) or private in scope (present in PACKAGE BODY only). Other elements, such as user-defined data types, constants and cursor definitions, can be part
  • We are now poised to move forward with type inference based on full blown inference engines, thereby dispensing with the nonterminating arguments over statically vs dynamically typed languages that allowed Steve Jobs's spawn such as Object-Pascal/Objective-C/Java to get its nose in the tent. If you want to declare a "type" in a declarative language, just make another declaration and let the inference engine figure out what it can do with that information prior to run time. See how easy that was? Well, there

If bankers can count, how come they have eight windows and only four tellers?

Working...