6 ms·
Kraken Technologies: How we organise our large Python monolith
- photonthug 3y agoNever heard of https://import-linter.readthedocs.io/ https://import-linter.readthedocs.io/ before. Not sure if I like this type of solution, but it's interesting, and certainly the problem is real.
- bitdivision 3y agoThe author, David Seddon, is also the author of the package [0]. So I'm guessing Kraken was an initial user. 0: https://import-linter.readthedocs.io/en/stable/authors.html https://import-linter.readthedocs.io/en/stable/authors.html
- walthamstow 3y agoInteresting that he doesn't blow his own horn about being the author of the linting tool. He simply describes it as 'an open source tool'
- shoo 3y agoYeah, the problem is certainly real. I remember working with a much smaller python monorepo some years ago (probably 100x fewer python modules but the beginnings of multiple client-specific variants that depended upon a swathe of core libraries) and we were already starting to see places it would be valuable to declare constraints banning certain types of imports that broke our desired module architecture and enforce those constraints during CI without needing humans to notice the violations during code review.
- CraigJPerry 3y agoThis is java circa 2009 flavoured, this model was a popular approach in the java community around that timeframe. Was enforcer the name of the maven plugin? I can’t remember now, but it became fairly popular. I wonder if this might be susceptible to the same issues that we had in java, specifically it doesn’t prevent accidental duplication, it makes refactoring harder/slower and it’s problematic for the team when it unexpectedly doesn’t catch a misuse - and this happens because the rules enforcement can only happen effectively if the rules themselves are perfect and complete and that gets harder to guarantee with scale and speed of iteration. For my money today, there’s another model “polylith” which is similar in some ways and as easy to understand but maybe simpler to evolve/change your mind over time.
- barefeg 3y agoWhat is the current flavor in Java?
- mentaltomorrow 3y agoSpring (and all its reflections under the hood), of course.
- photonthug 3y ago> this happens because the rules enforcement can only happen effectively if the rules themselves are perfect and complete and that gets harder to guarantee with scale and speed of iteration. IMHO, project-level assertions about initialization-order feels a little bit dirty, but potentially practical as long as there's only a few rules. Surely even a bazillion line monolith can still often be thought of in terms of a few layers. But by the time you get to lots of rules it's getting hard to stomach the code-smell and keep justifying it as practical. At that point I'd want something dynamic and backed by a real solver.. not just a layer of static-analysis. The deal framework for DBC doesn't quite do this afaik but is starting to expose some stuff along these lines, and at least can assert imports are "pure". https://deal.readthedocs.io/details/module_load.html https://deal.readthedocs.io/details/module_load.html
- ianandrich 3y agoHave you had any experience using deal on personal projects or professionally yet?
- photonthug 3y agoSo far I'm working it into personal projects gradually. Runtime checks are at least as useful as something like pydantic's validation, and more expressive, because validation is basically "pre" but now deal can provide the "post". DBC via pre/post might be "just" syntactic sugar on asserts, but notation matters: it looks great, it reduces cognitive load. It easily does stuff that's impossible or just awkward with types, so having an alternate way to express constraints available probably keeps me out of certain rabbit holes. Really looking forward to trying verification ( https://deal.readthedocs.io/basic/verification.html https://deal.readthedocs.io/basic/verification.html ) but I think I need to hit some critical mass of annotation first.
- mint2 3y agoNote, this is not the crypto kraken, it’s a different kraken for those who ignore crypto related stuff
- loveparade 3y agoWhy does it matter? Just because I don't like Google doesn't mean they suck at writing Python code. The same goes for anything crypto.
- ericjmorey 3y agoPeople are emotional and sometimes addressing an emotional concern helps. In this case, people who are exhausted by cryptocurrency culture would be more willing to read this write-up being assured that it's not cryptocurrency related.
- mint2 3y agoI personally almost skipped it, thinking it might be a crypto company puff piece masquerading as a python show and tell. crypto is known for puffery and it’s exhausting. But this article turned out to be not even from a crypto company, instead just having the misfortune of sharing name.
- febed 3y agoIMHO the customer specific stuff should have been forked out into a separate repo instead of cluttering up the main one
- gyulai 3y agoI quite like layered dependency structures. I even have a lua codebase where I've linearized the sourcecode files into a particular order. The layout looks like this: 01_foo/ 03_foo.lua 04_bar.lua 15_whatever.lua 02_bar/ 22_whatever.lua 56_something.lua It has always bothered me in codebases that they don't have a "beginning" and an "end", and therefore it's difficult for a reader to know where to start when they just want to read the codebase. So, my approach is to impose this linear order and only allow code that comes later to depend on code that comes earlier, never the other way around. This way, you can read through the code rather easily. As you look at any piece of code, it will only depend on code you've already looked at, so you don't have to be constantly jumping through the codebase as you're reading. I've also found that failure to correspond to a linearizable dependency structure is a "code smell", and that, as I try to eradicate that code smell, I frequently end up with code that's better in all kinds of ways.
- globalreset 3y agoThat sounds like one of the things they could write about in dailywtf. First, who has time to read a project from start to beginning. Second, as the time changes the dependencies between parts will change as well.
- gyulai 3y agoWho has time to write documentation? As the software evolves, the documentation will need changing. Who has time to write unit tests? As the modules evolve, the unit tests will need updating. Why do any of these things? A well-written piece of code that actually solves a complex problem is a demanding mistress and doesn't appreciate the "who has time..." attitude. Among the software engineering good practices that I engage in, I'm finding this to be one of the highest bang-for-the-buck ones. For example, literate programming is a thing that many people believe is worth the effort, at least in certain scenarios and at least for certain parts of codebases: But, if you can make your codebase more readable without requiring additional prose to be written, then that's a comparatively high bang-for-the-buck alternative. In practice, linear structure doesn't need all that much updating at all: You may have noticed that I don't use strictly sequential numbers. Early in the life of the codebase, I will generally skip lots of numbers, so that I can fill in the gaps with code that comes later. Mostly, all it really takes is to be intentional about where in the linear order to insert new code. Also, note that it's still useful, even if no one ever goes on a mission to read the codebase in its entirety. If the codebase as a whole has a linear structure, that also imposes a linear structure on any subset of it. If you have five sourcecode files that are somehow pertinent to something you're doing, you immediately know the order in which to look at them.
- unusable_link 3y agoI'm very sorry for the offtopic but how am I supposed to read the article if they covered the button to close the cookie popup by the button to subscribe to their newsletter? [0] I tried clicking the bottom and the corner and it just doesn't work. Is it a dark pattern? Is it done deliberately to make people click on the newsletter button more? [0] https://ibb.co/dg2krqL https://ibb.co/dg2krqL
- pxul 3y agoYes this bugged me too. Was able to clear the cookie pop-up by rotating my phone.
- nick-of-time 3y agoI used uBlock's element zapper to kill it. Mobile Firefox supports it. To exit zapper mode oncxe you're done (I had to look this up) swipe right twice.
- kgeist 3y ago>Enforcing layering with Import Linter We use a similar tool for PHP - deptrac, it checks that our architectural decisions about layers and modules, and their interactions, are not violated. If they're violated, the build fails. Interestingly, we don't use similar tools for our microservices. I'm not sure whether it's an oversight or it's just unnecessary in a microservice.
- calderwoodra 3y agoCode layers makes sense, but organizing your code in layers does not. For example, I much prefer this: project/ feature_1/ view.py service.py model.py feature_2/ view.py service.py model.py over this: project/ views/ feature_1_view.py feature_2_view.py services/ feature_1_service.py feature_2_service.py models/ feature_1_models.py feature_2_models.py And their import-linter library doesn't support this very well.
- david-j-vujic 3y agoSome have already mentioned Polylith, but what might not be known is that it is available for Python too (I’m the maintainer of the Python tooling). What is mentioned in the article reminds of the Polylith Architecture, even if Polylith probably has a more simplistic view on code: a flat structure, made of something called “bricks” - that are small namespace packages. These ones are combined into features, the features are combined into apps or services. You can choose how to deploy your artifacts - as a single Monolith, or several microservices. Since the code is not coupled to the built artifact, it isn’t a big thing to change it from one type to another. Docs here if you want to know more: https://davidvujic.github.io/python-polylith-docs/ https://davidvujic.github.io/python-polylith-docs/