80 points · by fagnerbrack · 2y ago · 116 comments
Seem to be a good pattern of adding what is needed and otherwise keep things as they are.
Do not have a lot of experience with it but I would gladly ditch our vue.js build process and docker image for the little web we actualy need to do.
One difference for me is that I only pick Vue for projects that are large enough to need fully front-end logic but small enough not to need a build-step (And one could equally well go for React once a project is large enough to need a build step), this is where Vue really shines since you get the auto updating goodess but don't need to burden yourself with any build script complications.
I get the author is looking for some integration with Django and server-rendered HTML but Svelte is definitely not heavy and v5 is going to produce even less JS code.
Are we talking purely bytes? Popularity? Typical codebase size? Browser performance?
And whichever it is, why are we prioritising it?
I.e. looking for solutions that "render HTML in Django, and use Javascript to enhance the server-rendred [sic] HTML."
HTMX is the most popular solution.
which i think is, for the most part an exaggeration.
if someone feels that learning a new framework is heavy and has a steep learning curve, then either they are juniors that need more practice and experience, or they have never tried learning a second framework, or they have become lazy. (but here i'd also like to blame employers that don't give their developers time to learn new stuff)
I want to know more.
Let's try to maintain a high level of writing and communication here.
Let us.
This is my minimum requirement of any ecosystem in 2024. It’s really important to get this right.
[0]: https://react-spectrum.adobe.com/react-aria/getting-started....
If coming from Django side (which I did), consider whether you really need a separate framework for the front-end. Nowadays, JavaScript isn’t that hairy, and browser runtime comes with tons of batteries and syntax sugar that make it easy to write complex things. Maybe you want to use a small library like React (which is, of course, not a framework) for certain widgets, or even introduce an extra build step and write TypeScript, but sticking to vanilla overall can be key to managing cognitive load for others or your future self. Yes, maybe you’d need to write a tiny bit of boilerplate (much less than in IE6 days!), but on bright side—basic language reference (e.g., MDN) would be enough for anyone to grasp how it is generally put together.
If you are considering using a framework and your front-end part is sufficiently complex for that then consider if you should rather architect it as a separate project. Putting strong boundaries in place can help keep it manageable, problems are isolated to one side, and it’d be more easy to find someone who is best at Django or best at (insert your front-end framework of choice) in future.
that also takes care of the problem of overlapping skills. sure, you need to learn a new framework, but really, it is not that big of a deal. if you have been creating complete websites from CSS/HTML to the backend, it really doesn't change that much. your CSS/HTML skills apply unchanged, and the only thing that is new is javascript itself and a new templating system.
the problem (as other commenters noted) stems from backend frameworks trying hard to avoid javascript. so they will try to do as much as they can in the backend, and i can imagine that throwing a full frontend framework into that is going to be challenging. i never tried it. as soon as i started using frontend frameworks 10 years ago, i was done with server side HTML generation.
However, there is no clear line between a content site and a web app. That’s why I suggest that, as a rule, if you see front-end becoming so complex that a full-blown framework is a must, then it might save you in future if you architect it as a separate project. (As sibling comment points out, it doesn’t need to compromise the ability to render static HTML and degrade in UAs without JavaScript.)
It makes sense for traditional web frameworks like Django to respond to client request with HTML, because it relies on browser's understanding of HTML text. But if these frameworks ship with JS anyway, why don't they use something else, like a data structure that is native in the programming language that they are written in, to describe the UI. Their JS component can parse that and render the UI. The JS component is basically just a templating engine on client side without all the routing, state management, etc complexities of a SPA framework.
I feel like not using HTML for server and JS component could simplify a lot of things. I guess my assumption here is that both server side programming languages and JS could use a better data structure to communicate than HTML text.
I'm not familiar with these new frameworks or have ever implemented a frontend framework, so I apologize for this probably silly question.
1. In the React space, you have to write two conversion steps: first you have to convert your app's data to some wire format (JSON objects or something) on the server, then you have to convert the wire format into HTML on the client ("render" the UI). This is more complex than a single step where you just convert the app's data to HTML on the server.
2. For best performance, the server needs to be able to generate HTML and send it to the client on the initial page load. (React calls this "server-side rendering"; its approach to it doesn't really work for lightweight frameworks because it requires you run JavaScript on the server.) Once you have that capability, you might as well use it as much as possible, rather than implementing a separate code path just for JavaScript.
disagree. the first conversion step also happens in the backend where you convert your data from the various sources into native (eg python) datastructures. converting that then to json is almost trivial. it just forces you to design an API and consolidate some structures to reduce the number of round-trips.
Also the TS compiler tends to be buggy and break in weird ways with minor version changes.
Sometimes you do need excited devs. When the domain is complicated I’d rather have fancy types than static analysis black holes.
With React you still need a ton of JS with components and other libs.
I’ve been a Django developer since 2008; I was allergic to JavaScript (for good reasons) too. After almost five years of front-end development I can tell you that most of those reasons stopped being valid sometime between 2017 and 2020. JavaScript is a great experience now.
I didn’t do it willingly. Front-end developers are expensive and hard to size up if you don’t know what Flexbox or a Promise is.
If you’re going to be doing anything web related you might as well get comfortable with the fact that learning JavaScript, TypeScript, CSS, Sass, HTML, and something like RxJS is going to make you a better developer and your life easier.
I've been programming for over 20 years and the languages and frameworks I favour have a sticky quality. These are the ones I can put away for years, return, get back into it and pick up new features in a few hours at most. The cognitive load of getting back into them are low.
I picked up django around 2011 and moved on to other things including JavaScript at the time. When I needed to build a Django project in 2016, there were some improvements and new features but the syntax, tooling and patterns were the same. It was possible to just jump right back in after a quick skim of the docs. It is possible to develop mastery of this stack, set it down for a few years and return to it with familiarity and continue on that journey.
The JavaScript ecosystem in that period however has pulled off a massive amount of transformation. I learned the basics of jQuery, yui, knockout, emberjs, backbone, coffeescript, ecmascript X, knockout, baconjs, rxjs, react with classes, react with hooks, redux, typescript, nextjs, react server components, react native, graphql, assemblyscript and on and on. It has been impossible for me to develop any deep mastery of anything in the JavaScript space. This does not even include the insane tooling with vague overlapping responsibilities. The closest I have found to reasonable stability in this area has been clojurescript with reagent.
I am constantly stuck in tutorial mode when I need to dive back into the frontend. I recently upgraded a 4 year old Django codebase in 2 hours. I am ripping out all of the react code because it is just not worth the effort any more. The tooling, dependencies and patterns are now outdated. HTMX has that simplicity and elegance that will keep the cognitive load manageable while I focus on the real problems.
This is true of most of almost all living technologies.
> When I needed to build a Django project in 2016, there were some improvements and new features but the syntax, tooling and patterns were the same.
Python and Django both underwent major transformations between 2011 and 2016. That was the 2->3 transition, class based views, channels, packaging was heating up, async came, and there were several syntax and libraries improvements. Were you more comfortable with Python at the time, is that why it was easier to get back into it?
Most Angular 2+ apps written in 2014 have essentially the same architecture as an Angular app written in 2024 (Directives, Components, Services, Pipes, etc, etc).
What you're describing reads like putting down any living technology and picking it back up again a few years later.
It's not really true for any other programming language. If I'm an expert in Java 8, I can build and ship a product using it. I don't need to be up-to-date in my knowledge of Java 17. Same holds for almost every language.
Javascript is an exception because you don't get to decide which version to deploy, so you have to constantly be keeping up with it.
Despite the churn, there are some great core technologies for the front end. Native browser functionality is much better than it used to be.
[0]: I was a C# developer for five years, but, with Mono, because I wanted to make sure I wouldn’t be employable.
Try using the native date control or the number control.
You also still can't easily style the select component. In React MUI, for example, they completely give up on it and use styled divs instead.
But what would I know, I'm one of those incompetent .Net developers.
C# and the .NET Framework were some of my favorite tools. I thought LINQ was neat.
> You also still can't easily style the select component.
Forgoing JavaScript and CSS for a .NET abstraction wouldn't make the situation any better. You'd just get whatever the select component's library gave you until the browsers standardize a way to do it.
I also try to avoid JS as much as possible. I honestly feel like it's a good design approach/directive - use HTML and CSS as much as possible, and JS only when needed and sparingly.
I'm not against it at all, I use it to expand menus, or to change a hidden field to visible based on which option in a dropdown is selected, maybe even some AJAX stuff.
But mostly if I can avoid it I do. My sites still look modern, but they are fast, and often the entire front page can load in 0.3 seconds or similar (according to various online speed tests).
I haven't ever needed TypeScript, Sass or whatever RxJS is.
I say this as a python dev with experience of bottle flask falcon Django Starlette abs FastAPI.
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.
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?
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/postgresexamples 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
}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 :)
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.
How could Python's runtime type checks be more safe than Typescript's completive type checks? Nobody sane uses typeless Javascript for serious business logic now anyway.
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.
Backend frameworks in JS are not as mature as Django, Rails, or Laravel.
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.