Hacker News new | past | comments | ask | show | jobs | submit login

My take: poorly designed data models (persistence structures) relying on clever hacks in the program to overcome incorrect ordinality and cardinality rules, data redundancy etc ...



I think he meant an actual code example


Sorry, my bad. Read that hastily. Let me try that again:

Company has Departments with many Employees. One Employee is always a DepartmentHead.

POOR DATA STRUCTURE:

class Department {

  property Integer DepartmentId;

  property String DepartmentName;
}

class Employee {

  property Integer EmployeeId;

  property String EmployeeName;

  property Integer DepartmentId;

  property Boolean IsDepartmentHead;
}

This will require programs to make sure that no more than 1 employee can be a DepartmentHead. For every update to the IsDepartmentHead property of an instance of Employee the program will have to iterate through the list of Employees to flush the switch before assigning the new one.

BETTER DATA STRUCTURE:

class Department {

  property Integer DepartmentId;

  property String DepartmentName;

  property Employee HeadEmployee;
}

class Employee {

  property EmployeeId    Integer;

  property EmployeeName  String;

  property DepartmentId  Integer;
}

This is a much better data structure since you can only ever have one Employee assigned to a Department as a head. The program will of course need to prevent Employees from Departments they don't belong to from becoming Heads of the Departments they are NOT in.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: