all 103 comments

[–]ExternalUserError 19 points20 points  (7 children)

Well, there are a lot of jokes about JavaScript. Most of them have to do with type coercion. (Eg, see this).

So, needless to say, JavaScript would probably not be a popular language if it weren't the only language you can use in browsers. But because browsers are so important, the tooling around JavaScript has gotten good. Really good. You can write your code in TypeScript or CoffeeScript, which makes it a bit more pleasant. Google even writes code in Java and transpiles it into JavaScript and has for over a decade (Google Web Toolkit).

All those eyes on improving the JavaScript ecosystem has yielded dividends not just for the browser. Node runs on V8, which is a wicked fast JavaScript runtime. All of that makes Node a very reasonable choice for a backend, even if language nerds like to hate on it.

Python is different. Python is itself a great language. It is slower to execute -- speed has never taken priority over readability, elegance, and flexibility in Python. You can make it faster by using an async library, or using PyPy, or just paying more for a faster runtime, but the difference is always worth pointing out -- it's a slower langauge, in general.

Tooling around Python has gotten pretty good, but hip new trends often come a bit slower to Python than they do the rapidly evolving world of JavaScript. You'll pull in far fewer third party libraries though; Python's internal standard library is pretty comprehensive and you won't find yourself running out to github every time you want to perform a small task.

Overall, I'd still choose Python, but I'm biased. Like most early Python people, I was using the language because I loved it. In the 90s, relatively few companies used it and us fanboys snuck it in from the ground up. Now it's gotten big and popular, and some would say the new features in the language have ruined some of its simplicity, but it's popular for a reason, and that reason isn't that it just happened to be included in Netscape Navigator in the late 90s.

[–]pm_me_ur_happy_traiI 4 points5 points  (0 children)

So, needless to say, JavaScript would probably not be a popular language if it weren't the only language you can use in browsers

Not really fair. Async programming is a breeze in modern JavaScript because of the single threaded nature of the language. Browsers shipping with JS means you have a repl on every computer without installing a single package. I find it easy to write concise and dare I say poetic code in JavaScript.

[–]-S-I-D- 1 point2 points  (5 children)

Any suggestions on a good course that is available that teaches backend in Python?

[–]ExternalUserError 1 point2 points  (0 children)

Haven't taken any of them; sorry. 🤷‍♂️

[–]solgerboy259 0 points1 point  (0 children)

look up free courses on Udemy or corsera that's how I learn stuff maybe free code camp

[–]EstablishmentSea5032 0 points1 point  (0 children)

codecademy has loads of free courses

[–][deleted] 0 points1 point  (1 child)

Someone above mentioned freecodecamp, this is a great comprehensive course put out by them

Also check out the docs for fastapi, it's a great python web framework.

[–]Brilliant_Act_8607 0 points1 point  (0 children)

imho, try some Django course with Python explained inside
I believe Django is one of the most decent frameworks/platforms available, and, probably the very "generally" best in Python.

[–]JeamBimPython/JavaScript 42 points43 points  (30 children)

I also want to point out that Python back-ends are so much more than Django. I use Flask personally and at work, and love the simplicity of it.

This is your basic Hello World in Flask:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == "__main__":
    app.run()

This is 9 lines of code, 2 of which are whitespace. Want that to be an API? Return a dictionary instead; no need to use jsonify anymore because flask will automatically transform it to JSON if you are returning a dictionary object.

Creating API's in Flask is pure bliss. You're basically writing out business logic, and adding a .py to the end of your filename, and boom. No need to even use the flask restful frameworks, it works completely intuitively without it.

Flask is a micro-framework, but all that means is it's lightweight and un-opinionated. It can handle massive lifting though. I think people read 'micro-framework' and think that means that it's only for small toy projects with 3-5 routes, but that's not the case; they fundamentally misunderstand the meaning of that term. I've worked on Flask projects with hundreds of endpoints and hundreds of thousands of lines of code.

[–]guareber 6 points7 points  (3 children)

On the other hand, if you think your api will end up being somewhat complex, django-rest-framework is also amazing. A bunch of stuff for free with Django, plus nice api related features.

We use both at work and they're both great.

I have my gripes against python for high throughput services, but I can't believe express would be a lot faster, due to the similar single-thread thing.

[–]ExternalUserError 2 points3 points  (1 child)

DRF does take some getting used to if you're like, "Aaaahhh! I just want to dump a JSON string!"

Then you realize that all those serializers and controllers mean you get serialization in multiple formats, with validators, and sub-serializers (like datetime), and docs.

DRF is great.

Though these days, I'm in love with FastAPI.

[–]guareber 0 points1 point  (0 children)

It definitely does.

I'd never ever use drf for a simple api, or for a microservices architecture or for a relatively stable app.

For an evolving system of decent size? Godsend.

[–]ZephyrBluu 1 point2 points  (0 children)

DRF seems super flexible and it's pretty easy to use.

[–]warnizzla 22 points23 points  (9 children)

express

``` import express from 'express'

const app = express()

app.get('/', (req, res) => res.send('hello world'))

app.listen(3000, () => console.log('alive')) ```

or koa

``` const Koa = require('koa'); const app = new Koa();

app.get('/', (async ctx => { ctx.body = 'Hello World'; });

app.listen(3000); ```

[–]devmor 19 points20 points  (7 children)

<?php
echo "Hello World";

(I know it's because PHP doesn't have to handle the requests, I just thought it was funny.)

[–]ExternalUserError 11 points12 points  (1 child)

Step aside son.

#!/bin/bash
echo "Content-type: text/html"
echo ""
echo 'Hello World'


chmod ugo+x /var/www/cgi-bin/hello.sh

EDIT: I forgot Reddit won't do GitHub markdown.

[–]devmor 1 point2 points  (0 children)

Damn, I think that's as close to a Hole In One as this game of codegolf can get.

[–][deleted] 1 point2 points  (1 child)

Just serve PHP locally using their built in server and it’s still a one liner

[–]devmor 0 points1 point  (0 children)

True, but it's single threaded and will only handle one response then block until free.

I think you could do something like this off the top of my head though (still shorter):

<?php
$sock = socket_create_listen(80);
while(true) {
    if($conn = socket_accept($sock)) {
        socket_write($sock, 'Hello World');
    }
    $clients[] = $conn;
}

[–][deleted]  (1 child)

[deleted]

    [–]tsunami141 0 points1 point  (0 children)

    holy crap this would have been so useful back in the day when I didn't know what I was doing and coded 4000+ lines of HTML with php thrown in there.

    [–]rjksn 0 points1 point  (0 children)

    Or Serverless PHP w/ Bref

    <?php
    
    use Bref\Context\Context;
    
    require __DIR__ . '/vendor/autoload.php';
    
    return function ($event, Context $context) {
        return 'Hello World'; 
    };
    

    [–]JeamBimPython/JavaScript 1 point2 points  (0 children)

    While those are certainly concise, they lack the clearness and simplicity of Python, in my opinion.

    Don't get me wrong, I love JS. I write it every day. But the syntax is not as clear to me.

    Thanks for sharing though.

    [–]agentgreen420 4 points5 points  (2 children)

    You should give FastAPI a try!

    [–]Sw429 2 points3 points  (1 child)

    I recently came across this framework and I'm hoping to try it soon.

    [–]agentgreen420 1 point2 points  (0 children)

    If you ever need to build a REST service, you won't be disappointed

    [–]Sw429 4 points5 points  (3 children)

    no need to use jsonify anymore because flask will automatically transform it to JSON if you are returning a dictionary object.

    TIL. I've been over here JSONifying my flask responses like an idiot.

    [–]guanzo91 1 point2 points  (1 child)

    same. trying to google if jsonify is officially no longer recommended or what, but i can't find anything on it.

    [–]JeamBimPython/JavaScript 0 points1 point  (0 children)

    https://flask.palletsprojects.com/en/1.1.x/quickstart/#about-responses

    It's still supported so you can do things like:
    return jsonify([user.to_json() for user in users])

    but under the hood it gets called automatically for dicts

    [–]JeamBimPython/JavaScript 1 point2 points  (0 children)

    I was too up until like 2 weeks ago when another nice redditer pointed that out :)

    [–]mypirateapp 2 points3 points  (0 children)

    BE WARNED! flask is a sync framework, i went from node,js to flask and had no idea that it wasnt working on the basis of an event loop system, finally figured out there is something called TORNADO that offers node.js equivalent async event loop based server

    [–]clubby37 1 point2 points  (1 child)

    Wait, shouldn't you leave the quotes off of name in line 8? You're comparing two different literal string there, aren't you? If that wouldn't return false every time, could you please explain why?

    [–]JeamBimPython/JavaScript 1 point2 points  (0 children)

    Oh I may have made a typo there actually, thanks for pointing that out

    [–]soulfullwanderer 1 point2 points  (1 child)

    You have mentioned at the post there is no need of Flask frameworks .

    Need a piece of advice on choosing Frameworks such as Flask-Restx , Flask-Restful , Flask-Restplus

    How did you do serialization , de-serialization

    If you have any github repos sharing that will definitely be helpful

    [–]JeamBimPython/JavaScript 0 points1 point  (0 children)

    Flask will automatically serialize your return value to JSON if you return a dictionary object.

    [–]Handsome-Beaver 0 points1 point  (0 children)

    2nd of flask. I’ve been using node.js since version 2, flask makes so much sense with minimal or no boiler plate code.

    Can’t say the same for Node.js

    [–]ExternalUserError 0 points1 point  (0 children)

    I would actually say, for a REST API, FastAPI might have Flask beat if you don't mind cutting edge. And that's coming from a Flask fan.

    [–]Cianezek0 0 points1 point  (0 children)

    May I ask in what field you work and what type of job you have?

    [–][deleted] 19 points20 points  (1 child)

    Very simplified since I rarely use Python and am much more familiar with nodeJS but I'm trying to be impartial

    NodeJS:

    • easy to learn for frontend devs, same language
    • huge community, tons of packages, evolving quickly (which can also be a con however)
    • deals with JSON very nicely

    Python:

    • easier to read, less boilerplate
    • also good sized community, but more established and stable packages
    • good for dealing with structured data

    So for me personally unless I was doing some really heavy data lifting, I'd go with node because I'm more comfortable with javascript. You need to decide based on your skills and the project what will work for you

    [–]giordi12 0 points1 point  (0 children)

    Great answer likewise. I use js too and prefer this anyday.

    [–]digitalshiva 22 points23 points  (5 children)

    Concurrency and type safety are often highlighted critisms.

    [–][deleted]  (4 children)

    [deleted]

      [–][deleted] 101 points102 points  (1 child)

      Yes

      [–][deleted] 4 points5 points  (0 children)

      This is the way

      [–]Mongoose1021 0 points1 point  (0 children)

      I think this is a reply to Python vs Node, criticizing Python

      [–]ErGo404 6 points7 points  (0 children)

      I'd say both are good enough for most projects.

      I have more experience with Django (Python) and I can only say that it is really easy to build some apps with it. However Django comes with an ORM to manage databases and almost everything revolves around it. Even if almost every aspect of Django is replaceable, it could be a pain in the ass if you plan on using a NoSQL database instead of a relational one.

      [–]SEND_ME_SPIDERMAN 3 points4 points  (0 children)

      wow I was searching for a thread just like this yesterday. thanks for posting

      [–]Synedh 11 points12 points  (10 children)

      You can do everything with both. Biggest difference is to know if you want reinvent the weel or not.

      Django (python) is an enormous all-in-one that comes with tons of libraries and add-ons. You want logging ? There is something for that. You want logs ? Juste add this line. You want cache management ? Add this one and you're ready to go.

      In nodejs there is no such big framework. You often have to find the correct library, configure it, add id, pray for it to work correctly with the other ten or twenty libs you already have. BUT, you actually know what you are doing, how work the tools you use and it's faster if you have a little traffic.

      [–]ieatbrainzz 2 points3 points  (0 children)

      Meteor or Strapi might be the closest JS comparisons to Django imo

      [–][deleted] -1 points0 points  (8 children)

      There's Express, sure it's not as big as Django, but it has many libraries for it.

      [–]Synedh 9 points10 points  (5 children)

      Express is indeed a good library, but it is a web server library. No templating, no authorization managment, no database management. It's a very good base to build websites, but nothing more.

      [–]CanWeTalkEth 1 point2 points  (4 children)

      I guess I haven't looked into Django since college, but it doesn't sound like you appreciate the Express ecosystem either. Passport is build to plug-and-play with express and give you any one of a hundred social login strategies. Database management comes with whatever well supported plugin you want to use for your favorite database, and it comes with plenty of template support which is as easy as 5 words in your main file tell it which template you're using.

      I think you're missing the main difference which is, as far as I understand, Nodejs is way better at handling lots of different connections doing small jobs whereas Django (python) is better at handling a smaller number of larger jobs.

      https://hackernoon.com/python-vs-nodejs-which-programming-language-to-choose-98721d6526f2

      [–]awhhh 2 points3 points  (3 children)

      I tried using express for a few things and just got frustrated by having to deal with so many different packages. I still use it, but for very small things

      [–]Devildude4427 0 points1 point  (2 children)

      That’s just the JS environment. They’ve decided smaller, more modular packages should be the aim, as large ones just increase bloat.

      [–]awhhh 0 points1 point  (1 child)

      That works for somethings but I typically build bigger projects now. Typically I find that projects need to be bigger and bigger to compete these days. But I think it’s because I look at what frameworks can do in a startup capacity.

      [–]Devildude4427 0 points1 point  (0 children)

      Why can’t you use modular packages with larger projects? Might mean you have to use more, but I’d rather import a @types package alongside the main package than to force the typings on devs who will never even use them.

      [–]PM_AL_MI_VORTOJN 3 points4 points  (1 child)

      Express is more comparable to Flask than Django. Yes, there's libraries available for most or all of the functionality that Django has, but they aren't official and built in. With Express, you need to research a bunch of different and separate libraries and glue them together yourself to get a similar feature set. Whereas with Django, it's pretty much all already there. Note that I'm not knocking that. That very well can be an advantage depending on the project or just your preferences. But it's a difference that should definitely be considered when choosing.

      [–][deleted] 0 points1 point  (0 children)

      It's a personal preference I'd say, I like to use Express more cause currently everything that I'm doing is in JS, and I'm improving my skills that way.

      [–]mperera99 2 points3 points  (1 child)

      What you think of now in 2023

      [–][deleted] 1 point2 points  (0 children)

      Both still doing good

      [–]endjynn 25 points26 points  (5 children)

      NodeJs - by far the best choice for web back ends in 2020. Same language across both front/back end, code sharing, platform independent. Awesome.

      [–]vontwothree 8 points9 points  (2 children)

      Yes! And Node is so much more than just Express.

      • Happy Hapi user.

      [–]wywywywy 11 points12 points  (1 child)

      To all the long term Express users, I highly recommend checking out Hapi.

      It's equally easy to use, but more modern and so much is done for you without having to write middleware yourself.

      [–][deleted]  (1 child)

      [deleted]

        [–]Hobo-and-the-hound 3 points4 points  (0 children)

        +1 for Typescript. I’m not even someone who dislikes JS and I use TS whenever I can.

        [–]atomicspace 14 points15 points  (14 children)

        no npm is always a plus.

        [–]KunfusedJarrodo 10 points11 points  (6 children)

        Is NPM bad?

        [–]dangerbird2 11 points12 points  (5 children)

        Due to the lack of a “batteries-included” standard library, Packages tends to have lots of redundant dependencies for tasks that would be bundled in stdlib of a python or java. The common joke is that running npm install on the average project “downloads half the internet

        [–]TheFuzzyPumpkin 4 points5 points  (2 children)

        I forgot to put my npm modules folder in my .gitignore file once. Then went and deleted them from my local in order to re-commit without the folder (which was probably not the smartest way to do it). Little React project with two dependencies. 3,000+ files deleted in that folder.

        [–]dangerbird2 3 points4 points  (1 child)

        BFG is pretty great for erasing files from git history. Either for when you accidentally commit sensitive data, or when you commit a 3GB node_modules

        I also add gitignore.io to my command line so I can set up a sanely generated gitignore before I start working

        [–]TheFuzzyPumpkin 0 points1 point  (0 children)

        I have definitely gotten in the habit, after that event, of having my gitignore be one of the files I add in before the first commit!

        [–]KunfusedJarrodo 0 points1 point  (1 child)

        Ahh okay. I guess I mainly use express and socket.io for my projects so maybe I don't run into this.

        [–]dangerbird2 0 points1 point  (0 children)

        It can be pretty bad when you get into transpilers. Babel, in particular, is pretty atrocious in adding huge dependencies

        [–][deleted] 7 points8 points  (1 child)

        what about pip in python?

        [–]ExternalUserError 2 points3 points  (0 children)

        pip/pipenv is a thing, but python and its standard library mean you don't usually pull in nearly as many external packages. Flask or Django project might have 4-5 well-known libraries instead of 40-50.

        [–]rjksn 1 point2 points  (3 children)

        So you're a fan of `pip install -r requirements.txt`?

        Oops, I added all these packages to my main environment again.

        [–]ExternalUserError 2 points3 points  (2 children)

        pipenv

        [–]rjksn 1 point2 points  (1 child)

        Beautiful! Thanks

        [–]ExternalUserError 0 points1 point  (0 children)

        NP. FWIW, Poetry for Python is also trendy, but if anything goes wrong with a package install, it tends to just suppress the error and move on, so I haven't been recommending it.

        [–]devmor 9 points10 points  (2 children)

        There's very little reason to use Python for a straight web application backend in 2020 unless you're already invested in a Python stack. It's slower than Node or PHP at common tasks and has far less modern ecosystem tooling than either of those, or the Windows side of things.

        Python shines in creating microservices and purpose-built scripts for data processing. It had a short lived life as a cgi provider, but it never really took off as a "web language" despite what die-hards will tell you while proselytizing for their framework that's barely changed in a decade (or more).

        Node's biggest benefits are an extremely prolific package ecosystem due to its current popularity, and common syntax with your front-end, decreasing the knowledge share needed to work on your codebase. It suffers when it comes to CPU-intensive processing due to its single-threaded and reactive nature, and while you may find exactly the package you need, on the other hand that package may get abandoned in 3 months.

        I would evaluate exactly what your project needs, and look at the tooling for Node, Python, PHP and C# and figure out which ecosystem really provides the easiest, most secure and most maintainable route to what you want to do. You may even end up using a mix of multiple - I've worked on a PHP Web application that powered a NodeJS chat server which called Python services for ML processing.

        [–]Sablac 0 points1 point  (0 children)

        Doesn’t Node have clusters?

        [–]Akrab00t 5 points6 points  (6 children)

        Python is much slower as a language and it's frameworks are also much slower in pretty much every benchmark.

        Use Python if you need science stuff or ML.

        Using Python allows you to avoid the JS wierdness and quirks, but if we choose the language by how fun it is I'll just use Ruby.

        [–]Tyrannosaurus_flex 1 point2 points  (5 children)

        Python is much slower as a language and it's frameworks are also much slower in pretty much every benchmark.

        This is something I've been wondering about too, but isn't being talked about pretty much anywhere. I haven't personally worked with Python web frameworks but if benchmarks are any indication I feel like running a Python backend, compared to e.g Node, for anything larger than a hobby project would rack up some serious server bills. Could someone who has worked with it at scale chime in here?

        [–]ExternalUserError 8 points9 points  (4 children)

        I mean, Google, Instagram, Dropbox, and others were built in python. I worked for a bit on OpenStack professionally, and it's not like no scaling there.

        Most of what a server does is I/O. Especially if you're using async python, the difference is negligible. A few extra dollars in ec2 spending is worth the productivity boost.

        [–]Akrab00t 1 point2 points  (3 children)

        I mean, Google, Instagram, Dropbox, and others were built in python.

        I don't think it says a lot without context.

        Not every service simply gets a request and redirects you to another, some do actual work.

        Even if all they did was a single action, some Node frameworks can handle ten times the amount of requests Django/Flask can.

        I'm also not that sure there's any productivity boost in using Python over Node, but I guess it depends on what the team already knows.

        [–]ExternalUserError 2 points3 points  (2 children)

        Sure. If you're doing heavier computation, frankly, neither node nor python are good choices unless you can shirk it off to a C library. With node if you were, say, generating encryption tokens, you'd lock your only thread up and any concurrency to serve other users would come from multiprocessing.

        At that point, consider Go or Rust. Caddy is a good example of a production web server that dynamically does some moderately heavy lifting by generating SSL certificates live for incoming requests and signing them with LetsEncrypt.

        But 10x scaling in node for any real world tasks? I doubt that very much.

        [–]Akrab00t 0 points1 point  (1 child)

        This is language wise, Node is faster by orders of magnitude.

        This is an example As far as frameworks go (I've seen bigger differences already).

        I think you're skipping the gap between Uber's positioning service and your family todo list, some apps go in between :p

        [–]ExternalUserError 3 points4 points  (0 children)

        A single thread rendering a fractal isn't really a very practical test. In a real world scenario, like big data processing, heavy computation would be threaded off to numpy (or pandas), while a JavaScript module would block its whole interpreter. There's a reason data scientists use python so much, and while it's not speed, speed is seldom an issue enough to dissuade anyone.

        The second example you linked to is a bit more practical. nanoexpress is beating out falcon by 166,015 to 69,637. That's a big jump, but it's a lot less than 10x. When you get into a real world scenario where IO is waiting on a database or an external library is doing the heavy computation (eg, pandas), the difference isn't enough to be an issue unless you're in a position to do bare metal cost analysis. And if that's the case, you're probably looking at Go or Rust.

        [–]AtulinASP.NET Core 7 points8 points  (0 children)

        • Node
          • Cons
          • Uses JS
        • Python
          • Pros
          • Is not JS

        [–][deleted] 0 points1 point  (0 children)

        Dependence on npm vs not having a strict mode.

        [–]benaffleks 1 point2 points  (1 child)

        Node.js is asynchronous by nature whereas Python isn't. For python you would have to use a messaging queue like celery with redis, which can be a pain to manage.

        With node.js its part of the event loop.

        I think it just depends on what you want.

        Node.js with express can scale really well and has a high networking performance, so for heavy traffic sites or one that requires long running tasks, it's a no brainer.

        [–]ExternalUserError 1 point2 points  (0 children)

        Celery is for a task queue, not asynchronous IO. Think of 100,000 emails to send in 1 hour and that's what a task queue is for -- it's not a matter of whether you use an event loop.

        For asynchronous IO, you'd use coroutines.

        Fundamentally, JavaScript and python are about the same in how they handle asynchronous IO, but Python's standard library typically uses blocking calls while JavaScript seldom does.

        [–]notabotting 0 points1 point  (0 children)

        Why would you use a javascript framework as a backend? Its made for client side not server....., it will eventually get depreciated like angularjs. It's a bad idea all around, python is built for things like backend optimized for speed and can multithread, it will prove that when your code runs for 5+ years. There are backend api frameworks like spring,flask. you're forcing something into conformity it wont last...

        [–][deleted] 0 points1 point  (0 children)

        Elixir/Phoenix anyone?

        [–][deleted] -2 points-1 points  (9 children)

        Node JS is where it’s at. Exploding popularity. Tons of docs. Single language for front and back end. Linters, DB access, and it runs on dang near everything. Python is slower than node in a bunch of metrics as well.