Better HN
topnewbestaskshowjobs
Log inSign up

BiteCode_dev

24,628 karma · joined Oct 21, 2019 (7y ago) · 5,512 submissions

I write to save you time and effort when dealing with Python:

https://www.bitecode.dev/

Email: contact at bitecode.dev

Submissions

comment 5y ago · link · parent

The XWindow system is a collection of the worse api in the world so it's no surprise.

But the vast majority of modern command line tools agree on --long.

comment 5y ago · link · parent

They have different goals, nobody expect people to write a website ui with pyodine.

(although, python is my fav lang, and I wouldnt use brython either, 700ko to pay upfront before writing any code is too much)

comment 5y ago · link · parent

> go has popularized long args, with a single hyphen (-name etc)

Why did they do that?

It took us 20 years to standardize on - for short and -- for long, with occasional finger rage on tar or find, and now this?

What were they thinking?

comment 5y ago · link · parent

Thank you for sharing this, I just adopted it.

comment 5y ago · link · parent

Best way to make dev do that is to make it easy for them.

E.G: I used to "spray my files in the home dir" for my apps, until I discovered "appdirs" (https://pypi.org/project/appdirs/1.4.0/). Once I had an easy way to always has a clean and correct path for my app config/data/tmp file, I just used it.

comment 5y ago · link · parent

Also, Basthon: https://notebook.basthon.fr/

comment 5y ago · link · parent

"Statistically, most of us are building applications that won’t make a Raspberry Pi break a sweat."

I keep repeating that, but the dev community is really susceptible to the "temporary embarrassed billionaire" syndrome.

comment 5y ago · link · parent

The entire VM is different:

- you can replace builtins in python. - you have __dunder__ methods and multiple inheritance. - JS has an ever running event loop and is async by default. - python is more strickly typed.

It's not impossible (see brython), but it's not easy either.

comment 5y ago · link · parent

Brython => a JS Python implementation. It will not behave like cPython for somethings, does not have access to the whole stdlib nor the scientific stack. But it is quite small (700ko without their stdlib) and has native bindings to the DOM. Use it if you feel like writing your web page in python (I wouldn't, I love python but 700ko+ with no framework loaded yet is way too much).

Pyodine => the cpython implementation, but compiled to wasm. It's very heavy (10Mo), but it brings the real, whole cpython implementation in the browser so it will behave the same and have the entire stdlib. It also comes with optional NumPy, Matplotlib, pandas, SciPy, and scikit-learn. Use it if you want people to write python in the browser, but don't want to expose your server to their code.

comment 5y ago · link · parent

Someone is going to quote fooled by randomness in 3, 2, 1...

comment 5y ago · link · parent

And just like that, flash is back

comment 5y ago · link · parent

Very impressive. It will hard to balance realism and readability though.

GTA uses some surrealist contrasts because it makes the games easier to play, especially for long hours, or when you go fast.

But the tech is so new I'm not going to complain, it's already very good, especially given what it eats in resources.

comment 5y ago · link · parent

See also: mega churches in the US.

comment 5y ago · link · parent

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

comment 5y ago · link · parent

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.

comment 5y ago · link · parent

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.

comment 5y ago · link · parent

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.

comment 5y ago · link · parent

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.

comment 5y ago · link · parent

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.

comment 5y ago · link · parent

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

comment 5y ago · link · parent

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.

comment 5y ago · link · parent

> , 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.

comment 5y ago · link · parent

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.

comment 5y ago · link · parent

> 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.

comment 5y ago · link · parent

TIL I'm almost a team by myself.

comment 5y ago · link · parent

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

comment 5y ago · link · parent

Tablesample is not accurate as far as I remember.

comment 5y ago · link · parent

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

comment 5y ago · link · parent

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.

comment 5y ago · link · parent

People that have this need have the skill to install the required tool.
1
141142143
184