Random tech posts

Menu

Scala to C# port: part 2

Well have definitely found my C# paint point. Or maybe it’s just me not knowing C# well enough yet, but the biggest thing I’m missing so far from Scala is the brilliant pattern matching I’ve got used too. In particular pattern matching with regexes.

While trying to parse a SQL ‘like’ language, I’ve got various chunks of code such as:

statement match {

case orTermNotEnd( field, value, rest ) =>

{

returnRest = rest

nodes ::= processOrStatement( field, value )

}

case orTermEnd( field, value ) =>

{

nodes ::= processOrStatement( field, value )

}

case greaterRegexEnd( field, value ) =>

{

var node = createNode( field, gtOp, value )

nodes ::= node

}

etc…

which is very very useful. But so far for C# I’ve had to put in a lot of nested if statements. Which at best is ugly… but has many other down sides.