Interesting though SQLite Optimizations #2098 is, I thought that it had been decided that AI could not be used for contributions. “The last couple of months” is not really that much time to get a good appreciation.
Besides, in the context of SQL (and the switch from Pickled BLOBs to JSON), I would much prefer that the code base be improved in this area before going all out on further work. I have commented in this area before, but:
- Clarity and understandability of code and static type checking
- Is it still the case that some DB methods can return either the desired thing, or None, and wasn’t there a comment that this gave rise to lots of hidden errors, so the code should be changed to type check that only the desired thing is returned, so these errors can’t occur.
@DavidMStraub, one complication is that when these methods are overloaded in a proxy (like LivingProxyDb, or PrivateProxyDb) then a method might return None. This is the number one issue in bugs throughout the code base: we don’t check to see if the return value is None and then we end up with crashes.
I think with the correct type hints, we could catch such errors.
- Has static type checking been implemented for all the DB methods and calls?
- There is a lot of code for JSON where there are long hierarchies of methods, because of the introduction of a small change, rather than making a clear abstraction.
- Some of the details of changes for JSON (not the overall concept) achieved small performance improvements at the expense of added complexity and reduced understandability. (Interesting that is probably not the case for SQLite improvements here).
Code is read much more than it is written, and whereas quick changes are ideal for prototypes, the code really needs to be cleaned up for production and maintenance (I’m talking about JSON code, not the SQLite optimisations here).
@DavidMStraub I know you had been looking at this sort of thing - e.g. your comment on Add type hints to the generic database handler by DavidMStraub · Pull Request #1858 · gramps-project/gramps · GitHub
What I am trying to achieve is clarity and explicitness and type checking in the code, like there is in gen/db/generic get_person_from_handle. I would much prefer replicated get_person_from_data, consistently like all the other get_foo_from_bar in gen/db/generic.
I am with you on this. Explicit is better than implicit, and if something is difficult to type-hint, it probably means that it’s not explicit enough.
[BTW, I had also given AI a go. It was interesting how much it got right, and ‘understood’. It wasn’t much good at producing a gramplet from a description - it ran but didn’t do what I wanted. Further prompts made it fail to run though nearer to what I wanted. I also tried a code improvement - surprised at what it refactored into subroutine, it ran but duplicated some of the output, due to a complicated misunderstanding on its part about the properties of a particular type. So what. I wouldn’t trust it to produce good, clear and correct code.]