News for hackers. Stuff that matters.
Re:Show HN: Rust Web Framework by imiric on Tuesday October 22, 2024 @05:25PM (#41918890)
After years of working with web frameworks in Python and Java, and then picking up Go along the way, I've come to appreciate Go's approach much more. That is, with a rich and capable standard library, you really don't need traditional frameworks. Need an HTTP server, router, etc.? Use stdlib. Need templates? Use stdlib. Need an ORM? You don't, but you may want to consider a small 3rd party query builder library of your choice. And so on.

This avoids depending on a complex framework that may or may not exist in a few years, improves security by minimizing the amount of 3rd party dependencies, keeps the learning curve low for any new developers joining the project, and is more flexible and easier to maintain. I don't have experience with Rust, and judging by the comments here, web frameworks might still be useful for it. Which is a shame, since the batteries included stdlib approach is far superior IME.

Anyway, I don't want to shoot down your efforts. Congrats on the launch and good luck!

Re:Show HN: Rust Web Framework by zarzavat on Tuesday October 22, 2024 @07:15PM (#41919738)
Remember the PHP 4 era. The average developer is incapable of implementing everything from scratch securely. Django and similar big frameworks perform a vital public service, by providing sensible defaults to people who need them.

I do agree that personally I don't like using big frameworks. My personal favourite is the express architecture: a thin substrate that allows for middleware plugins to be installed and not much else beyond that.

Re:Show HN: Rust Web Framework by bilekas on Tuesday October 22, 2024 @07:26PM (#41919823)
> I've come to appreciate Go's approach much more

I've also come to really appreciate a good standard library. I used to POC things in node because it's so simple, but the dependency tree is hard to justify.

I do like Rust's stdlib too, but its a different tool for a different project. My issue with Rust is the refactor cost when it needs to change.

Re:Show HN: Rust Web Framework by mixmastamyk on Tuesday October 22, 2024 @09:44PM (#41920844)
Interesting that Python has actively said no to recent web-based modules in the stdlib. Because that stuff moves too fast, and putting in the stdlib would hold it back. The most famous is requests, but I've heard the argument elsewhere.

Not sure who to believe. :-D

Re:Show HN: Rust Web Framework by littlestymaar on Wednesday October 23, 2024 @02:37AM (#41922427)
I've not done a lot of Go, but a former employer used it for all the back-end stuff, and they weren't using the standard modules for web stuff either (and it was at a time who didn't have a proper dependency management tooling so it was very tedious compares to modern languages).
Re:Show HN: Rust Web Framework by bilekas on Wednesday October 23, 2024 @04:20AM (#41922966)
> a former employer used it for all the back-end stuff, and they weren't using the standard modules for web stuff either

This might have been a long time ago but I can't think of much that you cant do. I've seen this behavior though on some project, but it was usually not about the stdlib's deficiencies but more so the developers lack of understanding what they're supposed to do and so revert to another lib.

Re:Show HN: Rust Web Framework by littlestymaar on Wednesday October 23, 2024 @04:50AM (#41923137)
It's never about stdlib “deficiency”, it's just that there are alternative ways of doing things in third party libraries and sometimes these alternatives are better than the original implementation which cannot evolve since it's in the standard library.
Re:Show HN: Rust Web Framework by efnx on Wednesday October 23, 2024 @02:43AM (#41922460)
> My issue with Rust is the refactor cost when it needs to change.

That’s an interesting take. I’ve heard it before but I believe the opposite. For me, Rust is much easier to refactor.

Re:Show HN: Rust Web Framework by bilekas on Wednesday October 23, 2024 @04:14AM (#41922931)
Depends on your level of refactor, for small things, sure, like everything its simple. But try to change the workflow or modify the architecture in a certain way, it can be a real pain. I find it's a blessing in a certain way though as it makes you plan and consider a lot more in advance when starting a project/implementation.
Re:Show HN: Rust Web Framework by metadaemon on Tuesday October 22, 2024 @05:53PM (#41919110)
Not needing an ORM made me laugh
Re:Show HN: Rust Web Framework by rad_gruchalski on Tuesday October 22, 2024 @08:15PM (#41920132)
Orms in go make little to no sense. As soon as one has a little bit more complex scenario, one ends up in the raw sql string mode anyway…

Like, try to build dynamic nested ands with ors using jsonb with gorm. Maybe there are two people on this planet who would like “aha, I know”. Just use your standard sql strings with prepared statements.

Re:Show HN: Rust Web Framework by sunrunner on Tuesday October 22, 2024 @06:26PM (#41919353)
Why is that?
Re:Show HN: Rust Web Framework by stickfigure on Tuesday October 22, 2024 @06:32PM (#41919390)
Your programming language has objects. Your database has relational tables. By definition, you need to map between the two.

You can write your own or you can use someone else's. Those are the two choices.

Re:Show HN: Rust Web Framework by sunrunner on Tuesday October 22, 2024 @06:54PM (#41919544)
By definition, you only need to do the minimum to move data from one process to another to get things read or written.

That doesn't mean you need an entire system to represent every table as an object-like thing (which is what I assume when people say ORM). It's actually possible to just emit queries to read and write the exact data that's required in the shape that makes sense for the caller.

Re:Show HN: Rust Web Framework by BlarfMcFlarf on Tuesday October 22, 2024 @06:38PM (#41919421)
You can map objects to db updates, and map query results to objects. Neither of those objects needs to have a mapping to actual relations, like how ORMs insist on.
Re:Show HN: Rust Web Framework by threeseed on Tuesday October 22, 2024 @08:48PM (#41920405)
Only for basic objects.

The minute you add relationships your approach becomes unusable.

There is a reason ORMs have persisted for over 30 years.

Re:Show HN: Rust Web Framework by wtetzner on Tuesday October 22, 2024 @08:56PM (#41920461)
No it doesn't. Why would relationships matter? You handle the relationships in SQL queries, and just copy query results to structs.
Re:Show HN: Rust Web Framework by stickfigure on Tuesday October 22, 2024 @09:16PM (#41920622)
> copy query results to structs

Congratulations, you've invented an ORM.

Re:Show HN: Rust Web Framework by threeseed on Tuesday October 22, 2024 @09:51PM (#41920891)
Majority of ORMs really are nothing more than this.

But then it's nice to have something that generates optimised, database-specific SQL, can handle date/number conversion, supports many-many relationships, converting BLOB to binary streams etc.

Re:Show HN: Rust Web Framework by ursuscamp on Tuesday October 22, 2024 @09:39PM (#41920796)
That’s 1% of an ORM.
Re:Show HN: Rust Web Framework by stickfigure on Wednesday October 23, 2024 @12:45PM (#41926785)
It's at least 30% of most ORMs. And if your homebrew ORM actually gets wide use, it'll grow from there.

Source: Wrote an ORM that other people actually use. Still adding features, twelve years later.

Re:Show HN: Rust Web Framework by wtetzner on Wednesday October 30, 2024 @08:45AM (#41994227)
This is clearly not what anyone means when they say they don't want an ORM.

An ORM library maps an entire relational database to a graph of objects, with the intention of abstracting away the relational database. Copying query results to structs doesn't actually do any of that.

https://en.m.wikipedia.org/wiki/Object%E2%80%93relational_ma...

Re:Show HN: Rust Web Framework by dragonwriter on Tuesday October 22, 2024 @08:52PM (#41920435)
Query results are actual, if transitory, relations.

And db updates are either relations or tuples (and a tuple is a relation with cardinality of 1, so...)

Re:Show HN: Rust Web Framework by wtetzner on Tuesday October 22, 2024 @08:58PM (#41920476)
You can be pedantic if you like, but this is obviously not what anyone means by "ORM".
Re:Show HN: Rust Web Framework by dragonwriter on Tuesday October 22, 2024 @09:00PM (#41920490)
Its literally the exact things that ORMs map between: query results -> objects and object changes -> database updates.
Re:Show HN: Rust Web Framework by wtetzner on Wednesday October 30, 2024 @08:50AM (#41994256)
No, ORMs abstract away the relational database and present it as if it were some kind of object database. Needing to map query results to structs is just incidental, and is completely missing the point of an ORM.

If copying query results to a list of structs is enough to qualify as an ORM, then the term is so generic as to be entirely useless.

Re:Show HN: Rust Web Framework by wesselbindt on Tuesday October 22, 2024 @07:30PM (#41919839)
> Your database has relational tables.

Mine doesn't, so I don't need an ORM. Plus, I think that when people say ORM, they mean more than just a map from the relational model to the object model and back. They refer to things like hibernate and SQLAlchemy and all the extra stuff that comes with that, like the active record antipattern, and a query builder which successfully encapsulates all trivial queries (which don't need encapsulation) but then as soon as you need to do anything even remotely complicated, the abstraction leaks. I'll be honest, not a fan of ORMs.

Re:Show HN: Rust Web Framework by wtetzner on Tuesday October 22, 2024 @08:53PM (#41920443)
There's a difference between mapping database tables to objects and just copying query results into structs.
Re:Show HN: Rust Web Framework by deznu on Tuesday October 22, 2024 @08:59PM (#41920482)
I kind of agree with this. Data in a database is often relational (hey it might not be, but it's still nice to represent it in a struct sometimes, rather than 10–20 different variables which can change anytime your database changes).

I've been using Go recently, and while I'm not convinced on an active-record style ORM in Go (I don't think the language is dynamic enough, and I'm not the biggest fan of codegen), I've been loading the row data from Postgres into a Result struct (pretty much a 1:1 mapping of the Postgres result set into the struct), and then using another function to load the Result struct into struct with their relationships attached (using tags on the structs to define the relationships between them). This has worked great using reflections & generics.

Re:Show HN: Rust Web Framework by __mattya on Tuesday October 22, 2024 @09:45PM (#41920846)
And chance this is open source?

I’m building something similar and I can’t decide on the relationship struct tag syntax to use. Would be neat to see how others are thinking about it.

Re:Show HN: Rust Web Framework by Thaxll on Wednesday October 23, 2024 @12:15AM (#41921770)
ORM by modern standard is not that, it's basically let me interact with the DB without knowing SQL.

Every language need to deserialize results into some object so by definition every language that deal with a DB do some form of ORM. So ORM is meaningless in that context.

Re:Show HN: Rust Web Framework by metadaemon on Wednesday October 23, 2024 @01:28PM (#41927294)
Why did it make me laugh? I thought the delivery was funny is all.
Re:Show HN: Rust Web Framework by qudat on Tuesday October 22, 2024 @05:34PM (#41918959)
Agreed on all fronts. Go has nailed the stdlib and every other language is in its shadow
Re:Show HN: Rust Web Framework by t-writescode on Tuesday October 22, 2024 @05:48PM (#41919078)
This is a major component of what drew me to love C# so much for a while. It's also one of those Perfect StdLib(tm) languages. Many of the components do need to be downloaded through nuget; but they are a part of the stdlib!
Re:Show HN: Rust Web Framework by Nuzzerino on Tuesday October 22, 2024 @08:38PM (#41920324)
Would it be a fair comparison? C# didn't have good support for JSON in the standard libraries for almost 20 years[1]. ADO.NET seemed like a failure to me as well, but maybe I just didn't understand it.

The System.Drawing namespace at least as of .NET Framework 4.5 required virtually all of its operations to be done through a System.Drawing.Bitmap, which meant that no matter how your image data was represented, it needed to get rasterized. This wasn't a big deal for most desktop/local use cases, but it's very inefficient, so if you had any servers relying on this, and had a reasonably decent amount of traffic to those servers, you could be getting CPU usages way too high.

As an example, I remember one time we were hosting 30 kb TIFF images (high res, 1 bit per pixel) for download, and generating the thumbnails was done in real time, which caused literally gigabytes in memory churn per request due to the rasterizations... IIRC I fixed it by using emscripten (this was 2015-2016) to do resizing and rendering in the frontend with a small C module using LibTIFF, then the server only needed to send the 30 kb files as is. Unfortunately I've had a hard time finding people to work with these days that give me that kind of room to execute.

Does Go's standard library have these rough edges or is it actually pain-free? I'm on the fence about whether I should learn Go or Rust while I am on a short employment break.

1. https://github.com/dotnet/runtime/issues/27761

Re:Show HN: Rust Web Framework by t-writescode on Tuesday October 22, 2024 @09:02PM (#41920504)
I think every kitchen sink standard library has some rough edges. Java is also a kitchen sink language and it, too, has rough edges around certain areas. I don't know Go well enough to have an opinion on where its weaknesses are.

As for this question, > I'm on the fence about whether I should learn Go or Rust while I am on a short employment break.

What are you learning the new language for? If for fun, then this question is longer. If for employment, I would bet that there are more devops, devops adjacent and "systems developer" roles in the Go language.

Re:Show HN: Rust Web Framework by egeozcan on Wednesday October 23, 2024 @03:38AM (#41922739)
Declaring a stdlib free of rough edges would be like declaring a complex piece of software bug-free.
Re:Show HN: Rust Web Framework by victorbjorklund on Tuesday October 22, 2024 @06:22PM (#41919336)
honestly sucks trying to build a large web app with just the go stdlib. The stdlib is amazing but it is not all you need for a good dx experience.
Re:Show HN: Rust Web Framework by int_19h on Tuesday October 22, 2024 @06:34PM (#41919406)
A rich stdlib establishes patterns and provides standard types for other libraries and frameworks, making the whole thing generally more consistent as opposed to something like the Node.js ecosystem, which looks and feels more like a bunch of random parts crudely fitted together through copious use of duck tape and glue.
Re:Show HN: Rust Web Framework by klabb3 on Tuesday October 22, 2024 @08:50PM (#41920419)
Concretely, Go has eg context.Context, net.Conn, http.Handler and of course io.Writer/Reader/Closer. All 3p libs will use the standard types. This means you can compose many 3p building blocks together, without any prior knowledge or coordination on their end.

When you have an insufficient stdlib, you often get compatibility issues, where things don’t compose. So you get these kind of pseudo-std mega frameworks like Tokio instead. It was a while ago I was deep in JS but I remember similar things there.

Re:Show HN: Rust Web Framework by dvektor on Tuesday October 22, 2024 @09:56PM (#41920934)
Really? What do you feel that it's missing? I write Go for a living but I have also used Laravel (and vanilla php back in the day),and both actix + axum and I think Go really does hit that sweet spot of abstraction level for backends/web services.

I will say that I do prefer Gorm only to be used to scan the table -> model, I'd still rather write the sql by hand but I also don't want to scan the rows every time. But other than that I really cannot think of what it's missing.

Re:Show HN: Rust Web Framework by wild_egg on Tuesday October 22, 2024 @10:43PM (#41921247)
Have you given sqlx a try? Manual query writing like database/SQL but convenience wrapper functions that handle the row scanning part for you. I haven't felt the need to use anything else for years now.
Re:Show HN: Rust Web Framework by Eduard on Tuesday October 22, 2024 @08:35PM (#41920300)
which Java version is the one you used last?
Re:Show HN: Rust Web Framework by threeseed on Tuesday October 22, 2024 @08:53PM (#41920442)
I develop in Go every day and it's by far the worst language I've ever used.

Having to explicitly handle every type of error immediately without any support for deferring, encapsulating, chaining, manipulating, transforming etc is antiquated and tiresome.

Rust has Option and Result types and all of the niceties along with it.

Re:Show HN: Rust Web Framework by Thaxll on Wednesday October 23, 2024 @12:12AM (#41921745)
All your complains are doable, I mean you work with Go daily and you don't know how to wrap errors?

Rust has all those nice things and yet you still need to import two of the most popular error lib to work decently.

Re:Show HN: Rust Web Framework by threeseed on Wednesday October 23, 2024 @03:05AM (#41922580)
That is not remotely comparable to proper Option/Result types.

And in Rust you don't need to import anything.

Re:Show HN: Rust Web Framework by pluto_modadic on Tuesday October 22, 2024 @09:24PM (#41920684)
hear me out. golang quality stdlib, with Option & Result types from haskell or rust.
Re:Show HN: Rust Web Framework by jon_richards on Tuesday October 22, 2024 @11:30PM (#41921515)
Don't forget enums. And lets get rid of the insane := syntax that makes no sense when basically every function is returning 2 values. Not to mention shadowing bugs like this:

  var cursor int64 = 0
  for {
    rows, cursor, err := db.PaginatedRows(cursor)
    ...
  }
Re:Show HN: Rust Web Framework by hackerbrother on Tuesday October 22, 2024 @10:17PM (#41921091)
The dream. Someone posted this, which is designed along these lines, here not long ago. https://github.com/borgo-lang/borgo
Re:Show HN: Rust Web Framework by shepherdjerred on Tuesday October 22, 2024 @10:22PM (#41921126)
Native Option/Result types + algebraic data types would solve quite a few complaints I have about Go
Re:Show HN: Rust Web Framework by egeozcan on Wednesday October 23, 2024 @02:26AM (#41922365)
It would solve many of my complaints as well.

But, to be honest to myself, I don't think anything will be too different in my day-to-day programming, nor that I would produce better code with less bugs.

Re:Show HN: Rust Web Framework by shepherdjerred on Wednesday October 23, 2024 @12:41PM (#41926756)
Adts eliminate certain kinds of bugs like nil pointer dereferencing, and, if you model your types correctly, makes invalid states unrepresentable
Re:Show HN: Rust Web Framework by threeseed on Tuesday October 22, 2024 @09:45PM (#41920849)
Sounds like Scala Native: https://scala-native.org/en/stable
Re:Show HN: Rust Web Framework by amedvednikov on Wednesday October 23, 2024 @07:01AM (#41923756)
V is Go with Option/Result, enums, ORM etc:

https://vlang.io/compare#go

Re:Show HN: Rust Web Framework by imiric on Wednesday October 23, 2024 @07:58AM (#41924069)
V is half-baked in many ways and shouldn't be considered for anything serious.

Odin[1] is a better alternative in the niche modern language space, and also shares many design choices with Go. It has operators like `or_return` and union types like `Maybe(T)`, which can in practice be used for improved error handling.

Though I honestly don't find Go lacking in this sense. The syntax is a bit verbose, but it forces you to think about how to handle every error, which is a good thing. There are far more important design topics worth discussing than this. Go usually makes more correct trade-offs where they matter compared to other languages, and most of the criticism it receives is unwarranted IMO.

[1]: https://odin-lang.org/docs/overview/

Re:Show HN: Rust Web Framework by amedvednikov on Wednesday October 23, 2024 @10:31AM (#41925416)
It's not half baked lol.
Re:Show HN: Rust Web Framework by imiric on Wednesday October 23, 2024 @12:50PM (#41926841)
Ah, you're the author. :D

I mean, kudos for sticking to it over the years in spite of the mountain of criticism, but I personally confirmed a few months ago that it's indeed half-baked. :) Certain features work sometimes, but often fail in cryptic ways. The documentation is a mixture of missing, outdated, wrong or aspirational. I've forgotten the specifics, but I remember being frustrated by it relatively quickly, and abandoning it altogether in less than a week. Good luck with it anyway!

Re:Show HN: Rust Web Framework by baranul on Thursday October 24, 2024 @10:24AM (#41935809)
Odin can be considered even more "half-baked". It is not a mainstream "corporate approved" language either. It's one thing to suggest sticking with Go or using C# as an alternative, it is another thing to suggest languages like Odin, Zig, or some other almost unknown like C3. At least V has a place at the table, with being an actual useful alternative to Go. Has a significant following and hardcore fans, because V gives them the missing features that many Go users have been begging or looking for (enums, sum types, immutability, easier C interop...). Same can kind of be said for Zig, with having a significant following, and pushing it as an alternative compiler for C.

Anyone taking a serious look at Odin or C3 (strangely morphed from C2 into being more Jai-like or Odin-like), will know they are both no where near to being production ready or 1.0 (many years far away), despite both being old. Odin has less of a following, less contributors, minimal documentation, no books on Amazon, and many of its good ideals were admittedly "borrowed" straight from Jai. Many consider Odin a Jai-clone, where it would be better to wait on the "real McCoy", which would be Jon Blow's releasing of Jai to the general public. Jai fans[1] are about as hardcore as it gets. When Jai is finally released, nearly everybody will forget about Odin or C3 (even tsoding suggested dropping it for a public release of Jai), and very few people even know about them as it is. Just about whatever Odin (or C3) wanted or aims to do, Jai does.

[1]: https://jamesoswald.dev/posts/jai-1/ (Simplicity, Jai, and Joy)

Re:Show HN: Rust Web Framework by baranul on Thursday October 24, 2024 @10:34AM (#41935907)
That has been around for a long time now. V lang[1], child of Go and Rust, has them. That, and things like enums, sum types, etc...

[1]: vlang.io

Re:Show HN: Rust Web Framework by nitaigao on Wednesday October 23, 2024 @12:25AM (#41921816)
Completely agree…

Forgetting to check any given err value leads to potentially undefined behaviour.

Re:Show HN: Rust Web Framework by giancarlostoro on Tuesday October 22, 2024 @11:10PM (#41921397)
Every time this subject comes up for any language I praise Go for making it very straightforward to start a web server.
Re:Show HN: Rust Web Framework by okasaki on Wednesday October 23, 2024 @04:08AM (#41922882)
Do you also praise Python for having http.server?
Re:Show HN: Rust Web Framework by giancarlostoro on Wednesday October 23, 2024 @10:04AM (#41925176)
Actually, I do for a different reason. I can go into any directory and type python -m http.server and now I have an improtu web server for a folder, so I can download files over my LAN.
Re:Show HN: Rust Web Framework by okasaki on Wednesday October 23, 2024 @11:22AM (#41925979)
That's a nice feature. You can also import it and it's a lot like the Go http server.
Re:Show HN: Rust Web Framework by imiric on Wednesday October 23, 2024 @12:58PM (#41926954)
Except it's not meant to be used in production, where you must use shenanigans like WSGI and 3rd-party servers.
Re:Show HN: Rust Web Framework by solatic on Wednesday October 23, 2024 @03:06AM (#41922584)
I've come to the conclusion that Professionally Pretty Products should use the JS ecosystem and Internal Web Dashboards should use Go. When your company is employing dedicated professionals for Product and UX, trying to sync their work to server-rendered Go HTML templates is just much, much harder compared to working with them in Storybook and the like. Yeah the dependency tree explosion is basically someone's full-time job to stay on top of, but when the company is already paying for Product and UX and iteration speed is key, it's a small price to pay.

But yeah, when you're building some kind of internal service with a classless CSS library that's just meant to provide some kind of dashboard to illustrate the state of your service, Go's stdlib is more than good enough and helps keep down long-term maintenance, everything will Just Keep Working.

I struggle to see where Rust fits in for web frameworks. You get the dependency tree explosion, the long compile times, difficulty collaborating with Frontend/UX. The benefit is, what, better performance? Is it really worth it?

Re:Show HN: Rust Web Framework by Oras on Wednesday October 23, 2024 @04:36AM (#41923056)
Go for web development is like PHP for machine learning.

Go is a perfect language when dealing with files or network. Once you add database layer, calling external APIs, then you face the same latency of other languages due to 3rd party integration.

Re:Show HN: Rust Web Framework by xpe on Wednesday October 23, 2024 @09:28AM (#41924884)
There are lots of Rust web-related libraries that are modular.
Re:Show HN: Rust Web Framework by WhereIsTheTruth on Wednesday October 23, 2024 @09:41AM (#41924982)
And Go compiles very fast, very few understand how important this is

Not only it is important for fast iteration, but it also contributes to the fun, waiting for compiler to finish is not fun

To me there shouldn't be any new language made without hotreload and incremental compilation

It's 2024, with the HW we have, we shouldn't have to wait more than 1 second to compile code

Fun fact, my game written in D (30k LOC), fully recompiles in 0.4 seconds (Intel i3 10400f), if i can do it, you can too