commit 51048fdabab1ae4293c175f2b226f7a5784cd7ba
parent 9d0c6200309f20e300b1d185d9b1518b01ebad26
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date: Mon, 21 Apr 2025 21:06:05 -0700
Add weeknote for 2025-W17
Diffstat:
1 file changed, 77 insertions(+), 0 deletions(-)
diff --git a/content/posts/weeknotes/2025-w17/index.md b/content/posts/weeknotes/2025-w17/index.md
@@ -0,0 +1,77 @@
+---
+title: "Weeknote for 2025-W17"
+description: "Tools for reproducible R, Python data classes, the wrong abstraction"
+date: 2025-04-21T19:48:11-07:00
+draft: false
+categories:
+- Weeknotes
+tags:
+- R
+- Python
+---
+
+## Managing reproducible environments in R
+
+I saw [a toot on
+Mastodon](https://mastodon.social/@joranelias/114361012740025621) bemoaning the
+experience of using `renv` to manage “reproducible environments” in R. I’ve had
+the exact experience the author describes:
+
+> More than half the time when I actually have to *use* it to restore a project
+> that hasn't been touched in more than a year or two `renv::restore()` fails
+> with tons of errors, I struggle for hours to figure it out and typically just
+> give up and simply install current versions of all the packages and pray.
+
+To give a concrete example, I was recently contacted by a journalist who
+wondered if I could update a quick and dirty analysis that I posted to Twitter
+_years_ ago, and `renv` failed because the older versions of packages wouldn’t
+build with the version of GCC on my computer. (Fortunately, my prayers were
+answered, and installing the current versions of all the packages worked just
+fine.)
+
+[A helpful reply](https://fosstodon.org/@brodriguesco/114361023856952425) to
+the toot recommended `rix`, and I plan to check it out!
+
+[rix: Reproducible Environments with Nix](https://docs.ropensci.org/rix/)
+
+## Using data classes in Python
+
+I’ve been writing a lot of Python at work lately, primarily using
+[PySpark](https://spark.apache.org/docs/latest/api/python/index.html). Now I’ve
+been using Python for a long time[^old] but after doing some work in Julia I
+fell in love with [multiple
+dispatch](https://docs.julialang.org/en/v1/manual/methods/) and lately I feel
+encumbered by Python’s approach to OOP.
+
+My interest was piqued by this post about leveraging Python’s [data
+classes](https://docs.python.org/3/library/dataclasses.html) (and relying more
+heavily on factory methods) to simplify object definitions. The approach
+advocated here feels like an improvement to Python classes I’ve written. I
+still prefer being able to extend a class’s capabilities by writing new “outer
+methods” (as in Julia) than creating a whole subclass (as Python requires me to
+do). I expect subclassing data classes will be less onerous than the status
+quo, but I just have to try this whole thing out and see how it feels.
+
+[Glyph --- Stop Writing `__init__`
+Methods](https://blog.glyph.im/2025/04/stop-writing-init-methods.html)
+
+## “Duplication is far cheaper than the wrong abstraction”
+
+[Maya (of maya.land)
+shared](https://maya.land/responses/2025/04/15/specific-advice-refactoring-code.html)
+this excellent and practical advice on how to identify and fix the problems
+that arise when a piece of code is committed to the “wrong abstraction”. I’ve
+been guilty of overenthusiastically introducing quickly-outgrown abstractions,
+so don’t take the following as an indictment of my colleagues’ skill. However,
+the aforementioned Python code happens to be part of a major refactoring effort
+(which involves changing languages and platforms), so now I’m inheriting years
+of accumulated tweaks and kludges, and I need to decide what to keep[^pm]. This
+advice couldn’t come at a better time for me professionally.
+
+[Sandi Metz --- The Wrong
+Abstraction](https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction)
+
+[^old]: I picked up Python to replace C for a project in 2004, and it’s been my
+ “primary language” on and off for the past 2+ decades. Hey, I’m old.
+
+[^pm]: And also help others figure out what to keep.