4 ms·
The trouble is, you learn javascript and discover it’s a better back end for website building. I say this as a python dev with experience of bottle flask falco
by andrewstuart 3y ago
The trouble is, you learn javascript and discover it’s a better back end for website building.
I say this as a python dev with experience of bottle flask falcon Django Starlette abs FastAPI.
- pier25 3y agoI'm a JS guy but I'm not sure I would agree. Backend frameworks in JS are not as mature as Django, Rails, or Laravel.
- leetrout 3y agoEhhh yes and no. I still run into a lack of "it just works" and stays that way in JS land. It is likely I have not found the right combination of tools or the right framework but nothing has been as reliable as django and the builtin contribs (auth, admin, sessions). What would you recommend I look at in JS land knowing I love django and dislike flask?
- andrewstuart 3y ago>> What would you recommend I look at in JS land knowing I love django and dislike flask? I just use typescript and nodejs and the database. No framework except the express web server. It's incredibly raw and close to the metal, which I like. Here's a throwaway example of register and login from ChatGPT to illustrate how easy it is. Totally unchecked but it's just to show approximately what's involved - and it's not much at all. import express, { Request, Response } from 'express'; import bcrypt from 'bcrypt'; import db from './db'; const router = express.Router(); router.post('/register', async (req: Request, res: Response) => { const { username, password } = req.body; // Hash the password const saltRounds = 10; const hashedPassword = await bcrypt.hash(password, saltRounds); // Insert user into the database db.run('INSERT INTO users (username, password) VALUES (?, ?)', [username, hashedPassword], (err) => { if (err) { console.error(err.message); return res.status(500).json({ error: 'Internal Server Error' }); } return res.status(201).json({ message: 'User registered successfully' }); }); }); router.post('/login', async (req: Request, res: Response) => { const { username, password } = req.body; // Check if user exists db.get('SELECT * FROM users WHERE username = ?', [username], async (err, row) => { if (err) { console.error(err.message); return res.status(500).json({ error: 'Internal Server Error' }); } if (!row) { return res.status(401).json({ error: 'Invalid username or password' }); } const isPasswordValid = await bcrypt.compare(password, row.password); if (!isPasswordValid) { return res.status(401).json({ error: 'Invalid username or password' }); } return res.status(200).json({ message: 'Login successful' }); }); }); export { router as routes }; For database I use the postgres.js library which is super nice https://github.com/porsager/postgres https://github.com/porsager/postgres examples from postgres.js front page: import sql from './db.js' async function getUsersOver(age) { const users = await sql` select name, age from users where age > ${ age } ` // users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...] return users } async function insertUser({ name, age }) { const users = await sql` insert into users (name, age) values (${ name }, ${ age }) returning name, age ` // users = Result [{ name: "Murray", age: 68 }] return users }
- krembo 3y agoWell, for me this is less way readable than python. And I know JS for a long time, yet IMHO its syntax and structure seems clunky.
- berkes 3y agoReadability and unfamiliarity are two different things.
- PrimeMcFly 3y agoIt doesn't seem that close to the metal, and not enough to justify the lack of convenience and readability. It's like using C++ instead of C#. Still pretty removed.
- leetrout 3y agoRespectfully, and thank you for taking the time to reply, this is why I clarified I like Django and dislike Flask. I'm not interested in writing all my sql for every operation. I will gladly take the overhead of an ORM for the convenience in centralizing query building, table definition, object mapping and (in the case of django) migration tooling. Knowing it's battle tested saves me from my own silly mistakes. I do love sql alchemy so I can imagine enjoying something like Prisma but I suspect express is going to leave me wanting more. I think my next project will use Go to force myself to avoid Django and pick up a nice perf boost with much better type safety than Python + MyPy.
- winrid 3y agoI'm not sure you can call one or the other "better". Python is more type safe due to run time type checks (less lolwut). Also, less typing. But, you also get the Django ORM which is great for productivity (good for complex but low volume apps). JS has some great features: async/await, deconstructing objects, nice JIT, same language as in browser. However, it's also very lisp-y, which is a pro and a con :)
- andrewstuart 3y ago>> I'm not sure you can call one or the other "better". I should have said "better for ME". >> you also get the Django ORM I decided the best way (for me) to write back end application is: * typescript * nodejs * postgres * plain old SQL I realised I hate using ORMs and much prefer the raw power and directness of SQL. Postgres is an incredibly powerful database - I find it's a problem to have any sort of abstraction between me and the DB. And honestly typescript is a real pleasure to write. I still use Python extensively for other stuff, but for web servers, typescript/node/postgres is my preference.
- winrid 3y agoI found the best way for me to write backend applications is with an ORM. Because SQL is super slow to write. The exception is sqlx in Rust when I want something super correct.
- andrewstuart 3y ago>> Because SQL is super slow to write. ChatGPT writes SQL incredibly well - presumably because there is so much training material out there. Seriously, ChatGPT is the single best reason to change your architecture away from ORM to plain SQL.
- winrid 3y agoThat's interesting. But no. I can write queries so fast with the Django ORM it's silly. Especially dealing when dealing with relationships... Pycharm will auto complete like 4 levels of joins in two seconds. That's faster than you tabbing to chatGPT let alone writing the prompt.
- reducesuffering 3y agoHere here. The same app built in Django was worse frontend, worse package management, and worse deployment than a Next app.
- macNchz 3y agoI’ve written reams of JS over the years–web frontends with a dozen frameworks, Node backends, mobile apps, you name it. It’d probably make sense for me to use it more often on the backend, but the trouble I run into when committing to it for a new project is that… I just don’t like it. I know how to avoid all of the “wat” stuff that people typically trot out to criticize the language. I can write a quality piece of production software with it. At the end of the day, though, I still just have this feeling like I’m cooking in someone else’s odd and disorganized kitchen with not quite all of the right tools and ingredients.
- EdwardDiego 3y agoOut of curiosity, what do you perceive as the main advantages of JS on the server vs Python?
- andrewstuart 3y agoIt's personal preference that's all. To be honest it's more that I prefer TypeScript to Python. Python and JS have been my main programming languages for 14 years or so. Either are good - I'm not totally off python. I still write async web servers in Python for various reasons. I'm not much of a fan of Python's type system probably because I haven't yet spent enough time to really learn it. I definitely use Python for Linux systems programming or non-web server stuff - Python is really great for more systems oriented stuff. I really liked Django at first but after a while some things really started to bother me about it. The ORM I found complex and clunky - any time I wanted to do something I kept thinking "Ugh this would be dead simple in SQL". Needing to add plugins to Django - I often felt like it took me the same amount of time to work out how to install and configure a plugin, as it would to write the same functionality from scratch, with the disadvantage that at the end of the process I'd often still feel like the plugin was a black box that I'd managed to make work but was never sure I had done it right. And the thing that really annoyed me most about Django is it's meant to be "batteries included", but the very first thing you need to do is work out how to implement users and signin and forgot password and signout - all stuff that should be the very definition of "batteries included". Instead, at the start of every Django project you're left to try to work out what is the right plug and how to install it and did you do it right. If I have to do all that stuff yet again for every project then why bother with Django at all? Why not just use a minimal web server and implement it myself because I'm going to have to anyway. And then, after forming these hesitations about Django, I started doing async web programming with Starlette and FastAPI and found I really liked async web server programming and Django isn't async. So at this point I'd pretty much lost interest in Django.
- VectorLock 3y agoOr you get hung up on how bad JavaScript is compared to Python.
- nprateem 3y agoIs there anything like django admin? I'm open to JS or Java tbh, but django is just so productive because of admin, forms, user management and DB migrations. Give me those in a more performant language and I'll be interested, but I just can't find them. Add to that that django has all those under one roof so you can hire a django dev who doesn't need to spend 2 weeks learning your libraries, and I'm just wondering why the faster languages ignore such a value proposition.
- em-bee 3y agonot sure what you are asking here. if you use a frontend framework with django as a backend to build your site, you still use django admin as before. there is no need to replace that. you are only replacing the end-user facing frontend.
- lysecret 3y agoYep, the future is JS full-stack. Especially with stuff like Trpc, Next, Server Components. These frameworks just have much more options to integrate the frontend and backend nicely.
- miiiiiike 3y agoI still like using Python on the back-end. But, I've also been waiting for what, 10 years, for Django to get async support.
- sesm 3y agoSo it’s a kind of survivor bias: those who learned JS stopped using Python for web backend.
- miiiiiike 3y agoI still like Django on the backend.