6 ms·
Go can’t do a fancy ORM because of its weak type system. Rust’s type system and compiler plugin support (still being polished, but entirely usable) allow for so
by chrismorgan 12y ago
Go can’t do a fancy ORM because of its weak type system. Rust’s type system and compiler plugin support (still being polished, but entirely usable) allow for some really nifty things. An ORM like Django’s is absolutely possible in Rust—and with strong typing and serious error checking into the bargain.
We can also end up with things like HTML templates compiled into your binary and the HTML validated at compile time. Even things as precise as type checking on something like <time datetime="{{ time }}"> can be managed with Rust. And I intend to.
I’ll be talking about how some of these sorts of things can work out at Strange Loop this year: https://thestrangeloop.com/sessions/fast-secure-safe-the-web-that-can-still-be https://thestrangeloop.com/sessions/fast-secure-safe-the-web....
- pdeuchler 12y agoI think you mean Go can't do a fancy ORM because of it's strong type system?
- apendleton 12y agoNo, as compared to Rust's type system, Go's is pretty unsophisticated.
- chrismorgan 12y agoNo, I don’t. While a strongly-typed language, Go’s type system is very weak compared with one like Rust’s.
- pdeuchler 12y agoWhile I'm naively familiar with Go's type system I'm not at all familiar with Rust's, so i'll defer to you on this... That said, could you explain how Go's type system is weaker than Rust's?
- chrismorgan 12y agoThe biggest thing is the lack of generics. That alone is enough to absolutely destroy any plans for a fancy ORM. Any such thing will end up using interfaces with type assertions everywhere.
- steveklabnik 12y ago(unintentionally) Mutable state passing over a concurrency boundary is a compile-time error in Rust. Two threads cannot mutate the same data unless you explicitly mark it as such, and by doing so, you'd force it through a mutex. This basically means data races are impossible.
- unoti 12y agoCouldn't an ORM for Golang be done with a code generator that generates filter functions and such based on the table layouts and relations? Then you'd get the best of both worlds: "dynamic" operation in the sense that the methods vary depending on the table layouts and relations, plus static validation of what you're doing at compile time.
- chrismorgan 12y agoGo’s type system is still not powerful enough to express such a thing; ORMs depend on blending things together from all over the place, e.g. with joins, method chaining and other things which really need genuine generics. There really is no solution without generics.
- unoti 12y agoIt seems to me that the method chaining is really all about building an internal S-Expression or tree structure of some kind that describes the type of query and joins needed. When it comes to solving problems, it's shaky ground to insist there can only be one possible approach.
- slight 12y agoAre you seriously suggesting that a statically typed language without generics can't do ORM?
- chrismorgan 12y agoWhat most mean by and expect of an ORM—yes. Extensive use of reflection (in Go, this takes the form of type assertions) proceed to make it fundamentally possible again, but they have lost a lot of conciseness, certainty of safety and correctness in the process.
- twic 12y agoYou can do it with code generation, though, right?
- tptacek 12y agoThe most popular current ORM is written in Ruby. I find your argument hard to buy.
- chrismorgan 12y agoI look forward to trying to convince you! ☺
- pcwalton 12y agoI think what he means is static type system expressiveness, rather than type system "strength" (which is a term I don't like, since it's so overloaded as to be practically meaningless). Since it's dynamically typed, Ruby's static type system is maximally expressive. Go's type system (as with Rust's, or Java's, or any statically typed language) is less expressive by comparison. I'm not ready to say that Rust's type system lends itself perfectly well to ORM's, as I haven't really seen an ORM as convenient as ActiveRecord in any statically typed language. (This is one of the reasons I like both statically and dynamically typed languages.) But I'm happy to see people try, of course, and I'd love to be surprised.
- codygman 12y agotl;dr ORM's with type safety and comprehensive error checking are possible with statically typed languages provided the type system is flexible/powerful enough http://ocharles.org.uk/blog/posts/2013-12-06-24-days-of-hackage-persistent-esqueleto.html http://ocharles.org.uk/blog/posts/2013-12-06-24-days-of-hack... More in-depth interactive tutorial: https://www.fpcomplete.com/school/starting-with-haskell/libraries-and-frameworks/persistent-db https://www.fpcomplete.com/school/starting-with-haskell/libr...
- Keats 12y agoSince you are the main force behind HTTP in rust, when do you think it (and rust) would be ready ? You just started on Teepee and it seems like there are lots of breaking changes on rust itself every week so that's not really inciting me to check it out for now. That talk looks really nice too, a shame it's in several months. Continue the good work !
- chrismorgan 12y agoThere are a few factors at work here. I hope to be able to secure some form of backing to allow me to work on it more (as it is, I’ve been taking Thursdays off to work mostly on Teepee). If anyone is interested in sponsoring me to work on it, I’m all ears! If I get backing things will happen much faster, to the level where I would expect to be able to write “ARGUABLY.” (though still not “Yes!”) on arewewebyet.com by approximately the end of this year. If not, it will probably take at least six months longer. I’m definitely in with Rust and HTTP for the long haul. Hang round, things will get better.
- Kiro 12y ago> Go can’t do a fancy ORM because of its weak type system. I don't understand what the type system has to do with building a fancy ORM. Do you mind elaborating?
- surrealize 12y agoSpeaking of interesting things you can do with type systems for database interaction, have you looked at the sqltyped library for Scala? https://github.com/jonifreeman/sqltyped https://github.com/jonifreeman/sqltyped
- voidlogic 12y agoStrong and weakly typed don't mean what you think they do. Strong typing is not about the expressiveness of a type system, rather about it having type safety, being memory safe and having static type-checking, and not having unsafe type conversions (and to a lesser extent implicit type conversions) and unions. What you meant to say was Rust's type system is more expressive then that of Go's.
- bryanlarsen 12y agoIOW, he used strong in a colloquial manner rather than in a formal manner. Not wrong, but definitely confusing.
- haberman 12y agoAny links to more info about Rust compiler plugins? That sounds really interesting.
- steveklabnik 12y agohttp://blog.burntsushi.net/rust-regex-syntax-extensions http://blog.burntsushi.net/rust-regex-syntax-extensions
- thinkpad20 12y ago> We can also end up with things like HTML templates compiled into your binary and the HTML validated at compile time. Even things as precise as type checking on something like <time datetime="{{ time }}"> can be managed with Rust. These things are already done in several of the Haskell frameworks. There's even Blaze, which is a Haskell DSL that allows you to write HTML entirely in Haskell. Personally, static verification of HTML doesn't seem that necessary, but I suppose it has its merits (possibly for security?).