bug in inets or erlang!

Joe Armstrong (AL/EAB) <>
Wed Nov 30 14:25:45 CET 2005


This is very confusing - I didn't bother to read this post
because of the heading " bug in .. " - I thought that means that somebody is 
reporting a bug. But no.

What follows is not a discussion of a bug but of a possible design error.

I have seen various postings using the words "bug" and "crash"
which gives the impression that something is wrong.

This is the wrong terminology.

Well designed functions either return values or raise exceptions.

A function contains a bug if it returns an incorrect value, or returns a value when it should
raise an exception or raises an exception when it should return a value.

The documentation of universaltime_to_localtime clearly states:

	Failure: badarg if Date or time do not denote a valid date or time

and this precisely what happens - you cannot do meaningful calculations
on dates before the start of the epoch concerned and so the time conversion
routines should raise exceptions.

Now arguably, the function that calls the timer routine might be buggy
since it should possibly realise that the method of calculating times
is incorrect and revert to a different method (say by using modified Julian
dates) - but this is a fault of the caller not the called routine.

Silently swallowing the error and creating a negative time (whatever that means)
is surely not the correct behaviour. Raising an exception that then causes a crash
is a sure-fire way to draw the programmers attention to the problem.

At a much higher level in the system we could say that "the system should not crash"
but the problem lies here with middle management - the little guy at the bottom was doing
his job correctly - he said "hey boss I can't compute anything sensible with this date"
but his boss ignored this and the entire system crashed ...

/joe


> -----Original Message-----
> From: 
> [mailto:]On Behalf Of Peter Lund
> Sent: den 30 november 2005 09:45
> To: Claes Wikstrom
> Cc: Peter Lund; ; 
> Subject: Re: bug in inets or erlang!
> 
> 
> Good you have an opionion. Please enlight us!
> 
> I think it is a bug! There is no real reason why this tiny function 
> should be causing crashes even if the caller asks for a valid 
> time and 
> date, any year in the past, for instance the birth of planet 
> earth year 
> some -6 billion or something...
> 
> /Peter
> 
> Claes Wikstrom wrote:
> 
> > Peter Lund wrote:
> >
> >> Yes, the important question here is if:
> >>
> >>  erlang:universaltime_to_localtime({{1969,12,31},{23,59,59}}).
> >>
> >> really should crash the code just because it is 1 sec too early? 
> >> No-one seems to have any opinion about it!
> >>
> >
> > I do :-)
> >
> > /klacke
> >
> 



More information about the erlang-questions mailing list