6 ms·
> In the industry code that isn't DRY is a much bigger problem than code that is too DRY. As with anything dogmatic, it truly depends. There are times when the
by nkozyra 2y ago
> In the industry code that isn't DRY is a much bigger problem than code that is too DRY.
As with anything dogmatic, it truly depends. There are times when the abstraction cost isn't worth it for a few semi-duplicate implementations you want to combine into a single every-edge-case function/method.
- PaulHoule 2y agoThere's a certain psychological attraction to messy and confused situations which people are just too comfortable with but it explains why things like GraphQL (didn't have a definition for how it worked for years because "Facebook is going to return whatever it wants to return") inevitably win out over SPARQL (which has a well-defined algebra). One of my biggest gripes (related to the post) is the data structure create table student ( ... applied_date datetime, transcript_received datetime, recommendation_letter1_received datetime, recommendation_letter2_received datetime, rejected_date datetime, accepted_date datetime, started_classes_date datetime, suspended_date datetime, leave_of_absence_start_date datetime, leave_of_absence_end_date datetime, ... graduated_date datetime, ... gave_money_date datetime, died_date datetime ) which is of course an academic example but that I've seen in many kind of e-business application. Nobody ever seems to think of it until later but two obvious requirements are: (1) query to see what state a user was in at a given time, (2) show the history of a given user. The code to do that in the above is highly complex and will change every time a new state gets added. The customer also has experiences like "we had a student who took two leaves of absence" or "some students apply, get rejected, apply again, then get accepted" When you find data designs like this you also tend to find some of the records are corrupted and when you are recovering the history of users there will be some you'll never get right. If you think before you code you might settle on this design create table history ( student_id integer primary key, status integer not null, begin_date datetime not null, end_date datetime ) which solves the above problems and many others in most situations. (For one thing the obvious queries are trivial and event complex queries about times and events can be written with the better schema.) I can't decide if the thing I hate the most about being a programmer is having to clean up messes like the above or having to argue with other developers about why the first example is wrong. If "No code" is to really be revolutionary it's going to have to have built-in ontologies so that programmers get correct data structures for situations like the above that show up everyday in everyday bizaps where there is a clear right answer but it is usually ignored.
- gls2ro 2y agoTwo points here just for fine grain discussion: 1. The first table structure is a flat non-normalized table structure that trades normalization for easy to query and select computed properties 2. Second structure is a normalized table structure that trades the normalization for joins.
- PaulHoule 2y agoEither one is normalized so far as I know. It is easy to write a query for the first that gets a list of students names and the dates they applied. That query is harder for the second one. On the other hand figuring out what state a user was in at time t could be a very hard problem with the first table. My experience with the first is that you find corrupted data records, one cause of that will be that people will cut and paste the SQL queries so maybe 10% of the time they wind up updating the wrong date. Systems like that also seem to have problems with data entry mistakes. The biggest advantage of #2 is ontological and not operational, which is that in a business process an item is usually in exactly one state out of a certain set of possible states. Turns out that this invariant influences the set of reasonable requirements that people could write, the subconscious expectations of what users expect, needs to be implicitly followed by an application, etc. Granted some of the dates I listed up there don't quite correspond to a state change, for instance the system needs to keep track of when a student started an application and when the last document (transcripts, letters, etc.) has been received. With 5 documents you would have 32 possible states of received or not and that's unreasonable, particularly considering that a student with just one letter and a very strong application in every other way might get accepted despite that. It's fair to say the student can have an "open application" and a "complete application". Similarly you could say the construction of an airplane or a nuclear power plant can be defined by several major phases but that these systems have many parts installed so if the left engine is installed but the right engine is not installed these are properties of the left and right engine as opposed to the plane.