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

> Beware and use Django until you’re sure you AND your team know what you’re doing.

That's one of my pet peeve in the Python world: people thinks Flask is for beginners and Django for advanced users. The Flask API is simple, the hello world is 5 lines. By the time you render your first Django ViewModel, you have read and tried out the full Flask doc.

So it's easy to say, "I'll start with Flask, and check out this Django thing later".

But in reality, it's exactly the opposite. Flask requires you to know a lot of things and make a lot of decisions, not to mention select/write additional libraries for features Django packs.

So if you use Flask for anything non trivial, you should show your trade or you are going to mess up, big time.

If you are a beginner, you should always start with Django. Yes, it's more work up front, but it will give you an idea of how important concepts work, plug in to each others, and can be organized in a code base.

Django is not perfect, and its ORM is really far from SQLAlachemy, but it's good enough for a loads of thing. And it will be mostly secure and extensible by default.


100%

The upfront cost of Django makes people thing it's much more complicated than a micro-framework like Flask.

I like Flask, but not because it's a simple easy to use framework, especially once you chuck SQLAlchemy into the mix. Shit, even now if I don't touch it for a while I end up trying to remember how things work


If you don’t use Django’s ORM or SQLAlchemy’s ORM, then do you really need to use Django?

Like an adjacent commenter said, ORM is ok for simple blog websites. But I can’t imagine using an ORM for complex data tables and relationships with normalized data.


I used the Django ORM for surprisingly complex applications

I created a video streaming website, with 600k visitor days, that features tagging, categories, related vidéos, user upload, encoding queue, search with auto-completion and so on. It relies heavily on the ORM.

Django migration system and db model generation also make it a very nice tool for data export/migration/exploration.

The ORM provides a nice API, but above all, a standardized one, which lead the Django ecosystem to become so reach because of the assumptions the libraries could do, making you very productive.

Now, one has to remember:

- you can, and should by pass the ORM if you need it, writing raw SQL. Django let you do that.

- plenty of things can end up be in a cache, using varnish, redis, etc. Plus a lot of things should be done in task queues anyway, not in the django views. So the cost of the ORM is rarely an issue.

- complex data tables are sometimes better presented using SQL views, making the ORM model simple.

As usual with coding, it's a matter of gain and cost, and the right answer is "it depends". But you can go very far, and very comfortably with this tools, as long as you don't fight against its nature.

So yes, definitely use Django with the ORM. I am not advocating to use Django + SQLA, but rather contrast Django with Flask + SQLA.


>But I can’t imagine using an ORM for complex data tables and relationships with normalized data.

Whenever I read a statement like this from someone, I always feel that they actually haven't thoroughly read the docs for Django's ORM. Can you give me one concrete complex example that you can't imagine doing with the ORM? Because 95% of the time, these "complex" models are trivially easy to pull off with the ORM (from my experience).


Django orm doesn't support composite primary keys.


The beauty of the Django ecosystem, is that you have packages for everything: djangopackages.org

E.G: https://github.com/Arisophy/django-compositepk-model


Fair enough. There is `unique_together` though, which you may look into.


In the context of database transactions, any APIs serve only as backend endpoints. For this purpose I question whether flask is the best choice. For rest API, I always go for Falcon.


While I do keep my eyes on FastAPI, even in this case I would recommend Django to a beginner, solely because of the amazing Django Rest Framework.

Not only it makes creating an API from ORM models quick and easy (although the documentation doesn't let you believe so), but it also let you do custom views seaminglessly, including goodies such as standardized permissions, authentication and pagination with several levels of granularity. Having that being able to be integrated with all the rest of the Django ecosystem transparently (your website, a wagtail CRM, etc.) is really sweet.

But the biggest advantage for a beginner is again that it will prevent them from having to make decisions they are likely to get wrong. Especially on the serialization, format, identifier policy and homogeneity of the API: people crafting that by hand often make a big mess and don't even know about it.


It's more of a design issue here. You could do away from classes while keeping types by using 2 lines:

    Expr = Callable[[str]], Callable[..., Iterable[str]]] 
    AstNode = Expr | Callable[... ], Callable[..., Iterable[str]]]
You then don't event need to call representation() , as each node is callable. No classes needed.

But my instinct tells me a node will eventually have more attributes and methods. Stuff to get parents, children, siblings, filtering and so on.

So it's probably a good call to use a class for later. Also you want to keep AstNode as a node could be an expression, a statement or a comment.


> But my instinct tells me a node will eventually have more attributes and methods.

I couldn't agree more with Jack Diederich's thoughts on that sentiment, at 5:40 in the video linked above:

https://youtu.be/o9pEzgHorH0?t=340

> Lots of times people think they might need something later. You don't. Or, you can just do it later.


https://docs.python.org/3/library/ast.html

Experience helps with this.

It's a middle path as usual: naive approaches waste as much time as overenginering.


YAGNI is a double-edged sword. It's almost no additional overhead to write a class now if you think you might need to add methods and internal state later. But it's quite a bit of refactoring work if you decide not to write a class and then realize you need one after the fact.

Maybe this is an indictment of Python as a language, but I think it's a case of not taking anything too literally. YAGNI fetishism is like DRY fetishism all over again.


I guess? At the same time, working in some languages (Racket and C come to mind), it's surprising how long I can go without anything ever becoming a class, ever. Seemingly indefinitely.

My sense is that many of us are taught to think in terms of classes and methods instead of data structures and functions, so it's very easy to slip into thinking you need objects in order to manage state, even when that's not the simplest way to do it.

Strictly speaking, though, I think that the only time in Python that you really have no workable alternative to classes is when you also need dynamic dispatch.


Personally: it's much easier to YAGNI in languages with relatively-strong compile-time checks and relatively-sophisticated tooling.

If you lose either of those, a little bit of preventative work goes a loooooong way. The friction (largely due to risk) of correcting things later is so large that it just starts snowballing unless your team is extremely attentive.

In that sense, Python is... middle of the road, with an extremely broad spread. Tooling is an odd blend of surprisingly good vs incapable of doing simple inference / detecting all calls, and type safety depends heavily on how you write things (some tactics are fairly strong, many are so weak as to be useless or make things much worse).


Personally:

Python has a great type checker. Several, actually. They're not compile time, because Python doesn't exactly have a compile time, but still. 11/10, use everywhere, spend less time on unit tests, be happy.

Second, to me, these sorts of concerns about refactoring are. . . maybe not a smell, but worrisome, all the same. They suggest poorly-modularized designs with no internal component boundaries that might have limited the scope of impact of such a change. That said, even if you do find yourself needing to do a far-reaching refactor like that, refactoring in a dynamic codebase isn't necessarily harder, it's just different. Not being able to lean on the compiler to help you boil the ocean, for example, is fine, because boiling the ocean wasn't necessarily the best approach in the first place. The strangler pattern will help here, not just with type errors, but also with other problems the compiler might not have been able to help with, and will also be friendlier to the people who do your code reviews.


> Python has a great type checker. Several, actually. They're not compile time, because Python doesn't exactly have a compile time.

Python does exactly have a compiler time, since it actually compiles things.

The typecheckers are run before that (but I think that's usually true of “compile time” checkers, too, they just don't break between checking and compilation; the analysis I would imagine almost invariably comes before actually generating compiled code; especially for languages where, unlike Python, typing effects what code gets generated rather than only whether the typechecker passes or fails.)


To echo the sibling - I believe the most important skill a developer can have is reworking* code, and doing it readily and continuously. If you can do that, then you don't ever have to worry about what code MIGHT do in the future, you just design it for what it DOES do and then rework it later if necessary. It's quicker and the result is cleaner. Also, even if you tried your hardest to predict what was going to be needed, there are always things you can't predict and at that point you either rework your code or have bad code.

* I could have said refactoring, but some people have very specific definitions attached to that word so I use something more general here


I don't think most users expect their chat app to be protected if the police seize their phone.

The main concern is about intercepting messages between 2 parties or mass exploiting the history stored by the provider.

Sure, for some case, it can be important, but that's a much more difficult and rare threat model to address.


Love this app. Recently, it became less and less usable, with deal breaker bugs like mails not sending reliably or at all.

So I'm going to donate, because this app is fantastic and I really want it to keep existing.


That's basically what modern JS frontend frameworks do as well. I suppose as soon as something becomes too complex, keeping track of all interactions is just too complicated and rerendering the entire world efficiently looks like an easier problem to deal with.

I like the current trend of going back to renderless components as well. This way you separate the state changes from the way it looks like. Feels like each component is a miniature MVC framework with front and a back.


> I suppose as soon as something becomes too complex, keeping track of all interactions is just too complicated and rerendering the entire world efficiently looks like an easier problem to deal with.

In fact, it can actually be less work, since you're coalescing changes into a single update() call rather than sprinkling them across observer callbacks. Also, if your update function starts running too slowly, you can always make it more precise by keeping track of which states have changed internally to the view. For example, if setting the background color takes a long time for whatever reason, you can do something like this:

    def View.update():
      if self.lightWasTurnedOn != model.lightTurnedOn:
        if model.lightTurnedOn:
          self.backgroundColor = red
        else:
          self.backgroundColor = ibmGray
        self.lightWasTurnedOn = model.lightTurnedOn
Now backgroundColor will only be set if lightTurnedOn actually changed since the last update.


Google has earned billions thanks to techs like python, and never contributed much to it compared to what it gained.

Then suddenly this.

Now I'm wondering if MS hiring Guido triggered some reaction to not loose control of what is currently one of the most popular language in the world. Or something else I don't know about.

I really want to rejoice. My favorite language gets $ 350k.

Yet I can't help but be suspicious of philanthropy coming from big players. I'm getting cynical and always look for a PR, strategic investments or counter attacks.


The Python Software Foundation ordinarily raises funds via PyCon sponsorship, but PyCon was online last year and this year and who knows about next year, so in-person booths are much less valuable. Therefore, the PSF has been trying to switch to direct sponsorship. Google has been sponsoring PyCon at a high level for a long time.

Also, Google uses Python heavily and employs at least one Python core dev off the top of my head (almost certainly quite a few more), so there are engineers there with a sense of the PSF's finances and enough seniority to influence folks who decide on donations.

That's the most obvious angle to explain this. It's a strategic investment - Google cares about Python and they know the PSF needs money.


It's probably "now" because it's the sponsorship program got revamped, see https://www.python.org/psf/sponsorship-new/

They probably get their logo on the python.org website somewhere, and $350k isn't a ton of money. p The reason is PR. Still, good for the python foundation to have a program that allows it to harvest some of the PR budget out there.


Right. It's a good thing for the psf and it doesn't look like there a string attached.


I normally think overanalyzing where organizations spend their money is misguided, but I was surprised that the largest dollar amount on the infographic was spent "strengthening trademarks".

Here's what I found under the details link. Does anyone understand what this actually means?

> One major component of the PSF’s mission is protecting Python-related intellectual property. To strengthen the PSF’s trademarks and copyrights for Python, PyCon, and PyPI, the PSF spent over $198,000 USD in 2019 and $77,000 through October 2020.


It's probably mostly money paid to lawyers (to do various legal tasks associated with maintaining the trademarks).


Everyone uses Python it is probably the most used language ever. I think it is really nice that Google gave the organisation some cash. If Google are trying to buy some goodwill in the developer community it is working.


They earned billions and gave $350k? Actually it says $150k for Visionary.

If it was 2 billion then they contributed less than 1/500th of what they received.


Not sure what is so "downvotable" about the parent comment. It merely states a calculation result. Is it factually wrong or something? Anyone care to explain? Personally I would have gone further and called it "peanuts" for Google.


Currently you have 2 options:

- https://beeware.org/

- https://kivy.org/

I doubt Google is going to sponsor any though.


If the browser supports JS, maybe you can quickly generate uuid based on the same pattern, load the favicon as data url and with onload, check if it's in cache. This would make it significantly faster.


Great idea but favicons used in meta-tags does not support the onload event! I've found a workaround for this but it's only working in chrome. ~jonas


Some httpie tricks:

Use --offline to see the request but not perform it:

    http --offline get google.com
    GET   / HTTP/1.1
    Accept: application/json, */*;q=0.5
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Content-Length: 5
    Content-Type: application/json
    Host: google.com
    User-Agent: HTTPie/2.4.0
Pipe stuff to httpie to put it in the payload:

    echo "Hello HN" | http --offline get google.com
    GET / HTTP/1.1
    Accept: application/json, */*;q=0.5
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Content-Length: 13
    Content-Type: application/json
    Host: google.com
    User-Agent: HTTPie/2.4.0

    Hello HN
And use http-prompt, because it's awesome: https://github.com/httpie/http-prompt


Not exactly apples to apples, but I'd like to plug in Vite: https://github.com/vitejs/vite

Not that it makes fast minification (which I don't care that much about, I minify only on deploy, and it's a small % of the time it takes), but it does allow for a very fast workflow in dev mode: auto reload seems almost instant even with heavy transpiling.

I only mention it because I assume people look at this articles and think about their dev process speed as well.

If you haven't, give it a try: it's from the Vue author, so it's really clean, but works with react as well.


From a first look this seems very similar to Snowpack. I'll have to check it out more to see how they actually compare.


> auto reload seems almost instant even with heavy transpiling

Because transpilation is done by esbuild


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

Search: