Most active commenters
  • threeseed(5)
  • wtetzner(5)
  • imiric(4)
  • stickfigure(3)
  • bilekas(3)
  • (3)

←back to thread

488 points levkk | 72 comments | | HN request time: 2.254s | source | bottom

Hi everyone,

I've been "funemployed" for a few months and with all that free time and idle hands I wrote a full web framework (think Rails, not Flask) for Rust.

It's boring old MVC, has its own ORM, templates, background jobs, auth, websockets, migrations and more. If you're keen but don't feel like rewriting your app in a different language, Rwf has a WSGI server to run Django (or Flask) inside Rust [1], letting you migrate to Rust at your own pace without disrupting your website.

I think Rust makes a great prototyping and deploy straight to production language. Now it has yet another framework for y'all to play with.

Cheers!

[1] https://levkk.github.io/rwf/migrating-from-python/

1. imiric ◴[] No.41918890[source]
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!

replies(13): >>41918959 #>>41919110 #>>41919336 #>>41919738 #>>41919823 #>>41920300 #>>41920442 #>>41921397 #>>41922584 #>>41923056 #>>41923336 #>>41924884 #>>41924982 #
2. qudat ◴[] No.41918959[source]
Agreed on all fronts. Go has nailed the stdlib and every other language is in its shadow
replies(1): >>41919078 #
3. t-writescode ◴[] No.41919078[source]
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!
replies(1): >>41920324 #
4. metadaemon ◴[] No.41919110[source]
Not needing an ORM made me laugh
replies(2): >>41919353 #>>41920132 #
5. victorbjorklund ◴[] No.41919336[source]
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.
replies(2): >>41919406 #>>41920934 #
6. sunrunner ◴[] No.41919353[source]
Why is that?
replies(2): >>41919390 #>>41927294 #
7. stickfigure ◴[] No.41919390{3}[source]
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.

replies(7): >>41919421 #>>41919544 #>>41919839 #>>41920270 #>>41920443 #>>41920482 #>>41921770 #
8. int_19h ◴[] No.41919406[source]
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.
replies(1): >>41920419 #
9. BlarfMcFlarf ◴[] No.41919421{4}[source]
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.
replies(2): >>41920405 #>>41920435 #
10. sunrunner ◴[] No.41919544{4}[source]
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.

11. zarzavat ◴[] No.41919738[source]
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.

12. bilekas ◴[] No.41919823[source]
> 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.

replies(2): >>41920844 #>>41922460 #
13. wesselbindt ◴[] No.41919839{4}[source]
> 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.

14. rad_gruchalski ◴[] No.41920132[source]
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.

15. ◴[] No.41920270{4}[source]
16. Eduard ◴[] No.41920300[source]
which Java version is the one you used last?
17. Nuzzerino ◴[] No.41920324{3}[source]
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

replies(2): >>41920504 #>>41922739 #
18. threeseed ◴[] No.41920405{5}[source]
Only for basic objects.

The minute you add relationships your approach becomes unusable.

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

replies(1): >>41920461 #
19. klabb3 ◴[] No.41920419{3}[source]
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.

20. dragonwriter ◴[] No.41920435{5}[source]
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...)

replies(1): >>41920476 #
21. threeseed ◴[] No.41920442[source]
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.

replies(3): >>41920684 #>>41921745 #>>41921816 #
22. wtetzner ◴[] No.41920443{4}[source]
There's a difference between mapping database tables to objects and just copying query results into structs.
23. wtetzner ◴[] No.41920461{6}[source]
No it doesn't. Why would relationships matter? You handle the relationships in SQL queries, and just copy query results to structs.
replies(2): >>41920622 #>>41920907 #
24. wtetzner ◴[] No.41920476{6}[source]
You can be pedantic if you like, but this is obviously not what anyone means by "ORM".
replies(1): >>41920490 #
25. deznu ◴[] No.41920482{4}[source]
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.

replies(1): >>41920846 #
26. dragonwriter ◴[] No.41920490{7}[source]
Its literally the exact things that ORMs map between: query results -> objects and object changes -> database updates.
replies(1): >>41994256 #
27. t-writescode ◴[] No.41920504{4}[source]
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.

28. stickfigure ◴[] No.41920622{7}[source]
> copy query results to structs

Congratulations, you've invented an ORM.

replies(3): >>41920796 #>>41920891 #>>41994227 #
29. pluto_modadic ◴[] No.41920684[source]
hear me out. golang quality stdlib, with Option & Result types from haskell or rust.
replies(6): >>41920849 #>>41921091 #>>41921126 #>>41921515 #>>41923756 #>>41935907 #
30. ursuscamp ◴[] No.41920796{8}[source]
That’s 1% of an ORM.
replies(1): >>41926785 #
31. mixmastamyk ◴[] No.41920844[source]
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

replies(1): >>41922427 #
32. __mattya ◴[] No.41920846{5}[source]
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.

33. threeseed ◴[] No.41920849{3}[source]
Sounds like Scala Native: https://scala-native.org/en/stable
34. threeseed ◴[] No.41920891{8}[source]
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.

35. ◴[] No.41920907{7}[source]
36. dvektor ◴[] No.41920934[source]
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.

replies(1): >>41921247 #
37. hackerbrother ◴[] No.41921091{3}[source]
The dream. Someone posted this, which is designed along these lines, here not long ago. https://github.com/borgo-lang/borgo
38. shepherdjerred ◴[] No.41921126{3}[source]
Native Option/Result types + algebraic data types would solve quite a few complaints I have about Go
replies(1): >>41922365 #
39. wild_egg ◴[] No.41921247{3}[source]
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.
40. giancarlostoro ◴[] No.41921397[source]
Every time this subject comes up for any language I praise Go for making it very straightforward to start a web server.
replies(1): >>41922882 #
41. jon_richards ◴[] No.41921515{3}[source]
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)
    ...
  }
replies(1): >>41922268 #
42. Thaxll ◴[] No.41921745[source]
All your complains are doable, I mean you work with Go daily and you don't know how to wrap errors?

https://pkg.go.dev/errors

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

replies(1): >>41922580 #
43. Thaxll ◴[] No.41921770{4}[source]
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.

44. nitaigao ◴[] No.41921816[source]
Completely agree…

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

45. egeozcan ◴[] No.41922365{4}[source]
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.

replies(1): >>41926756 #
46. littlestymaar ◴[] No.41922427{3}[source]
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).
replies(1): >>41922966 #
47. efnx ◴[] No.41922460[source]
> 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.

replies(1): >>41922931 #
48. threeseed ◴[] No.41922580{3}[source]
That is not remotely comparable to proper Option/Result types.

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

49. solatic ◴[] No.41922584[source]
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?

50. egeozcan ◴[] No.41922739{4}[source]
Declaring a stdlib free of rough edges would be like declaring a complex piece of software bug-free.
51. okasaki ◴[] No.41922882[source]
Do you also praise Python for having http.server?
replies(1): >>41925176 #
52. bilekas ◴[] No.41922931{3}[source]
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.
53. bilekas ◴[] No.41922966{4}[source]
> 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.

replies(1): >>41923137 #
54. Oras ◴[] No.41923056[source]
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.

55. littlestymaar ◴[] No.41923137{5}[source]
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.
56. ◴[] No.41923336[source]
57. amedvednikov ◴[] No.41923756{3}[source]
V is Go with Option/Result, enums, ORM etc:

https://vlang.io/compare#go

replies(1): >>41924069 #
58. imiric ◴[] No.41924069{4}[source]
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/

replies(2): >>41925416 #>>41935809 #
59. xpe ◴[] No.41924884[source]
There are lots of Rust web-related libraries that are modular.
60. WhereIsTheTruth ◴[] No.41924982[source]
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

61. giancarlostoro ◴[] No.41925176{3}[source]
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.
replies(1): >>41925979 #
62. amedvednikov ◴[] No.41925416{5}[source]
It's not half baked lol.
replies(1): >>41926841 #
63. okasaki ◴[] No.41925979{4}[source]
That's a nice feature. You can also import it and it's a lot like the Go http server.
replies(1): >>41926954 #
64. shepherdjerred ◴[] No.41926756{5}[source]
Adts eliminate certain kinds of bugs like nil pointer dereferencing, and, if you model your types correctly, makes invalid states unrepresentable
65. stickfigure ◴[] No.41926785{9}[source]
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.

66. imiric ◴[] No.41926841{6}[source]
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!

67. imiric ◴[] No.41926954{5}[source]
Except it's not meant to be used in production, where you must use shenanigans like WSGI and 3rd-party servers.
68. metadaemon ◴[] No.41927294{3}[source]
Why did it make me laugh? I thought the delivery was funny is all.
69. baranul ◴[] No.41935809{5}[source]
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)

70. baranul ◴[] No.41935907{3}[source]
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

71. wtetzner ◴[] No.41994227{8}[source]
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...

72. wtetzner ◴[] No.41994256{8}[source]
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.