Hacker Newsnew | past | comments | ask | show | jobs | submit | more BiteCode_dev's commentslogin

The end user doesn't know that, and doesn't care.


Your boss is not your end user. The way your boss interacts with the emails you send is not the way your end users do. Optimising for your boss is not how this channel should work, though I appreciate there are a lot of bosses out there who don’t understand this.


I don't understand your point.

Are you complaining that his boss is forcing him to implement something that his end users can use?

If so, why isn't his boss right?

Personally, I'd say that yeah, he's supposed to work for his end user, why would he do anything else?


My point is that, from the perspective of email, you frequently receive internal feedback that doesn't correspond to how users actually use email.

For example, if the org uses desktop Outlook but < 1% of your audience does, is it worth optimising the email for that audience based on internal feedback?

If someone notices that something weird happens when an email is replied to or forwarded, is that something worth acting on based on the real world frequency of that action?


I'm not sure why the example starts with all those verbose calls to run_until_complete(). Why not do this?

    async def main():
    
        db = DB()
        await db.connect('db_name', {
            'host': 'localhost',
            'port': '5432',
            'database': 'db_name',
            'username': 'db_user_name',
            'password': 'db_user_password'
        }, default=True)

        await db.connect('other_db_name', {
            'host': 'localhost',
            'port': '5432',
            'database': 'other_db_name',
            'username': 'db_user_name',
            'password': 'db_user_password'
        }, default=False)

        db.connection('other_db_name')

        db.default = 'other_db_name'

        await db.stop()

    asyncio.run(main())
Am I missing something ? It's using asyncio.run() in other examples, so it assumes 3.7+ anyway.


They differ slightly in semantics; asyncio.run() always creates a new event loop to run the task, while run_until_complete() don’t (unless you call asyncio.create_event_loop() of course). I don’t know if this is the reason behind the decision, but the two are not equivalent (and there are cases asyncio.run() wouldn’t work).


Yes but await doesn't, which is what I replaced run_until_complete() with here.

The asyncio.run() is just to pretend I run the lib snippet in a code that already started the loop, which the doc seems to do.


At first, I though "this article just made me realized I didn't use the python itertools.tee to its full potential".

But then I tried to think of a code where I would rather use this than a list comprehension or yield and a more manual control flow.

And I couldn't.

Those streams are elegant when the business logic flows perfectly like a river. Unfortunately, reality is messy, and production code will have matching, conditions, casting, extractions and transformations all over the place, leading to:

- very long chains of calls

- hard to change code when feedback pushes for it

- limiting your tooling (specially debuggers) to stuff that have exceptional support of chaining, and it's rare


This article made me realise that I don't know how to perform step-through debugging on chained of operations on Streams in Java, so I looked it up. I found out that there's Stream Trace Dialog in IntelliJ IDEA [0]. I guess it proves your point that working with Stream API requires additional tooling in cases when the code doesn't 'just work'.

[0]: https://www.jetbrains.com/help/idea/analyze-java-stream-oper...


the ideal scenario with functional programming like this is to reason about the code, and may be algebraically model it mentally so that you "know" it works.

But i find a lot of programmers don't do that - but instead write a first version which they don't truly understand (or understand completely), and then use stepped debugging to tweak the program until they get to a verison that works to their desired outcome.


Ideal scenarios rarely exist IRL. You may be in a rush. Inexperienced. Tired. On a problem you don't completely understand yet. With incomplete information. Exploring data or the problem space. Experimenting with an API. Trying to debug the code your colleague wrote, or a bug in the underlying lib.

That's why practicality beats purity in the vast majority of situations.

There is a place for purity, but you need a hell of a setup.


The way out of this is called unit testing. Code like this is just over engineered crap without it. Most of the effort is writing good tests. Show me the test that tells me in a concise way what this is actually supposed to do.

Mostly purity in this context boils down to weird combinations of premature optimization or complete disregard for that. Mostly it doesn't matter of course since code like this runs on trivial amounts of data so giving the garbage collector a little more work with silly stream objects, boxing/unboxing, etc. does not matter. Code like this does not matter, at all. Unless it's wrong. Hence the need for tests. Without tests it's just more likely to end up in tears. With tests, it doesn't really matter what the code looks like as long as the tests pass. If it's convoluted without tests, it's a problem waiting to happen.


Tired won't make you write a proper test, not be a beginner, make you explore data more efficiently, etc.

In fact, it's very hard to write a test first when you are exploring.


Completely agree, streams are good for when you have a ( you guess it ) stream of things where you need to do a limited and well defined amount of things.


Funnily, I was thinking about this the other day with Python: python is great for scripting, with the generators, string formatting and stlib modules like pathlib, datetime or argparse.

But there are still stuff I use bash for because it's way more efficient for one liners and small utilities.

One of the things is that calling something in bash autoprints, unless you pipe it. Could it be done in Python?

Well, it turns out you can, if you do a little dirty hacking with __call__, __repr__, __iter__, __or__ and __del__, you get:

https://0bin.net/paste/XeMvMuSh#45izWhAtQ5Bd14PDWoBqTJMvHZXa...

Which will let you do:

-ls('/etc'), auto prints all the files in the dir, in the shell and in a program.

- ls('/etc') | keep(r'\.conf$'), pipe the output of ls, pass it to keep, filter it, then auto print it (again, works in the shell AND in a py file)

- res = ls('/etc') | keep(r'\.conf$'), store the generator in the variable, doesn't print, doesn't calculate, ready to be able to be read with a for loop

This means we could create a lib with a very shell like experience in python for all those 5-lines-scripts that are still too good to pass bash for.

We could also make a @main decorator to auto run a function if __name__ == "__main__", borrow the "with cd()" and "with temp()" syntax from the fabric lib.

The need for bash would get smaller and smaller for me. I rarely develop on a linux box that doesn't have python, after all.

Now a problem people often hit is: yes, but you have to provide the dependency to your script. ShellJS proves that despite that, it has a great value already.

But the good news is, it's not a problem anymore thanks to a great features of Python 3: zipapps. With shiv (https://shiv.readthedocs.io/en/latest/), you can bundle your python script and all its dependencies (including our dirty shell lib) in a single pyz file, which then can run anywhere there is a modern python, which is everywhere I personally need it.


> but instead people are re-inventing 'sqlalchemy'

SQLalchemy last version is asyncio compatible now: https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.htm...

> network libraries and entire web frameworks for the sake of two new keywords

The trend in the community now is SansIO: https://sans-io.readthedocs.io

You create entire libs without the IO parts, dealing only with the business logic.

The you let the I/O libs to deal with the rest. This allows modern project to provides a sync and async API with the same protocol implementation. E.G: https://github.com/encode/httpx

Also, I'm pretty glad gevent has not been adopted:

- it's very hard to know if you are doing something wrong with gevent. Or doing something with gevent at all.

- gevent magic patching broke stuff in unpredictable ways, and the solution was to disable part of it: https://stackoverflow.com/questions/8678307/gevent-monkeypat...

- gevent didn't play well with stdlib threads and multiprocessing, (had its own thread pool, subprocess wrapper, and no multiprocess story) while asyncio has a very good interoperability story

- the asyncio pluggable loop meant we didn't need a perfect solution out of the box. Thanks to that design, we have been able to integrate the nodejs loop, like with the uvloop project, giving birth to stuff like asgi, fastapi and uvicorn. Asyncio can now comparable async perfs as Go. (gevent does that, but forces you to, and having libuv in the stdlib is not something the core devs would want).

- gevent is a 5mo package. It's 1/6 of the ENTIRE python installer.

- the coroutine based design means we have a standard api for async, no matter the backend or implementation. Which means solution like trio were able to emerge, and eventually the core dev are now considering including trio-like scoping in the next asyncio iteration.

There are plenty of problems with asyncio though:

- create_task is basically a goto. See trio for a solution.

- coro() does not run the coro task. In JS it does, and returns a future you can await, or not. This makes it very confusing to beginner that get lost in the await/return/create_task dance.

- there is no concurrency limiting primitive, cancellation is hard and back pressure mitigation is non existent.

I was very skeptical about asyncio, but after 3.7, it became quite nice. asyncio.run() made all the difference, ergonomically, and when dealing with errors.


> gevent is a 5mo package. It's 1/6 of the ENTIRE python installer.

Oh no, that means I'll need 2 more floppies to distribute my software!


If core dev would accept such budget for one lib, given stdlib is composed of a lot of them, each python install would be enormous.

Not to mention python runs on constraints systems such as MicroPython, which features coroutines.

HN, the place were people complain about how electron is bloated then ask you do copy that.


> - the coroutine based design means we have a standard api for async, no matter the backend or implementation. Which means solution like trio were able to emerge, and eventually the core dev are now considering including trio-like scoping in the next asyncio iteration.

The structured API for concurrency that Trio provides, in principle, doesn't depend on the said keyword-based approach - it's just what the author chose to use for the implementation. It's definitely not something that asyncio enabled for its users that wasn't possible without it. Here's another structured API for concurrency that doesn't depend on keywords [1]. It can be implemented with gevent.

[1] https://hackage.haskell.org/package/async-2.2.3/docs/Control...


No, but it does mean that primitives in trio can be awaited in the same way than any async primitive instead of using a callback.

I get that scoping trough nurseries is the trio selling point, but you do need to have the ability to run something "before" and "after" a lone async call, and I don't want to have to write a "with" block to wrap any single thing that I wish to await.

By having "await" as a universal construct, we allow trio (or anything really) to offer an additional level of granularity - scoping a group of async calls - without losing the smaller one: scoping a single call.


> SQLalchemy last version is asyncio compatible now.

it's been compatible for 5+ years already, Core API was driver-endependent even in 2015.

> Also, I'm pretty glad gevent has not been adopted:

When I say 'adopted' I mean integrated into the language runtime so that the entire stdlib is aware of it. Some of your points consider the state of gevent 10 years ago, that's not a benchmark for a conclusion on how successful a potential integration into the core language might be, and none of them point at inherent issues with the implementation that make it unusable compared to asyncio.


> , that's not a benchmark for a conclusion on how successful a potential integration into the core language might be

That's fair.

I'm also biased by the fact I really like to know when my code is suddenly going into async territory.

I like the JS model for this: it's explicit enough that there is little surprise (promises are now a standard, so if something returns a promise, it's async), but implicit enough that I don't have to care (no loop to setup, no coroutine instantiation between calling and scheduling). And it aged well: future can now just be awaited, and you can simply keep the callback api in non async function.

gevent is too implicit to my taste I guess. Now you could argue that we could make gevent calls explicit, but then it would be not that much different from asyncio.

I would really be happy if the community would settle in something like:

    @autorun
    async def coro(): ...
Then:

    coro() # this calls create_task(), and binds it to the upper nursery
I think it would strike the right balance from a usability point of vue.

As for the interoperability issue, it's a pretty though nuts to crack.


TIL I'm almost a team by myself.


Weird article that basically says people are wrong then prove they are right.


Tablesample is not accurate as far as I remember.


I googled around, it isn't it gets complete pages with multiple rows so it tends to clump.


The code you are showing does a lot more than MV:

- it's portable accross OSes (and keep flags if the OS supports it, deal with encoding, etc)

- it ensures selinux context is saved if there is such a thing

- it has proper and rich error communication with the calling code

- it's includes documentation and comments

- it outputs json par parsing and storage

No to say "mv" is not awesome, because it is. There is much more boiler plate in python, and is why I'll often do subprocess.check_call(['mv', 'src', 'dst']) if my script is linux only.

But you are pushing it


To raise cows, you need crop. So real burgers already include the suffering from cropping, even more so because you need a lot more crop per calorie of you have a cow between you and the plant.

Now I want to emphasis that guilt is not a good reason to start with beyond meat.

The desire to try to do a nice thing can be, but as a vegetarian, it's important that people are not pushed out of meat because of some negative emotion.

I'd rather have happy meat eaters than frutsrated veggies.

But give it a try, just for curiosity sake.

I like the taste of BM, but find them hard to digest.

Also remember it's still process food, and organic free range steak is likely healthier.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: