[SR-Dev] script parsing: string switch support

Henning Westerholt henning.westerholt at 1und1.de
Fri Feb 20 15:54:02 CET 2009

On Friday 20 February 2009, Andrei Pelinescu-Onciul wrote:
> [..]
> > > (1) - could be changed in some cases (e.g. string case with some int
> > > label allowed, which could be automatically converted to string), but I
> > >  think it would too confusing and I disallowed it (in general having
> > >  mixed types in a switch() are 99% an error).
> >
> > I would suggest to convert numbers to strings in this case automatically.
> > For most people things get more confusing with the increasing amount of
> > details they have to remember about the configuration language.
> This would only make sense if we use match() for strings and switch()
> for ints. Otherwise it would be too confusing.
> Anyway I don't think the amount of details of the configuration language
> is ever a problem, as long as one gets meaningful error messages when
> checking the config (and before ser startup).

Hi Andrei,

the amount of detail in the config language is IMHO important. The developers 
must document and test every single statement. Every user must read, learn 
and memorize each statement too. 

I regulary need to check the documentation for some special cases in the 
config when i get asked for a review of some changes a co-worker did, because 
he still feel not completely confortable after years of administrating SER* 
systems. During all the time i spend on user channels i really rarely heard 
the that our server is to slow (only when some real bottlenecks were 
involved, like DB), the common complain is that the learning curve is too 
steep. Perhaps i'm lazy, but i'd not say that everybody out there is it 
too. ;-)

> The other approaches trade-off less config details for guessing what the
> user intended, which IMO is much more dangerous. Is much better to get
> meaningful errors when running ser -cf ... , then getting unexpected
> behaviour at runtime (a very good example for this are typed variables
> vs. untyped ones or operators that try to guess the type and assume the
> user made the right choice).

I just checked in kamailio, we don't throw an error if one mix strings and 
ints in a switch case. We also check for a correct type of an integer in a 
mixed expression, e.g. if its a valid int value. I don't think that we 
convert them implicitly, as many pseudo-variables hold internally both a 
string and a integer value, so mixed expression will work just as intended in 
most cases.



More information about the sr-dev mailing list