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 6y ago · link · parent

Nice to see we all copied that from perl.

comment 6y ago · link · parent

I sometimes use DDG for getting a UUID too :)

https://duckduckgo.com/?q=uuid&t=hj&ia=answer

If you like that kind of things and you dig Python, the lib "faker" (https://faker.readthedocs.io/en/master/) is a real threat:

  from faker import Faker
  fake = Faker()

  fake.name()
  # 'Lucy Cechtelar'

  fake.address()
  # '426 Jordy Lodge
  #  Cartwrightshire, SC 88120-6700'

  fake.text()
  # 'Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi
  ...
There are many different generators, and you can even use l10n to generate names, phone numebers, plates, IP or ssn from different parts of the world.

It's amazing to create test data, either for dev or teaching, and I just have it autoimported in my PYTHONSTARTUP because of it.

It also plays well with "factoryboy" (https://factoryboy.readthedocs.io/en/latest/) to mass generate complex data set, and even add them automatically to the database.

comment 6y ago · link · parent

Don't worry, in 15 years they will use all the money they gained doing this, and start acting well again. Better even.

And everybody will forgive, and people will defend them on HN for being redeemed, and they will be alright.

That's been the trend.

comment 6y ago · link · parent

At twitter scale, doing anything is costly.

comment 6y ago · link · parent

Well, you can put catchas in case you doubt there is a bot activity.

They also have so many phone number and email they can use that to do additional checks.

They you can use the network effect: bots usually have something in commons: topics, likes, ip, followers...

If you have millions at your disposal, something can be done.

They are not, so I'm more encline to assume there is benefit for them to avoid doing so.

comment 6y ago · link · parent

Would you keep a bot that just massively upvote things so that they reached frontpage, then rented to the higest PR firm bidder?

comment 6y ago · link · parent

Fair enough and very honest.

> But this is a global parameter across all queues so this means we essentially loose the one good feature of celery for small tasks which is retrying lost tasks within some acceptable timeframe.

Oh, for this you just setup two celery deamon, each one with their own queues and config. I usually don't want my long running task on the same instance than the short ones anyway.

> We were also excited to use it's chaining and chord features but went into a series of bugs we couldn't dig ourselves out of when tasks crashed inside a chord (went into permanent loops). I just declared bankruptcy on these features and we implemented chaining ourselves.

Granted on that one, they not the best part of celery.

Just out of curiosity, which broken and result backend did you use for celery?

I mostly use Redis as I had plenty of problems with Rabbit MQ, and wonder if you didn't have those because of it.

comment 6y ago · link · parent

I don't see how you came to this idea. The jobs can be as long as you want, you can have retry, persistant queues, priorities, and dependancies.

Of course, I would advice to put a dedicated queue for very long running tasks, and set worker_prefetch_multiplier to 1 as the doc recommand for long running tasks: https://docs.celeryproject.org/en/stable/userguide/optimizin...

With flowers (https://flower.readthedocs.io/en/latest/), you can even monitor the whole thing or deal with it manually.

I assume your comment is reporting on other comments, but not direct experience?

comment 6y ago · link · parent

Sure, this will remove one problem: type/domain squatting.

All the other ones remain.

I can't wait for Stackoverflow spamming to get the scammers answer with a legit solution + url + hash at the top of Google search when typing the name of the package.

Before that, you'd install from npm.

But now, any URL is fair game.

I'll get the pop corn.

comment 6y ago · link · parent

Wait, you only have a couble hundred jobs, but don't want a single point of failure, but think a database is too much, but talk about cloud hosting?

This all seems contradictory.

Personnaly, using Python, I go for Celery (www.celeryproject.org): it's a persistant daemon that can run tasks, provide queues and shedule work like cron .

A lot of people prefer Python-RQ, as it seems simpler, but the truth is you can start using celery with just the file system for storing tasks and result:

https://www.distributedpython.com/2018/07/03/simple-celery-s...

If your needs grow, you can plug it to redis, rabbit MQ and/or a database later.

It can expose an API so that other languages can talk to it and trigger tasks or retrieve results (but not write tasks, they must be in python).

comment 6y ago · link · parent

> Can you install any script from arbitrary urls using pip?

You don't need to. Download any module or packgage, put it next to your code, and you can import it. There is nothing to do. There is not even need for metadata.

But yes, pip can install packages from arbitrary URLS, including git repos, if they contains the right metadata.

What's more, with something like shiv (https://github.com/linkedin/shiv), you can actually bundle those dependancies into one zipapp (an official python feature, see https://docs.python.org/fr/3/library/zipapp.html), which is basically a zip containing your entire project that you can just execute like if it were one py file.

comment 6y ago · link · parent

I've felt exactly that while testing Vite (https://github.com/vitejs/vite) this morning from Evan You, author of VueJS.

Standard install, nothing to configure, instant hot reload + modern code and tooling yet no perceivable latency for anything.

It felt like suddenly I could enjoy front end dev.

So I get the appeal of Deno.

But I know this ability to put arbitrary URLs as dependancies in the code are going to be terribly missused and abused.

I can see all the tutorials that will start including them, the bad architecture decisions that will spread them accross all files, the interns that will use localhost there, the typo and domain squatting or black SEO, the rise of people just telling you to put an URL from their site (the same that tell you to curl that bash script), the split from npm, the hardship of scanning/mapping/updating dependancies, the mismatch betwen running and installing bitting you, the undebuggable tickets because of proxies/antivirus/firewalls, the cloud hosting potential for failures, some twisted scenario leading to a DoS...

I know it will cause horrible technical debt down the road.

My spider dev sense is tickling and I'm not going to touch this tech for 5 years, until I either see my prediction unfold, and be completly disproved by its success (but I doubt it, I've been really good in the last 10 years at spotting bad technical choices).

There is a reason we have been using separation of concerns since the down of time. Declaring dependencies, installing them and importing them are 3 different concerns. They should not mix.

comment 6y ago · link · parent

If that bothers you, use sigle dispatch.

comment 6y ago · link · parent

You can make it easy to deal with text file without lying to your API users. open("foo", mode="t") could become open("foo").as_text().

Besides, Python has pathlib now, which allows you to do Path("foo").read_text() for quick and dirty text handling already.

comment 6y ago · link · parent

The problem is not "text mode by default". The problem is that the API offers a text mode at all.

Opening a file should return an object that gives you bytes, and that's it.

This "mode" thing is idiotic, and leak a low level API that makes no sense in a high level language with a strong abstraction for text like Python.

Text should decoded from a wrapping object. See my ohter comments.

comment 6y ago · link · parent

    with open('text.txt','w').as_text() as f:
       f.write("text")

comment 6y ago · link · parent

A student don't know anything about mutability, and since Python signatures are not explicit, there is no way to know they have to do that.

It's just something to be told. A design decision, like there are thousands to learn in IT, that you just can't guess.

comment 6y ago · link · parent

Chardet, written by mozilla, already detect encoding if you need such thing.

comment 6y ago · link · parent

The open() API is inherited from the C way, where the world is divided between text files and binary files. So you open a file in "text" mode, and "binary" mode, "text" being the default behavior.

This is, of course, utterly BS.

All files are binary files.

Some contains sound data, some image data, some zip data, some pdf data, and some raw encoded text data.

But we don't have a "jpg" mode for open(). We do have higher API we pass file objects to in order to decode their content as jpg, which is what we should be doing to text. Text is not an exceptional case.

VSCode does a lot of work to turn those bytes into pretty words, just like VLC into videos. They are not like that in the file. It's all a representation for human consumption.

The reasoning for this confusing API is that reading text from a file is a common use, which is true. Espacially on Unix, from which C is from. But using a "mode" is the wrong abstraction to offer it.

If fact, Python 3 does it partially right. It has a io.FileIO object that just take care of opening the stuff, and a io.BufferedReader that wraps FileIO to offer practical methods to access its content.

This what what open(mode="b") returns.

If you do open(mode="t"), which is the default, it wraps the BufferedReader into a TextStream that does the decoding part transparently for you, and returns that.

There is an great explanation of this by the always excellent David Beazley: http://www.dabeaz.com/python3io_2010/MasteringIO.pdf

What it should do is offering something this:

    with open('text.txt').as_text():
open() would always return BufferedReadfer, as_text() would always return TextStream.

This completly separates I/O from decoding, removing confusion in the mind of all those coders that would otherwise live by the illusionary binary/text model. It also makes the API much less error prone: you can easily see where to the file related arguments go (in open()) and where to text related arguments go (in as_text()).

You can keep the mode, but only for "read", "write" and "append", removing the weird mix with "text" and "bytes" which are really related to a different set of operations.

comment 6y ago · link · parent

Thanks. French here. Can't edit anymore though

comment 6y ago · link · parent

You can easily distinguish them:

    if isinstance(msg, str)
So I don't think that's a good argument for not accepting iterables of strings in str methods. Things like replace() would benefit a lot and it's not that hard to do, you can even accept regexes optionally: https://wonderful-wrappers.readthedocs.io/en/latest/string_w...

I agree that iterating on string is not proper design however. It's not very useful in practice, and the O(1) access has other performance consequences for more important things.

Swift did it right IMO, but it's a much younger language.

I also wish we stole the file api concepts from swift, and that open() would return a file like object that always gives you bytes. No "b" mode. If you want text, you to open().as_text(), and get a decoding wrapper.

The idea that there are text files and binary files has been toxic for a whole generation of coders.

comment 6y ago · link · parent

Python is interpretted, not compiled, and completly dynamic. You cannot check much statically.

In fact, any program can replace anything on the fly, and swap your string for something similar but mutable.

It's the trade off you make when choosing it.

comment 6y ago · link · parent

It if was such a righ call, why did it die ?

comment 6y ago · link · parent

It's hard to strike a balance for this.

For many FP programmers, the lambdas are not nearly magic enough.

In Swift, you can do something like this :

    reversedNames = names.sorted(by: { $0 > $1 } )
It's a closure expression, and is an anonymous block of code that will magically bind parameters passed to it to numbered variables.

So you see the position Python is in: it has to balance a bit of magic for the power user, and yet not too much for the casual user.

It's a very delicate exercice, and it receives a lot of critics for it.

An F# or Lisp dev comming to Python will complain that it's not expressive enough.

A geographer comming to Python will struggle reading advanced code.

Yet we have to catters to all of them, give the huge Python popularity and it's goal to be "the second best language for everything".

I think Guido did a very decent job at it, although he gets a lot of heat for it. People don't like to hear "no" when they ask for a poney.

And the lambda expression is one of the most controversial decisions. Beginners have a hard time with it, but professional coders may snap when they hear it's limited to one line.

comment 6y ago · link · parent

No, but it is possible to write Python 2 code than runs in Python 3.

In fact, the vast majority of popular libs had a 2/3 compatible code base for a few years.

The hard part was not the syntax in fact. It's pretty trivial: the language are not that different.

The hard part is the I/O stack, because the stdlib is very different, espacially for this part.

comment 6y ago · link · parent

I missed that it was serie, indeed.

comment 6y ago · link · parent

Hey!

https://xkcd.com/1053/

And honestly, I would be rich if I got a dollar every time a student does this:

    msg.upper()
Instead of:

    msg = msg.upper()
And then call me to say it doesn't work.

comment 6y ago · link · parent

First, there are not a lot of interpretted (not compiled, that's another matter entirely) languages that are as old as Python.

And there are really few that are even near Python popularity, or used with such diversity as Python.

I mean, you can get away with keeping AWK the way it was 2 decades ago, nobody is going to use it for for machine learning or to teach computing in all universities in the world on 3 operating systems, utilizing C extensions, or processing Web API.

Among the few that would even compare, there are the ones that have accumulated so much cruft that they became unusable from today's standard (E.G: bash). Then you have those who have done like Python (E.G: perl 6). The ones that just tried and failed (PHP 6). The ones that broke compat and told everybody move or die (Ruby in a point release, gave basically 2 years). And the ones that created a huge pile of horror they called full stack to keep going (E.G: JS). Also those that got hijacked by vendors and just exploded in miriads of proprietary syntaxes (E.G: SQL) or completely new concepts (E.G: lisp).

At least, in Python you CAN write Python 2/3 compatible code, and you have a LOT of tooling to help you with that, or migrating.

So, yes, the Python 2 -> 3 transition could have been better. Insight is 20/20.

But I'm struggling to think of any other language in a similar situation that has done better.

comment 6y ago · link · parent

If x is near your memory limits, and you do y = x[:-1], you will get a MemoryError :)

For those situations, bytes() + memoryview() or bytearray() can be used, but then you are on your own.

comment 6y ago · link · parent

People like this need to be put into managing a team of visual basic devs at an obscure local DMV IT department, and force them to make projects after projects until they realize that if they want something done in those situations, they have to get dumber.
1
162163164
184