HNHacker News
TopNewBestAskShowJobs

Suor

614 karma · joined October 26, 2011

submissionscomments
Suor··on Ban 1+N in Django
Writing things directly is tightly coupling code. Sometimes quite distant portions of it, i.e. database access and presentation logic. With ORM and some smarter lazy technics or introspection at least you can untie it, with hand written SQL there is no way. And the reason is strings are poorly composable. Unless you use some query generator, but then we are back to ORM-like something.
Suor··on Ban 1+N in Django
Never used this, but I see that it provides a context manager/decorator, which you can use to "shield" any code. And also some shortcuts for DjangoREST or something.

Regarding extra code, you can simply replace the Djangos' `render()`, with the one from this lib and you are done. I would have probably made a custom template extension or something to do that for all renders automatically though too.

Suor··on Ban 1+N in Django
cacheops is more of a general purpose ORM caching with automatic invalidation.
Suor··on Ban 1+N in Django
For that fetching in chunks is usually a way to go. I use something of these usually https://handy.readthedocs.io/en/latest/db.html#queryset_iter...
Suor··on Ban 1+N in Django
GraphQL makes it even more fun :)
Suor··on Ban 1+N in Django
I usually use `.values()` and `.values_list()` only when model creation is really slow. Usually many rows fetched.
Suor··on Ban 1+N in Django
Actually there is such thing already https://pypi.org/project/django-auto-prefetch/ Not a monkey patch though, so will only work on the models you inherit from this.
Suor··on Ban 1+N in Django
Here is an example of such thing https://github.com/Suor/django-cacheops/blob/8b3a79de29b2545...
Suor··on Ban 1+N in Django
Should be easy enough to implement. You only need a context manager that adds 1 to some threadlocal flag on enter and subrracts on exit then check this flag in the monkey patch. Not sure how costly that will be though.
Suor··on Ban 1+N in Django
cacheops can do the same, but it never came to my mind to actually go this way. I would rather write some special code to fetch with `id__in=[...]` and then cache individually.
Suor··on Ban 1+N in Django
HN keeps automatically replacing the URL. It used to be a redirect before, but not anymore
Suor··on Ban 1+N in Django
Thanks
Suor··on Boiling React Down to Few Lines in JQuery
Using framework has its cost, so you can be better of if you understand clearly what you are doing. OTOH, framework brings structure so it's less probable you skrew up your design.
Suor··on Boiling React Down to Few Lines in JQuery
There are sure some things I haven't covered. The major one is components, which make a big deal in factor, reuse and composition. But the post started to be too long and loosing point so I skipped it.

There are also ideas beyond React I left aside. I will probably write some follow up post later.

Suor··on Ask HN: Why my link disappeared from HN?
I've already emailed there, won't make a difference probably anyway. I hate this HN tricky rating, one my post got dumped from top 5 cause there were too many comments!

Reddit kind of saves the day :)

Suor··on Ask HN: Why my link disappeared from HN?
I announced on twitter and posted to reddit. Is this prohibited?
Suor··on Ask HN: Why my link disappeared from HN?
Maybe english?
Suor··on Ask HN: Why my link disappeared from HN?
Is there something wrong with it?
Suor··on Why Every Language Needs Its Underscore
OTOH, if the program logic is mapping a sequence, then you better use map() on the sequence.
Suor··on Why Every Language Needs Its Underscore
It's not lazy, it returns iterator. There is a difference, you can't slice or index its result anymore. Compare to Clojure or Haskell map, which are truly lazy.
Suor··on Why Every Language Needs Its Underscore
No it won't, unless you `tee` an iterator first.
Suor··on Why Every Language Needs Its Underscore
It's easy cause it's familiar. But it's not simple.

This excellent talk by Rich Hickey explains the difference http://www.infoq.com/presentations/Simple-Made-Easy

Suor··on Why Every Language Needs Its Underscore
If core is small then such language should provide a way to extend it outside. Like macros.
Suor··on Why Every Language Needs Its Underscore
Just

    zip(seq, seq[1:])
Won't work with iterator though.
Suor··on Why Every Language Needs Its Underscore
It doesn't need direct port. But it can take advantage borrowing ideas or library design principles.
Suor··on Painless Decorators in Python
The first part of a post is mere reasoning showing how I got to the actual interface I use. @decorator works with `call` not with `func, args, *kwargs`.
Suor··on Painless Decorators in Python
funcy doesn't preserve function signature. The only way for now to do this is to use exec, e.g. compile code from source or AST, which I choose to avoid.
Suor··on Painless Decorators in Python
You will still need a wrapper function and update it's metadata. Which is even more boilerplate. Or you can hide that in base Decorator class, but then we'll back to another layer of abstraction.

So it's either more boilerplate or more abstraction. Choose exactly one.

Suor··on Painless Decorators in Python
This handles decorators with arguments and makes a general case of passing same arguments to function as to wrapper less cluttered.
Suor··on Painless Decorators in Python
This looks like even more boilerplate.
Page 1 of 2Next →