0
submitted 1 year ago* (last edited 1 year ago) by JokersPistol@programming.dev to c/experienced_devs@programming.dev

Which one is easier to develop and work with (which saves the most time)? Which one would you go for? The name of the API represents its true purpose in this case by the way, createOrUpdate creates or updates the passed in meeting and create just creates the meeting. I will be the only one working on this project for now, although obviously, I would like others to work on it with me eventually.

top 1 comments
sorted by: hot top controversial new old
[-] macgregor@lemmy.world 1 points 1 year ago

Many databases or database clients have an "upsert" operation which is exactly this. Create or update this entity. If the DB supports it you can save an explicit lookup giving minor performance and code cleanliness improvements in application but might shift that performance cost to the DB (had to rollback a prod change not too long ago because someone switched to a PG upsert and it caused average CPU to rise, haven't gotten a chance to investigate why yet, something about indexes probably).

Anyway, I tend to start with just explicit create and update methods and add an "upsert" abstraction if I find myself sprinkling lots of checks around making code messy. So I would go for "createOrUpdateFoo" in that case.

this post was submitted on 17 Jun 2023
0 points (50.0% liked)

Experienced Devs

3950 readers
1 users here now

A community for discussion amongst professional software developers.

Posts should be relevant to those well into their careers.

For those looking to break into the industry, are hustling for their first job, or have just started their career and are looking for advice, check out:

founded 1 year ago
MODERATORS