8 ms·
A FactoryFactoryFactory in Production (2017)
- personjerry 3y agoThe story kinda ends at its climax, and abruptly ends upon reaching the `class EventFactoryFactoryFactory` and fails to explain why it was needed or what it did, concretely
- Tehdasi 3y agoThat's the punchline, nobody knows what it does or why it was needed.
- celdon25 3y agoNobody knows if the author checked the commit graph, which is really where you are expected to go if you want to know why it was needed. Maybe it turned up nothing, we will never know.
- imron 3y agoCommit message was probably ‘get eventfactoryfactoryfactory working’
- eyelidlessness 3y agoThe commit graph alone? That’s gonna be missing a ton of context you’d find by reference, while doing a bisect to compare the previous reference graph, and taking notes which become so self referential they never terminate. On the bright side, now you’ll solve the halting problem!
- eyelidlessness 3y agoIt’s okay, I don’t think I’m very funny either
- deleted 3y ago[deleted]
- eximius 3y agoI can understand how `InboundRequestContextFinderProviderFactory` comes about, hopefully due to a very mature, thorough testing environment where your `InboundRequestContextFinder` is injected via a provider and that provider needs to be constructed for different environments. Though it does seem like perhaps the Finder itself is possibly an unnecessary abstraction. Frankly, the longer I work, the more comfortable I am seeing these kinds of things. They can be misused, but they are also necessary for some really good things too. The absurd names are funny, but also somewhat standardized enough to be a signal on their own.
- viraptor 3y agoYeah, out of context it may seem weird. And if you just call it FactoryFactoryFactory that's bad design with bad naming. But the fact it exists is not weird as long as you don't use it all the time. I mean, any time you use a an ORM which can use multiple backends and inject runtime/test implementation, you have 3 or 4 levels of factories to create the actual model instance. They're just named much better.
- cutler 3y agoStockholm Syndrome?
- djbusby 3y agoSyndromeSyndrome
- AndrewPGameDev 3y agoStockholmSyndromeContextRequestBeanInstantiationStrategyDefinitionGeneratorFactoryFactoryFactory
- AdieuToLogic 3y ago> The absurd names are funny, but also somewhat standardized enough to be a signal on their own. They are a form of Hungarian notation[0], made popular in MS Windows C code: In its original form, Hungarian notation gives semantic information about a variable, telling you the intended use. In this iteration, the Hungarian notation is encoded as "canonical suffix words for a class" instead of "canonical prefix characters for a variable." Both uses are, in my not-so-humble opinion, anti-patterns to be avoided. 0 - https://en.wikipedia.org/wiki/Hungarian_notation https://en.wikipedia.org/wiki/Hungarian_notation 1 - https://learn.microsoft.com/en-us/windows/win32/learnwin32/windows-coding-conventions#hungarian-notation https://learn.microsoft.com/en-us/windows/win32/learnwin32/w...
- ts4z 3y agoI overlapped at LinkedIn at the same time as the author. While there, I wrote my first (and to date only) FactoryFactory. LinkedIn replaced its uses of Spring with a thing called Offspring. Offspring explicitly disavowed being a dependency injection framework, but it did a similar job for us. I rather liked it. Notably, you just wrote Java with it. Invariably, in Offspring, you'd have to write a FooFactory to construct your Foo object to inject it into some (other class. By convention, all of the factories ended in Factory. Well, I had a use case for a runtime class that needed to make a per-request factory to make little objects. So to make my Bars, I needed a BarFactory; and to construct the BarFactory, I needed an Offspring factory, thus BarFactoryFactory. There it was. I felt a little weird after that. I suspect the EventFactoryFactoryFactory code here was such an Offspring factory being used for dependency injection, but I can't explain why it produced a FactoryFactory.
- vore 3y agoA FactoryFactory is just a poor man’s currying!
- eitland 3y agoCurrying is just poor man's obfuscation :-) Seriously, I think anytime I have met currying (admittedly only in JS projects) the code could be rewritten to be better without it.
- vore 3y agoIt's a lot more common in e.g. OCaml and Haskell where the syntax makes the partial application a lot easier.
- OJFord 3y agoI don't have any inside knowledge, but I'd guess an EventFactory is tied to a specific Event type, so the FactoryFactory is about producing Factories for any such type? I'd never have guessed the third though.
- xg15 3y ago
- Sesse__ 3y agoAt my first project in my first job, there was a MockWorkerInfoServiceStubFactory. I think it was a factory for mocks of the stub for the worker info service, but it's never easy to know when to pop tokens from the start or from the end of such a name… (It was in C++.)
- riwsky 3y agohttps://c-faq.com/decl/spiral.anderson.html https://c-faq.com/decl/spiral.anderson.html
- arjvik 3y agohttps://archive.ph/CSmeE https://archive.ph/CSmeE
- WirelessGigabit 3y agoObligatory help to generate these names: https://projects.haykranen.nl/java/ https://projects.haykranen.nl/java/
- dvt 3y agoThe irony here is that the root of the "FactoryFactoryFactory problem" actually finds itself in composability, which itself is a feature of the -drumroll- > functional programming paradigm It's very common to see/use F(F(F...))) paradigms in lambda calculus homework exercises and its more modern/useful derivatives (yes, like Scala) where the real "meat" of the logic is the center of this Tootsie Pop. We need to change the shape of a thing to make it fit some function that takes the thing (where every step of the way, we're greeted with: no, not like that). Often times, the function expects a functional type, but we just have an object. Better Factory it up! So at some point down that rabbit hole, you're like "fine, what about a FactoryFactory?" ok cool, that works (because the engineer 15 years ago wanted it to be more "general"). Just add a ".build()" and commit. Merge. Done.
- eyelidlessness 3y agoI don’t think that’s such an irony. In FP, minding the conceptual overlap, you could conceivably name every function with a Factory suffix. After all that’s what a function does, return a thing it created. Taken to its logical extreme, one would expect far more Factory suffixes for a real program of any significant complexity. But that’s kind of a silly naming convention when every function produces a new value and there aren’t non-Factory things lurking around producing unknowable realities.
- fiddlerwoaroof 3y agoIt’s even better in Haskell: Haskell only has single-argument functions, so multiple arguments are really function factories, and sometimes they produce other function factories. So, the type signature of a FactoryFactoryFactory is something like foldr: (a -> b -> b) -> b -> [a] -> b
- eyelidlessness 3y agoHeh I was thinking about implicit currying too and I just figured that much factorying would break too many brains.
- gravypod 3y ago> I would never take a job where I got paid to write Java code for a living. I had seen the light with the functional I've never understood this kind of mindset. It seems to be really limiting. I've never once worked somewhere that only used on language or which didn't use java for anything.
- hactually 3y agoIve worked at a lot of places with no Java. I do tend to avoid the larger enterprisey environments tho
- epgui 3y agoI've never worked anywhere where java was used for anything. But I did work at a Clojure shop, and that was great. You could pick a niche language and only ever work with that, if you really wanted to.
- imtringued 3y agoGroovy is essentially a single framework language. If you want the Rails experience on the JVM with good performance it is your best bet but you aren't going to be writing anything except grails apps in it.
- unlikelytomato 3y agoAgreed. Along those same lines, I've ripped out just as much incomprehensible functional scala as I have "enterprisey" java. For every great idea, someone will internalize it as dogma. Dogma releases one of the duties of reflecting on what they are actually doing and if it is the best approach. java has it's place. many things have a place.
- imtringued 3y agoI personally thought it was ironic to praise Scala when the problem with the code was the opposite of incomprehensible. The complaint was about unnecessary boilerplate but his solution introduces a different kind of problem.
- majormajor 3y agoOnce you're dealing with a lot of code that has both a lot of external library/datasource dependencies AND you want to write good, thorough tests around it... what's the alternative to doing something like DI/Factory stuff? At some point you hit the point where you need to interact with the stateful, non-functional outside world. I completely understand why people invent things to avoid having to pass every single thing needed at every single layer as arguments into the topmost method call to get sent all the way down. I couldn't tell you off the top of my head exactly why any Java code here would need a Provider here vs a Factory there vs a FactoryFactory in some other place, but... without further information on what these classes were actually doing, I'm gonna withhold judgement. Once you've got words like that three deep on the end there's probably room for some refactoring, sure... but is it the most pressing thing that causes headaches when modifying the code? I doubt it.
- eyelidlessness 3y ago> what's the alternative to doing something like DI/Factory stuff? At some point you hit the point where you need to interact with the stateful, non-functional outside world. More DI and more Factory, I kid you not. If I’ve learned anything from FP, there’s nothing you can’t solve by passing contained references to things that make more things. If it ever becomes cumbersome it’s also a great forcing function to reconsider everything you think you know and whether you want to keep knowing.
- 8192kjshad09- 3y agoThe solution is integration tests. Unit test with dozens of mocks are the work of architecture astronauts.
- imtringued 3y agoIt's some cruft from the pre lambda days. I don't know why anyone would care about this.
- davidrupp 3y agoConsidering implementing AbstractPatternConfigFactoryBuilderFactoryConfigPatternAbstract. Just to see if anyone notices.
- winrid 3y agoI never got the factory thing. I just put the object creation logic in the object itself as static methods. For example here: https://www.tutorialspoint.com/design_pattern/factory_pattern.htm# https://www.tutorialspoint.com/design_pattern/factory_patter... I'd just have a static Shape.getOfType() Or maybe ShapeType.toShape() for type safety instead of using strings for the type. It's okay, I'll brace for the down votes. :)
- viraptor 3y agoFor things where you don't have to know which type of shape you're actually trying to create - sure. But now consider you're making something that displays shapes in one of two GUI toolkits, depending on where you're running it. You have basically 3 options: - if/else everywhere to make ShapeA/ShapeB depending on the current toolkit - generic Shape DTO and if/else + transforming all around the dispatcher to each toolkit - pass in ToolkitContext instance which has a .createShape() which requires a single condition at app initialisation stage Well... that ToolkitContext is a ShapeFactory. (Among other things) Then if you want to use a nicer system of handling this, you use DI, which is then effectively a FactoryFactory. Whether it looks obnoxious each time or you simply say AppContext.Get<Shape>() depends largely on your language though.
- contravariant 3y agoSolving the issue of having two different ways of drawing shapes by having two different classes of shapes and special logic to construct the right one seems like a bad idea. Seems to me that what you actually want is an algebraic data type and 2 different plot functions. Visitor patterns are a neater way to achieve that.
- viraptor 3y ago> seems like a bad idea. "Seems like a bad idea" seems like a bad way to make software engineering decisions. Define what you're losing / gaining, how it impacts readability, does it simplify future development, etc.
- leetbulb 3y ago"FFF" is a result of an implementation consisting of a poorly(?) though out mix between compositional OOP and dependency injection.
- g051051 3y ago> class InboundRequestContextFinderProviderFactory > What does this even mean? Why does the context need to be found, provided, and factory-ed? The implementation of the class itself is 1 line of actual logic surrounded by 22 lines of boilerplate. How are "Context", "Finder", "Provider", and "Factory" Java specific problems? Whoever decided to use that convention certainly wasn't required to do so by Java.
- alanfranz 3y agoIf you want to avoid Java just for those naming styles, while the ecosystem is actually great (doc, tooling and lib maturity) you’re doing it wrong. Java works. Its effectiveness is high, and it’s quite uncommon to hit rough edges since it’s so well tested. A smooth ride forbackend when compared to languages like Python or Javascript.
- artyom 3y agoI kindly disagree. Python tooling, documentation and lib maturity is nowadays comparable to Java IMHO. Which one is better suited for your problem is a matter of perception. Javascript (on the backend) is obviously a different story.
- ssijak 3y agoTooling for a dynamically typed language can never be on the same level as for a statically typed language. And among statically typed ones, from my experience, Java/JVM has the best and most mature tooling by far.
- EdwardDiego 3y ago> Python tooling, documentation and lib maturity is nowadays comparable to Java IMHO. Having moved to a Python shop, I disagree. I really would like it to be true, but it's not.
- peterashford 3y agoHaving just recently moved on from a Python shop, I have to disagree. Vehemently. Python tooling is in no way as good as Java's.
- jmopp 3y agoI feel like Java was designed in a way that runs contrary to how my mind works. I tend to navigate code starting at the entry-point and going deep. With lots of layers of abstraction, it's hard to figure out what is actually being run, and I tend to get lost in a Java codebase.
- renewiltord 3y agoJust remove the name and make it a Function<String, Function<Context, Function<String, Context>>> and then use lambdas throughout and your PL fans will love you for not making it something.
- artyom 3y agoMy problem with Java is exactly this. I've avoided it my entire professional life, no matter its promises or success stories. I'm not saying Java doesn't work, but makes my daily life as a programmer miserable. But there was a period when Java paid the bills, so I got proficient at it. Jumped ship as soon as I was able to. I still don't know if there's any other language with that amount of "ceremonial syntax" out there.
- kagakuninja 3y agoUsed Java 15 years before switching to Scala. Never wrote a FactoryFactoryFactory. Not sure if I've ever written a FactoryFactory, maybe once for some obscure reason. As annoying as Java is, please don't mistake pattern over-engineering with the language. One could choose to do the same things in any OO language, like C# or C++. And as someone pointed out here, there are similar obscenities in the FP world, they are just obscured under higher-kinded types and algebras.
- computerdork 3y agoI agree. Yeah, as most people here know, C# is Microsoft's version of Java (they used to say if you know one, you pretty much know the other, although have diverged a more as time progressed). So to some degree, most of the problems of Java can be found in C#... ... although you alluded to one problem that Java has. Its frameworks were developed during the height of design patterns and many (like Spring) are bloated or overly complex or not worth the trouble (and actually, I think design patterns, when used very carefully and in truly useful situations, can be fantastic).
- vips7L 3y agoSpring is not Java. I haven’t worked on a Spring app in the last 10 years. There are other frameworks like Quarkus, Helidon, or Micronaut which all have a modern design.
- computerdork 3y ago
- tempodox 3y agoI guess you can do something similar in C++ using templates, just that the result isn't usually called “factory”. The terrible things OOP lets you do aren't limited to Java.
- xyst 3y agoOddly enough - this was on page 1 earlier today. https://factoryfactoryfactory.net/ https://factoryfactoryfactory.net/
- dang 3y agoFollow-up posts are a regular occurrence. To judge by the comments, this one was pretty good!
- mproud 3y agoDoes anybody still have that blog post from like 15 or 20 years ago with the factory design pattern that had something like a Knight Factory to help defend the kingdom? Anybody know what I’m talking about?
- venkyvb 3y agoYou mean this ? http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html?m=1 http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...
- nsonha 3y agoI think the problem with this terminology is that it's not direct enough. Like why do you require people to understand a metaphor (factory -> make things) while coding? Just name the thing makeX or makeXMaker.
- User3456335 3y agoThat's because it's standard terminology that means more than just 'making things'. There is also the Builder pattern which also makes things but which is not the same as a Factory. Besides, the word maker sounds weird.
- nsonha 3y agoFactory methods literally just "make things", idk why polymorphism has to be a "pattern" when it's already a feature of the language.
- royallthefourth 3y agoOh, that'd just be a NewThing() constructor. The ThingFactory() can probably take an argument specifying which implementation you need. It's almost always just a small function holding a conditional chain that you don't want to copy/paste all over the place. As a bonus, it's a named design pattern that you can find in basically any book about design patterns. Whether it's actually worth using is another question, but at least it's a point of reference.
- kazinator 3y agoIf you ever see a factory that makes single objects of one kind, that's basically abuse of the factory pattern. The purpose of factory is to make groups of related objects that are from parallel, but distinct, inheritance hierarchies. For instance, to do AES encryption, you might need an AESKey (a kind of Key) and an AESCryptContext (a kind of CryptoContext). Your code doesn't want to know about the existence of these classes at all, let alone their relationship. You need some interface where you pass, say, the character string "AES" (or some enumeration, or Lisp symbol or whatever) and you get some object that makes keys and contexts of that kind.
- deleted 3y ago[deleted]
- vvpan 3y agoHas anybody actually been in a situation where dependency injection was better than just modules?
- computerdork 3y agoI worked on a pretty large java codebase (Stubhub) and actually found most of the code was well organized and very consistent in its architecture. The one thing I didn't like was the usage of Spring pretty much throughout. For the most part, I never had to use dependency injection to solve a problem, and realized that all the extra time and energy used to learn the Spring code and debug its problems (like adding in a new component using autowiring) was clearly not worth it. But, there was one situation where I had to change the name of a component/constant (can't remember what it was) that was used throughout a very large microservice (like 24 different places or something). This component was autowired using Spring. If I had to rename it by hand, it would have required doing a search and replace in all those places, but instead I had to change the name in one file. It saved me like an hour of time. Guess what I'm saying was it saved me like in hour in this one particular situation, but cost me days worth of time in learning it's overly complex code and debugging it. Yeah, I feel as though it is a solution in search of a problem and completely not worth it (and overall, I like Java. Yeah, to save Java, Spring must find a it's way to the ash heap:).
- computerdork 3y ago... actually, to add to this, there is one other HUGE situation where it is beneficial, Spring Boot. Spring Boot is pretty awesome and think it uses the dynamic component wiring of Spring to put together its components. Was thinking awhile ago they need to re-create spring boot but without spring (if this is possible)
- imtringued 3y ago>I never had to use dependency injection to solve a problem, Here is some life advice. Start passing your dependencies through the constructor instead of using a "new X()" call in the constructor. That is what dependency injection is all about.
- 3y ago
- kazinator 3y agoFactoryFactoryFactoryFactorsFactorsFactoryFactoryFactoryFactors
- moribvndvs 3y agoI’ve spent most of my 25+ year career working in other platforms/frameworks, and only in the past 5 years or so started working in Java. Not by choice. As such, I’ve got lots of bones to pick about the language and the JVM (the former of which I’ve worked around by using Kotlin, which I quite like). The meme about factories, however, has perplexed and kind of annoyed me. Isn’t that more a symptom of once-popular design paradigms that overstayed their welcome or perhaps never were, which can happen in any long lived ecosystem (in this case, one I’ve seen pop up here and there in other OOP platforms, such as .NET)? Maybe I’m spoiled by mostly having worked in recent Spring Boot where I rarely see these tedious and awkward patterns, and perhaps the meme is more impactful for people stuck in legacy land, but there is a bit of hubris with these blanket associations that rubs me the wrong way. I’m no Java apologist, either.
- dang 3y agoDiscussed at the time: A FactoryFactoryFactory in Production - https://news.ycombinator.com/item?id=15952502 https://news.ycombinator.com/item?id=15952502 - Dec 2017 (46 comments) Related ongoing thread: Why I Hate Frameworks (2005) - https://news.ycombinator.com/item?id=36637655 https://news.ycombinator.com/item?id=36637655 - July 2023 (206 comments)
- JaDogg 3y agoI recently started working in a Kotlin project coming from a Java background. I wrote a Builder for a data class I needed to add stuff in a loop. Reviewer suggested I use `copy()` instead. Once I used that I was happy, I didn't need that Builder after all. I removed bunch of useless lines of code, made things simpler. Loved it!
- oaiey 3y agoAs a C# guy I am also amazed by this. Somehow the C# frameworks and community skipped this degree of pattern madness and took a more pragmatic approach. I think this is because of the more industrial and less academic influence on the language and frameworks
- wodenokoto 3y agoI feel like the article cuts short. It ends with a “I saw one in real life!” But not anything about why it came to be, if it performed well, despite its clunky name or if it actually was a good idea given its circumstances
- eternityforest 3y agoI always see all this terrible Java stuff, but the world hasn't ended and people who use Java all seem to say it's actually great for large enterprisy stuff. Are these FactoryFactoryFactories secretly some kind of busywork conspiracy to keep all the "Coding for the sake of coding" engineers busy doing mostly harmless nonsense rather than deciding to make their own assembly language based on JSON that gets interpreted with buggy regex? Like, I could work with a factoryfactoryfactory. It's just random nonsense, but there's not a lot of actually content. If someone writes their own PEG parser in Forth, and then embeds a handwritten forth interpreter, and then writes the application in their own language, I'll be completely lost. I'd rather deal with stupid boring enterprise code that does nothing than clever hacks.