Showing posts with label operator precedence. Show all posts
Showing posts with label operator precedence. Show all posts

Thursday, 5 March 2020

On Polish Notation in Software Design

I was looking up Polish Notation, as I remember hearing about it.

And it turns out Polish Notation is actually, basically, when you think about it, exactly how programming languages in my experience work.

For example:

x − 5 6 7

Is polish notation for:

(5 - 6) x 7

This is very very difficult to understand for someone like me who is absolutely not used to Polish Notation.

However, when I write this down in programming language method calls, everything becomes crystal clear immediately.

multiply(minus(5, 6), 7);

For some reason, the statement above makes perfect sense to me.

Likewise as in the Polish Notation, in software design method-calls, the sequence of statements is unambiguous.

With the infix notation, parentheses are required to override operator precedence rules.

Both in Polish Notation as in programming, this does not seem to be required.

References

Wikipedia - Polish notation
https://en.wikipedia.org/wiki/Polish_notation

Friday, 14 November 2014

SQL Operator Precedence

Just a small note for me to remember how this works.

select * 
from ((select 'FINANCE' as dept,  42 as employees from dual) union 
      (select 'SALES' as dept, 32 as employees from dual)) departments
where
   departments.dept = 'FINANCE'
or
   departments.dept = 'SALES'
and
   departments.employees < 30;
returns: FINANCE 42

Clearly, AND takes precedence over OR, as usual.
AND B OR C => (A AND B) OR C

OR B AND C => A OR (B AND C)

References

Stackoverflow - sql logic operator precedence
http://stackoverflow.com/questions/1241142/sql-logic-operator-precedence-and-and-or
SQL Logical Operators
http://www.praetoriate.com/t_garmany_easysql_sql_logical_operators.htm