5 ms·
This library reminds me a lot of the code I've seen from junior developers trying to make things "cool" by removing a few characters of typing in exchange for l
by typon 6y ago
This library reminds me a lot of the code I've seen from junior developers trying to make things "cool" by removing a few characters of typing in exchange for library abstractions that create headaches down the line. I think features like this take years to naturally evolve in a codebase, on an as needed basis. And once that code base has evolved to reach something resembling non idiomatic Python, it can be quite hard to integrate new devs into the team. Such transitions into custom dsls or nifty tools are inevitable for large code bases, but I try to minimize it as much as possible, even when it hurts productivity. Long term maintainability is more important to me.
- slaymaker1907 6y agoI know what you are talking about in general, but most of the stuff in this library seems to either add clarity or help prevent errors. The problem of kwargs where you end up with a bunch of confusion on documentation is definitely a real thing. Multiple dispatch is also a great thing as well. You don’t realize you need it until you try implementing something unification algorithm. Compose is nice for reducing the mental overhead of reading nested expressions. However, I do wish they took a line from lodash and implemented flow instead (like compose but reversed so the first argument is invoked first, then the output of that is fed into the second, and so on). Syntactic sugar is not bad if it increases signal to noise when reading code or if it prevents erroneous usage.
- marmaduke 6y agoOk but what’s with the pre post meta init thing? Let’s see a junior run a debugger through that! Dropping one line of code costs several stack frames in your debug session.
- jph00 6y agoIt's a feature from the standard library. However it's only normally available in dataclass. fastcore simply brings the same functionality to other classes too.
- dragonwriter 6y agodataclass has __post_init__ as a mechanism for doing what you'd normally do in __init__ besides what dataclasses do in the generated __init__, because the generated __init__ means you can't do it in __init__, and otherwise you'd have to override (and replicate the function of) the generated __init__. It is not equivalent to PrePostMetaInit.
- laminatedsmore 6y agoI think a python implementation of flow is in the toolz library as compose_left. I find myself often using the similar pipe function. - https://toolz.readthedocs.io/en/latest/api.html#toolz.functoolz.compose_left https://toolz.readthedocs.io/en/latest/api.html#toolz.functo... - https://toolz.readthedocs.io/en/latest/api.html#toolz.functoolz.pipe https://toolz.readthedocs.io/en/latest/api.html#toolz.functo...
- dragonwriter 6y agoTheres a lot of good stuff here (@delegates, partialler), sure, but then there's things like the extended Pathlib with pickle functionality; @typedispatch is a nice concept, but the multimethod seems to be more complete implementation of the concept that's been around much longer, so I'm not sure if there is a good case for it that I'm missing or it's just NIH.
- deleted 6y ago[deleted]
- ayush--s 6y agoAll sizable codebases eventually grow their own patterns & utils that have similar abstractions. I'd rather spend my time writing business logic than boilerplate.
- wrkronmiller 6y agoThere used to be a saying among web developers that you can either use a framework or end up building a framework.
- digitallogic 6y ago> I try to minimize it as much as possible, even when it hurts productivity. Long term maintainability is more important to me. I don't think this needs to be an either/or choice in these situations. You can have both if you make the make the conscious decision to not fight your tools. Yes, sometimes you have to be more verbose in one language than another, but the productivity hit in that case always pales in comparison to the hours, days, and in some cases I've seen, weeks, lost by someone fighting their language/tools. My favorite example of this was a developer given a 2 week feature implementation that ballooned to two months. They had minimal experience C++, and they didn't like its looping syntax. Rather than accept that frustration and write the code in a syntax they disliked, they instead spent weeks writing a "re-usable library that abstracts away looping semantics".
- ghj 6y agoNot a good example because being discontent with c++ for loops is how we got https://en.cppreference.com/w/cpp/ranges https://en.cppreference.com/w/cpp/ranges (which imo is a good addition to the standard library) But yea, not while you're trying to ship.
- giancarlostoro 6y agoI think the sweet spot is the approach taken by Kotlin for making DSLs because it further removes ceremonial boilerplate that Java loves to give you. I think Pythons as minimalist as it needs to be... The best I do is rename imports that are long if anything. I also define function pointers if I reuse the same method call throughout a tree which helps to keep things tight yet still readable.
- wirthjason 6y agoI’ve seen this happen with senior devs too, but who come from a background other than Python. There’s a lot of value in deeply learning the internals of a language so you can write good code in the target language rather than developing some mashup of “features”. Ironically the article begins with be premise of deeply learning python but never touches on the advanced features that were learned and applied to develop the library.
- jph00 6y agoThe person that wrote the article doesn't work at fast.ai and didn't write the library, so they don't have that information.
- hitekker 6y agoBut aren't you one of the authors of this article? The headline lists you as an author and you're a founding researcher at Fast.ai.
- jph00 6y agoOh so it does! Sorry I'll ask Hamel to change that - he's just being generous with his credit. I didn't write a single word of it! Sorry for the confusion. :)
- mloncode 6y agoSorry about that. Indeed, I felt that since he was the author of the library and essential to me learning it I felt the least I could do was to put his name on there. I removed his name via https://github.com/fastai/fastpages/pull/408 https://github.com/fastai/fastpages/pull/408 -- Sorry for the confusion! Indeed, even though I learned a ton about python, I didn't feel like what I had to say made for an interesting blog article, and was a bit abstract. I was equally excited about the library from and end user's perspective and decided to blog about that instead.
- hitekker 6y agoI have a feeling these Python enhancement libraries will become ever more popular now that Guido has stepped down. I wonder what the vision of Python's steering committee is.
- GhostVII 6y agoLot of the features in this library seem to be targeted at making things clearer, not just making your code as compact as possible. It is a lot cleaner to use type dispatch rather than have some switch case in your function to determine behavior. And it is useful to know where the kwargs is being used rather than have it be a black box. Having to store every parameter from __init__ into self is an annoying pattern I find myself almost always following, so it's nice to have a solution to that too. Generally I prefer to use vanilla python as much as possible, but I think there is value in having libraries like this, which make things clearer and have less boilerplate without much cost. Most of what I see would be pretty easy to replace with regular python if you decided to move away from the library, there aren't lots of wierd layers being added to your code.
- Too 6y agoNot just for humans but also for machines. These meta programming tricks usually breaks mypy, regressing back to a fully dynamic language. There are some good ideas in there though, like @dispatch which have potential to improve type checking.