All posts by george

Reverse Polish Notation

My knowledge of reverse polish notation came in handy today. It’s weird how these things come up in real life and not just in an academic setting. Granted, not every college graduate deals with the Excel file format.

Excel’s formulas are stored in binary spreadsheet files in reverse polish notation, which makes sense. There aren’t usually numbers in the file which say how many arguments a function contains, so we have to know that in advance to be able to understand the formula. You evaluate the arguments of a formula before the formula itself, so the stack at the point of evaluating the formula itself should contain exactly the number of arguments the formula has. It’s elegant when it works, but it makes it difficult to figure out when you have an error (unlike in XML where everything has boundaries)

Usually, if you read in more arguments than are available, an exception is thrown, and if you read in too few, an exception is thrown when evaluation completes and you have extra tokens to read. You could theoretically read too few arguments at one point and too many at another and just have an invalid result, but that would require two errors happening simultaneously, which is (hopefully) improbable.

Things I’d like in an IDE

I wish Resharper had a feature which pointed out where exceptions are being created but aren’t being thrown (ie, new Exception() instead of throw new Exception()). I also wanted a feature which automatically sets breakpoints where exceptions are thrown, although after thinking about that for a bit I’m not sure about that. I do really like the syntax checking for the most part, even if it messes up sometimes. And I still do go back to Emacs for anything repetitive; I haven’t seen anything in Resharper or VS that allows for Emacs-like macros.

GetType() Vs. Is

I wrote two functions and disassembled them using Reflector:

.method private hidebysig static bool CompareWithIs(class ConsoleApplication1.A x) cil managed
{
.maxstack 2
.locals init ([0] bool flag)
L_0000: nop
L_0001: ldarg.0
L_0002: isinst ConsoleApplication1.B
L_0007: ldnull
L_0008: cgt.un
L_000a: stloc.0
L_000b: br.s L_000d
L_000d: ldloc.0
L_000e: ret
}
private static bool CompareWithIs(A x)
{
return (x is B);
}