Thu Aug 24 09:29:39 CEST 2000
On Wed, 23 Aug 2000, Alexander Williams wrote:
> On Wed, Aug 23, 2000 at 03:14:41PM +0100, Sean Hinde wrote:
> > Some of the comments came from a guy here who in a previous life spent 7
> > years writing SCPs in C. He is finding that he needs to be much more careful
> > about typos than he used to be. Old C model - hack it in let the compiler
> > find the typos, Erlang model - type it in very carefully and hope that in 6
> > months time your typo doesn't cause a breakage. He is feeling insecure about
> > some of his code compared to C (!)
Typing *is* useful but not a universal panacea. A type checker could
*prove* that the following factorial program was correct:
+type fac(int()) -> int().
fac(1) -> 17.
To get a "nice warm feeling inside" I'd also like to make a few spot
checks (i.e. compute fac(6) and check that I really do get 720)!
<<this is called testing :-)>>
As for being insecure in Erlang compared to C IHMO it's the other
In Erlang I write:
fac(0) -> 1;
fac(N) -> N * fac(N-1).
And then incremetally test.
 > erl
Erlang (BEAM) emulator version 4.9.1.b8 [source]
Eshell V4.9.1.b8 (abort with ^G)
- looking good. I'm getting a nice warm feeling inside :-)
(oh and there *is* no type proof of correctness - but I'm not worried)
- try again
Now I have to make an act of faith - do I believe this? -
Yes - the bignumber stuff was and is carefully tested.
Would I believe a C program that did the same thing? - no I'd have
to start worrying about the exact point when things overflowed etc. and
*that* is hard.
> 'm not sure I really understand his adopted mindset, though maybe
> that comes from having worked in dynamic languages extensively.
> Does he not do integrated testing as he goes? Crank up a temporary
> Erlang node and send in the module/application, then begin unit
> testing of the functions over various inputs. If he does it as he
> goes, actually testing interactively as he writes the source, perhaps
> he'll be MORE secure about his code, because its been tested a brick
> at a time.
> Programming in dynamic languages does require a change in operational
> development mindset; the compiler no longer catches some kinds of
> errors for you, but is better at catching/adapting to others. Using
> the same kind of write-compile-rewrite cycle doesn't make sense. (I
> end up having the interpreter running, and literally "testing as I
> go." Probably end up testing more things that could go wrong than
> even the type system would catch, really.)
Yes again. It's even nicer you get to run your program really early in the
I view programming as the gradual discoving of types. When the
development is over I then know the types. If I'd known them before
I'd started then the program would have "written itself".
Erlang is an vehicle that helps me discover the types.
Bluetail AB, tel: +46 8 692 22 11
Hantverkargatan 78, fax: +46 8 654 70 71
SE-112 38 Stockholm, Sweden info: www.bluetail.com
More information about the erlang-questions