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

While the design of Curio is quite interesting, it's may not be a good choice, not for technical reasons, but for logistical reasons: the chances it gets a wide adoption are slim to None.

And since we are stuck with colored functions in python, the choice of stack matters very much.

Now, if you want easier concurrency, and a solution to a lot of concurrency problems that curio solves, while still being compatible with asyncio, use anyio:

https://anyio.readthedocs.io/en/stable/

It's a layer that works on top of asyncio, so it's compatible with all of it. But it features the nursery concept from Trio, which makes async programming so much simpler and safer.


anyio is also compatible with asyncio and Trio, so you can use it with either library or paradigm.


Uvloop/uvicorn - which is the production grade asgi server only works with asyncio.

Hypercorn works with trio..but you lose a LOT of performance


I used them both extensively, and here are the main reasons I can think of:

- The event loop in JS is invisible and implicit. V8 proved it can be done without paying a cost for it, and in fact most real life python projects are using uvloop because it's faster than asyncio default loop. JS dev don't think of the loop at all, because it's always been there. They don't have to chose a loop, or thinking about its lifecycle or scheduling. The API doesn't show the loop at all.

- Asynchronous functions in JS are scheduled automatically. On python, calling a coroutine function does...nothing. You have to either await it, or pass it to something like asyncio.create_task(). The later is not only verbose, it's not intuitive.

- Async JS functions can be called from sync functions transparently. It just returns a Promise after all, and you can use good old callbacks. Instantiating a Python coroutine does... nothing as we said. You need to schedule it AND await it. If you don't, it may or may not be executed. Which is why asyncio.gather() and co are to be used in python. Most people don't know that, and even if you know, it's verbose, and you can forget. All that, again, because using the event loop must be explicit. That's one thing TaskGroup from trio will help with in the next Python versions...

- the early asyncio API sucked. The new one is ok, asyncio.run() and create_task() with implicit loop is a huge improvement. But you better use 3.7 at least. And you have to think about all the options for awaiting: https://stackoverflow.com/questions/42231161/asyncio-gather-...

- asyncio tutorials and docs are not great, people have no idea how to use it. Since it's more complex, it compounds.

E.G, if you use await:

With node v14.8+:

    await async_func(params)
With python 3.7+:

    import asyncio 

    async def main():
        # no top level await, it must happen in a loop
        await async_func(params) 

    asyncio.run(main) # explicit loop, but easy one thanks to 3.7
E.G, deep inside functions calls, but no await:

With node:

    ...
    async_func(params)

With python 3.7+:

    ...
    # async_func(params) alone would do nothing
    res = asyncio.create_task(async_func(params))

    ...

    # you MAY get away with not using gather() or wait()
    # but you also may get "coroutine is never awaited"
    # RuntimeWarning: coroutine 'async_func' was never awaited
    asyncio.gather(res)
Of course, you could use "run_until_complete()", but then you would be blocking. Which is just not possible in JS, there is one way to do it, and it's always non blocking and easy. Ironic, isn't it? Beside, which Python dev knows all this? I'm guessing most readers of this post will have heard of it for the first time.

Python is my favorite language, and I can live with the explicit loop, but explicit scheduling is ridiculous. Just run the damn coroutine, I'm not instantiating it for the beauty of it. If I want a lazy construct, I can always make a factory.

Now, thanks to the trio nursery concept, we will get TaskGroup in the next release (also you can already use them with anyio):

    async with asyncio.TaskGroup() as tg:
        tg.start_soon(async_func, params)
Which, while still verbose, is way better:

- no gather or wait. Schedule it, it will run or be cleaned up.

- no need to chose an awaiting strat, or learn about a 1000 things. This works for every cases. Wanna use it in a sync call ? Pass the tg reference in it.

- lifecycle is cleanly scoped, a real problem with a lot of async code (including in JS, where it doesn't have a clean solution)


> Python is my favorite language, and I can live with the explicit loop, but explicit scheduling is ridiculous. Just run the damn coroutine

You can't "just run the damn coroutine", that's not what coroutines are.

But that does point to the mistake of Python, at least from a UX perspective: coroutines are more efficient but they're also a lot more prone to use errors, especially in dynamically typed languages. Async functions should probably just have been tasks, which is what they are in JS.


I know, but we could make coroutine creates with async have a special marker that is different to yield and auto schedule.


That’s what a task is.


I’m not an expert on Node.js but I was always under the impression that you couldn’t write await outside of an async function. Has that changed recently?


You can await at the top level of a module since node v14.8.

It has been proposed to Python: https://groups.google.com/g/python-ideas/c/PN1_j7Md4j0/m/0xy...

But I have no more info about it.


You are right that you can only await in an async function, but you can call an async function anywhere and get back a Promise.

await-ing that promise is often what you want to do but there are other ways to do work once the promise has resolved.


asyncio is not a competition to threads, it's complementary.

In fact, it's a perfectly viable strat in python to have several processes, each having several threads, each having an event loop.

And it will still be so, once this comes out. You will certainly use threads more, and processes less, but replacing 1000000 coroutines by 1000000 system threads is not necessarily the right strategy for your task. See nginx vs apache.


"Viable" as in "you have no other choice sometimes". This forces you to deal with 3 libraries each with their own quirks, pitfalls and incompatibilities. Sometimes you even deal with dependencies reimplementing some parts in a 4th or 5th library to deal with shortcomings.

I really don't care that much which of them survive, I just want to rely on less of them


No, it's just useful. They are techs with different trade off, and life is full of opportunities.


Python Zen = one obvious way to do it. Having a bunch of very different ones, each with serious disadvantages, is a bad look.


Zen of Python is an ideal, and at this point, kind of tongue-in-cheek.

This is the same language that shipped with at least 3 different methods to apply functions across iterables when the Zen of Python was adopted as a PEP in 2004.


There is at least some recognition in those cases that they introduced the new thing because they got it wrong in the old thing. That's different than saying they should co-exist on equal terms.


> That's different than saying they should co-exist on equal terms.

I'm not sure who is claiming that. Here's the OP we're replying to:

> They are techs with different trade off, and life is full of opportunities.


Yes, that says each has good and bad points and you should weigh them against each other in the context of your application, to figure out which one to use. I.e. equal terms.

Zen would be: pick one of the two approaches, keep its strengths while fixing it to get rid of its weaknesses, then declare the fixed version as the one obvious way to do it. You might still have to keep the other one around for legacy support, but that's similar to the situation with applying functions across iterables.

This is what Go did. Go has one way to do concurrency (goroutines) and they are superior to both of Python's current approaches. Erlang has of course been in the background all along, doing something similar.


It's a technical thread, not a political one. If you were so sure of your argument, you wouldn't use a throwaway.

Besides, it's weird, like saying we should not have int, float and complex, there should be one way to do it.

Just because those are 3 numbers doesn't mean they don't have each their own specific benefit.


int, float, and complex are for different purposes. async and threads paper over each others' weaknesses, instead of fixing the weaknesses at the start. Async itself is an antipattern (technical opinion, so there) but Python uses it because of the hazards and high costs of threads. Chuck Moore figured out 50 years ago to keep the async stuff out of the programmer's way, when he put multitasking into Polyforth, which ran on tiny machines. Python (and Node) still make the programmer deal with it.

If you look at Haskell, Erlang/Elixir, and Go, they all let you write performant sequential code by pushing the async into the runtime where the programmer doesn't have to see it. Python had an opportunity to do the same, but stayed with async and coroutines. What a pain.


Oh, you meant like, why don't Python didn't reimplement the whole interpreter around concurrency instead of using the tools it already had to find solutions to problems?

Well, that question is as old as engineering itself, and it's always a matter of resources, cost, history and knowledge.


Multiple threads with one asyncio loop per thread would be absolutely pointless in Python, because of the GIL.

With that said, sure, threads and asyncio are complimentary in the sense that you can run tasks on threadpool executors and treat them as if they were coroutines on an event loop. But that serves no purpose unless you're trying to do blocking IO without blocking your whole process.


It would not be pointless at all, because while one thread may lock on CPU, context switching will let another one deal with IO. This can let you smooth out the progress of each part of your program, and can be useful for workload when you don't want anything to block for too long.


This entire article is about removing the GIL


I read it as each process having multiple threads and an event loop. If the threads are performing I/O or calling out to compiled code and releasing the GIL, said GIL won't block the event loop.


In Python it would be pointless, but for example it's how Seastar/ScyllaDB work: each thread is bound to a CPU on the host and has its own reactor (event loop) with coroutines on it. QEMU has a similar design.


It's also (to my knowledge) how Erlang's VMs (e.g. BEAM) work: one thread per CPU core, and a VM on each thread preemptively switching between processes.


Probably nice if you haven't read the books, because the direction is spotless.

But if you are a fan of the original story, it's a spit in the face of a masterpiece.

The title, names and arcs are basically used for branding.

It was predictable, the Foundation cycle is mostly dialogs spanned over hundreds of years. Little details is given to action, and characters, which are superficially developed and serve mostly the purpose of a vehicle for history, die of old age every few chapters or so.

Very hard to adapt, and pretty much impossible to make money outside of the show, with the face of your actors, by selling toys or pretty symbols. Also, good luck keeping hooked the general public. There is no focus on sexuality, little humor, hardly anyone relatable, they talk a lot then goodbye.

So they made it a block buster. It sure can work, but it's not Foundation.


Oh boy, it's not just unentertaining, but a grotesque farce of what you get when you want to check all the bingo boxes for making something bankable, and in doing so, completely destroy the original content.

In the first minutes it's already game over: they try to get you interested in the human characters in a book where the main protagonist is an entire galaxy over centuries. All named persons are going to die every 3 chapters, I get that you can't get ROI on your expensive hot actors faces, but that makes no sense for the material you work with!


I've been fighting to keep Unity as long as I could, but it's now breaking too often so I accepted my gnome shell fate. It requires 10 plugins, one app, and manually crafted .desktop files to be usable, but ok, it's free software, I'll adapt.

I understand the rational to also push for wayland first now, but it breaks my workflow for things like autokey. We do need to move from X11, but once again, something I will have to work with.

And now Firefox is a snap, which is slow, has permissions problems all around (guaranteed the sandbox will break some addons), takes a lot of space, etc. Again, I get it, it's a perfect candidate to push the tech, and they need to solve user facing apps distribution problem with linux.

I like Ubuntu a lot. I donate to it. I don't want to migrate to Manjaro or something else. Ubuntu is the sweet spot for things working out of the box.

But with 21.010, I really feel like at least moving to Elementary or PopOS right now. Tried them, the first one can't install (EFI partition is too small), the second breaks on my machine.

I don't like KDE, so I guess, next is Xubuntu? Something else?


Pop!_OS just published 21.10 beta yesterday so you're in good luck.

https://www.reddit.com/r/pop_os/comments/q6xvv0/pop_os_2110_...

Having nothing but great things to say about this distro. Favorite Linux distro I've used.


Isn't pop also gnome? You can install pop shell which is an extension. It adds tiling, which isn't for everyone.

I'm like you don't like the fact that defaul gnome is so bad that I need a bunch of extensions. But I don't like KDE either, looks so inconsistent, too much pointless blurring and animation. However, I guess other choices are worse because they would have some other flaws that you can't even find extensions to work around.


I tried to install the pop shell, but it worked out badly. Those distro are not made to just have the DE installed after the installation of Ubuntu. Something always breaks.

You have to install from the official .iso


But it's not a DE just extension of Gnome? I've never actually tried Pop OS but after installing pop shell, I only got windows tiling. The only thing missing is the command palette which I don't really mind.


All those distros have different default settings.

E.G: full disk encryption is enabled by default when you install it, which is the opposite of most Ubuntu based distros.


Perhaps Ubuntu Mate with Mutiny?


Is that still maintained ? It was an experiment in 16.04 right?


It works out of the box for most hardware, install proprietary things easily, including drivers and codecs, and have more up to date softwares. It also have lots of usability tweaks.

You can, have all that with debian, but then you have to do the work.

I don't want to do the work if canonical can do it for me.


I installed debian just a few weeks ago on my brand new desktop. AMD Ryzen 5800x, MSI B550 motherboard, MSI Nvidia RTX 3060 Ti. Everything worked, out of the box, without adding anything magical. Including Ethernet, wifi, Bluetooth and hardware accelerated graphics. Have been buying Nvidia gpu's since forever and their (proprietary) drivers have never let me down.

So I'm not sure what you're talking about. Also, more up to date software, I'm quite certain my Debian Sid has more recent versions of everything compared to what Ubuntu has.


Yeah, I've met those kind of comments for 15 years.

There is always somebody to say that in those kind of threads. Same as Vi is easy, try Manjaro, Nix, this latest implementation of LISP, that NoSQL db, this DSL, etc.

I used to give them the benefit of the doubt, spend some time testing the alternative the person talked about, came out disappointed, and wasted time.

Now I just trust numbers. When 100 people like you will tell me the same for 3 years, I will try.

Before that, I'll stay on what I know works.


I use Linux distributions since 1995, starting with Slackware 2.0, there is always someone that tells that.

Hence why I mostly run Linux on VMs nowadays, and Android/Linux.


Have you considered Fedora?

I recently moved from Arch to Fedora and I have all the same up to date vanilla packages without having to do any real work.


I tried so many distros. None of them fit the bill for a pro laptop.

I don't want to move out of ubuntu based distros, they get too many things right.

I'd rather try Elementary, Pop OS, Xubuntu, etc.


I have heard great things about PopOS but haven't tried it personally. Hopefully you find the right distro for you.


Go for it! Those are great choices, you'll do fine.


In their mind it makes sense: firefox is a user facing app that is frequently updated and requires a lot of dependencies. Perfect candidate for a snap.

But yeah, up to now, snaps really sucked, and flatpak is winning.


Well, in this day and age of bazooka DMCA take down, it's refreshing to see a game author happy about his game being gutted, and put online to play.


> it's refreshing to see a game author happy about his game being gutted, and put online to play.

The game author is typically not the copyright holder.


Nah, design patterns are mostly communication tools.

When you name something "factory", when some doc mentions "dependency injection", when you import a "register", when you talk with a colleague about a "decodator", if you know the name, you already know what it does, and what the API will probably look like.

I say probably, because we don't have a format definition of all design patterns, nor are they all recognized as such. For for the ones that are and we do, we don't all agree. Not to mention you must adapt them to problems and languages.

So sure, when you code and you encounter a problem, you may use a design pattern. But you don't explicitly do so. Just like a chess master doesn't chose a move by thinking "I'm going to use x", they just decide on it, and also adapt it to the situation.

I never think about design patterns when I code, only when I name the code, I write the doc, and talk about it. When I communicate.

If you read a book about design patterns, they will make no sense to you. You will probably misuse them. But if you look at real life source codes from other devs, or yours again and again, you realize some problems come back often, and a lot of people use similar solutions. Then you look it up: bingo, it has a name.

That's how it works, not the other way around. It's formalization of real life, not theory to apply.


> Just like a chess master doesn't chose a move by thinking "I'm going to use x", they just decide on it, and also adapt it to the situation.

This is an interesting analogy maybe someone who knows more about chess can correct me, but don’t chess masters have elaborate memorized openings and end games where they do decide to use “the indian defense” then go on autopilot until someone deviates from the common lines?


The idea is that they won't tell themself, "I'm going to use the indian defense".

Just like I won't tell myself "I'm going to apply the strategy pattern here".

We just see the situation, and if it calls from a solution from the banks of solutions we have encountered in the past, we see if it fits, we try to apply it if it does (tailoring may be necessary).

Then the commentator later may say "oh, he decided to use Y". But that's for the benefits of the people watching.


I'm largely agreed with this, but to add on:

if you consider the idea source -- Alexander's A Pattern Language -- the notion of a pattern is a more useful than that; it is both a communication tool, as well as the realization that the problem (in his case, buildings) can be subdivided into smaller parts, and at a certain level, these parts fall into common repeating forms (patterns). You can thus mostly initialize the design by simply composing patterns together.

The key that typically gets lost in GoF pattern discussions is that it doesn't end there. Once the patterns are decided, you need to account for the non-standard details of the problem at hand -- e.g. the house is partly on a hill. The hill raises the height of the door. The door had a relationship with the window -- it's no longer aligned, and will have to be modified to fit. With the shift of the window, the mirrors need to change.. and with the mirrors, the door. Eventually these changes will stabilize, producing an equilibrium (TB: he declares that equilibrium to be "beauty", and a feature that everyone can innately detect, though they may not know how to reach it... this corresponds strongly to "code smell" or "elegance" in programming)

So the elements of the home starts as patterns, but they're also in a fluid state, and the effects of reality will trigger a feedback loop, creating continuous design reflows, until the whole thing reaches an equilibrium (and you can now build the house).

He then goes on to note that the home exists in a continuously fluid state (as it's used and changed by inhabitants), constantly deviating from that equilibrium, and being brought back into that state. So the most beautiful homes are those not designed into a harmonious state, but maintained in a harmonious state -- I particularly like the correspondence to programming here.


Yes, but even after the opening lines are exhausted, a huge part of expert chess play is just intuition and choosing which moves “look right”, rather than conscious thought and calculation (though that too has its place).


The equivalent of a standard chess opening would be a function call or some form of template in software engineering.


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

Search: