Rui he recently pulled an all-nighter on a new contract. The core system is… complicated. There is a PHP interface, which also communicates directly with the database, as well as a Java backend, which also talks to point-of-sale terminals. The high-level architecture is a bit of a mess.
The actual architecture of the code is also a mess.
For example, this code lives in the Java section.
final class Status
static byte [] status;
static byte [] normal = 22,18,18,18;
public static boolean equals(byte[] array)
boolean value=true;
if(status[0]!=array[0])
value=false;
if(status[1]!=array[1])
value=false;
if(status[2]!=array[2])
value=false;
if(status[3]!=array[3])
value=false;
return value;
Status information is represented as an array of four integers, with the normal status always being the descriptive “22,18,18,18”. This is obviously the code coming from the POS terminal and clearly we know there will always be four of them. But man, it would be nice if this code represented that more clearly. AND for
loop in equals
method could be good, or given that there are four different status codes, maybe put them in named variables?
But that’s just an aperitif.
The PHP frontend has code that looks like this:
$sql = "select query from table where id=X";
$result = mysql_query($sql);
$result2 = mysql_query($result);
We retrieve a field called “query” from the database, modify it to insert some values, and then execute it as the query itself. You know exactly what’s going on here: they store the database queries in the database (so users can edit them! This always goes well!) and then the interface checks the database to know which queries should be executed.
Rui can’t wait for the end of this contract.
Otter – Automatically secure your servers without the need to log into the command line. Get started today!