2,204 karma · joined March 29, 2019
In prod, the pyinstrument profiler has worked well for me https://pyinstrument.readthedocs.io/en/latest/guide.html#pro...
I think it's indicative that the nicest use is in AST processing. As someone that works on the occasional parser-y side project it looks pretty cool, but also, 97% of professional Python development is in data-science/application development. I suspect this is a case of the core language devs having a bias towards features that are useful to them as opposed to the community as a whole.
It just feels nice to me.
I was hoping the code in the article would form (an admittedly small) piece of evidence. I'd just really like someone to show off a nice neat counter example, that demonstrates the true beauty of Python OO, and is "unrefactorable" to a data types + functions equivalent.
Pathlib is a great example, maybe a canonical one, of:
> Very occasionally, you come up with a core type that's used so often, it's nice to have the cutesy stuff.
Django's class based views I think could probably reasonably refactored into data types + functions. I'm not too au-fait with Django or its internals, but if someone could send me a "demonstration Django clone in 800 lines", I'd give it a go.
> What if client_a and client_b write to different APIs? ...
Then you use an if statement to split at that point. Again, given a specific toy example, I'm fairly certain a reasonable refactor is possible.
Surely it's possible to construct a smaller example? It's not like the millions of lines codebase isn't de-composable?
Given some examples, I'll do a follow-up blog post.
Given some examples, I'll do a follow-up blog post.
Given some examples, I'll do a follow-up blog post.
Given some examples, I'll do a follow-up blog post.
Edit: ignore me - this person seems to know more what they're talking about - https://news.ycombinator.com/item?id=25933781
I stole their API somewhat for my 33-line-React, if you have any interest in how stuff works under the hood - check it out! https://leontrolski.github.io/33-line-react.html
- render entire pages from a Python backend
- use as components in mithril https://mithril.js.org/
- I'm aware of dhall, jsonnet and friends, I think they're cool, but I think the most important for me is this is just js - that means nothing new to learn + you can use it from front end code + free linters etc.
- I think the to-html bit is important, this is something I tangentially talked about in more detail here - https://leontrolski.github.io/dom-syntax.html. There was some discussion on hacker news about that one too, again, I think the important "feature" is that it's just js. Again, to me that's really important, so hiccup, jsx, etc don't cut it.
const root = document.getElementById('noughts')
m.render(root, {children: [...Array(10000)].map(_=>m('', {class: ['hi']}, 'hi'))})
m.render(root, {children: [...Array(10000)].map(_=>m('', {class: ['bye']}, 'bye'))})
wrapped with: console.time('a'); ... console.timeEnd('a')
On my laptop (admittedly a fairly new macbook), I got (approx): 130ms to make divs from scratch
80ms to switch from 'hi'->'bye'
50ms to re-render with no changes
I'd be super interested as to what comparable figures would be for React. There's a fair bit of interesting discussion below surrounding performance, but with no datapoints. Lots of the code looks pretty code-golfy - I promise I don't do stuff like this at work, neither should you
Happy to s/g/grid/ - writing the whole exercise felt a bit golfy TBH.It's interesting, there's a lot of chat about performance with these frameworks, yet I'm not sure how much is relevant to the real world. When I do eg a
document.querySelectorAll('*')
on airbnb map view (I guess a pretty good example of a mid complexity SPA), there are 3407 DOM elements - doing a diff on the VDOM elements of these should quick.If I were doing something like a clock on a page (or an animation for example), I'd probably just do it out-of-band of my framework. These kind of things tend to be few and far between anyways.