481 points · by ingve · 9y ago · 580 comments
> For comparison, I switched from Rust to Go and, in the same amount of time I had spent stuggling [sic] to make even a <100 LOC partial implementation work, was able to write and test the entire exterior of an IRC server - all the socket-fu and concurrency handling - leaving only the IRC-protocol state machine to be done.
I don't think this is an unusual experience. I'd consider myself a journeyman programmer with 16 years of experience and probably a dozen languages under my belt. Learning Go was unique: after 3 days I felt productive; After 2 weeks I sort of looked around and said "is this it?" Go gets out of your way for the most part, and performs as advertised.
For a lot of programmers, for a lot of projects, that's exactly what you want.
I've attempted to learn Rust a few times, and it always feel like I'm moving uphill.
Rust is awesome for a number of problem spaces, so I'm not knocking it. And Go _isn't_ awesome in a lot of ways (vendoring, I'm looking at you). But it feels like there are a lot of core, language-level things Rust needs to improve to attract more non-genius developers.
Go is an easy, fast, and very parallel language. Go is exactly what google needs, in all regards. It makes sense why Go exists, it makes sense why google is creating a way to migrate from python2 to go. Go is easier than hard C and Go is fast.
Rust is the safe follow-up of C, but more familiar than Haskell, Caml and such. It's a pain to get working, it sucks to program in, it requires so much thought, it's just a bloody fucking fuck. But once rust runs, it works and there's a very very good chance it won't break.
And that's also the reason why we'll probably build firewalls and hardened OS in derivatives of Haskell and Rust, and we'll build Google 2 and Facebook 2 in Go. And in my book, that's a good thing.
What sucks about programming in Rust? What makes it a bloody fucking fuck? I disagree on both these points:
* Rust enums and move semantics make writing state machines a pure joy. Far nicer than in C++ or Go.
* Pattern matching (both fallible + infallible) is very developer friendly.
* Option<T> and Result<T,E> are totally brilliant.
* It's trivial to add and version-fix a dependency on an external library with Cargo.
* Rust's ownership and move semantics help you to write cleaner, easier to understand code.It took me longer than 4 days (almost two weeks) to just read the rust book (part time), so yes you're not going to get from 0 to 100 in just four days. If that's your benchmark, how fast you can get going, then you're right Rust isn't for you. But nobody would expect anyone to get up to speed with C++ in just four days.
Rust is a systems programming language with a focus on security and performance, not a play toy for people looking to write small scripts.
My understanding is that the rust team has put 2 priorities ahead of everything else: zero cost abstraction and safety. Given those constraints they've done a fantastic job in the area of ergonomics, but I don't know if it will ever be easy. Maybe rust is as easy to use as it can be.
Honestly I feel like peoples biggest issue with Rust is that they're trying to write things in Rust that don't actually need Rust. They want the ease of use that you get with a garbage collected language and then get annoyed when Rust forces them to worry about allocations and cleaning up after themselves. C++ should have the same issue but its been around long enough that most of those details have safely been wrapped behind STL and other abstractions to the point where most people don't need to worry about them. Perhaps in time Rust will reach that point as well and everyone will be using the equivalent of Boost that abstracts worrying about whether something is a Box<ARC<Foo>> behind a nonthreatening layer of macros.
I would phrase it like this:
• Go is a useful, safe subset of C (with a rather expanded libc.) Go lets you do fewer things than C (e.g. hard real-time things; processor-optimized things) but for most people, they don't need those things, and delving into them was what seeded the bugs into their C/C++ projects in the first place, completely unnecessarily.
• Rust is a formalization/codification of idiomatic C++. It's not a subset; it's a rethink, like Plan 9 is a rethink of Unix. You can do everything in Rust that you can do in C++, and the compiler will catch (nearly) all the bugs you would have left in the equivalent C++ project.
In other words, Go says "you don't need this"; Rust says "if you're so sure you need this, let's ensure you do it right."
For any given piece of code, either Go's assertion or Rust's assertion could be "correct." You either need the things only Rust lets you do, or you don't.
For a large codebase, though, I expect the answer is actually nearly always going to end up somewhere between. Big apps or libraries always have that one part that does heavy lifting and has to go fast, but go fast correctly; and 99% that doesn't.
Thus, I envision the future of many "systems software" codebases to look like this:
1. (1% of LOC) an "engine" library, written in Rust, which compiles to a C-ABI shared object;
2. (3% of LOC) an "engine wrapper" library, written in Go, which imports the "engine" object using Go's C FFI and then exposes a safe Go API to it—and also, the tests for the engine library, written in Go because it's easier;
3. (96% of LOC) the app itself, written in Go, which calls into the "engine wrapper."
Idiomatic C++ favors values and copy semantics. Rust favors references and move semantics. C++ has function and method overloading, and Rust does not. There are so many places where Rust chose exactly the opposite of "modern" C++ that calling Rust a codification or formalization of C++ makes no sense at all to me. Rust has some great features, and C++ has a lot of warts, but Rust is definitely not an improved C++.
Rust seems like a reaction to problems in C++, but for many design decisions I think they erred on the side of doing the opposite of C++ and ignored the things C++ does well.
This is a bold claim, IMO somehow misleading. To "do everything you can do in C++", you have to use the unsafe part of rust, where you essentially lose of the compiler guaranty. Second and maybe ever more importantly, rust never promise the remedy to "nearly all bugs", the universe of bug preventable is a well-defined limited set.
I could not disagree more! Rust is a great joy to program in. I would rather program in Rust than any other language.
Rust is challenging for many people to learn. That is very different.
The borrow checker and ownership model is a huge tradeoff. Even those very experienced in it still fight it from time to time. Go made a different trade, they chose GC. And GC _is_ easier. But it has computational overhead (well today anyway).
Consider the cascading implications. Rust has a trait for Copy vs. Move types. This means every type has an implicit, and unknown behavior, on certain assignments:
let v2 = v;
println!("v is: {}", v);
You can't actually tell me whether the above code compiles without consulting other parts of the code. That's not the case for Go. It is thus simpler and more intuitive to program in.But it is a trade-off. Go as a language must have a GC. It will never be suitable for certain tasks as a result.
Go also has less compile time checking. This means faster compiles, quicker dev cycles but less compile time safety. Go chose easier here again. These trade-offs are what make rust seem "difficult" in comparison to go. I don't know if you can ever "fix" them.
That's great until you try to do some real world things with it and run into endless impedance mismatches.
Rust isn't quite so far up its own butt, however the developer community doesn't seem to realize that there's a massive gap between the toy example programs in their documentation and the level of knowledge needed to build something worthwhile.
Go isn't a replacement for C; you can't use it for many forms of low-level systems programming, because it has a runtime. Go provides a high-performance replacement for things you might otherwise write in Python or similar, and in that capacity it works quite well.
Rust can do anything C can; its capabilities build upwards from bare metal, not downwards from higher-level languages. It intentionally doesn't have a runtime, and its approach to avoiding garbage collection (namely borrow checking) provides safe memory handling without a runtime at the expense of being a novel language feature without analogue in other languages. Much of the learning curve in Rust comes from that.
Now that developers are ready for new languages, D is already an "old, failed" language.
It reminds me of selling a house. If you put your house during a hot market and go into contract right away, but then your buyer can't come up with the money and it falls out of contract three weeks later, bringing your house back on the market it's now no longer "newly available!", and everyone thinks that, because it didn't sell in the first week, there must be something wrong with it.
My personal entirely uninformed opinion of D is exactly that: It's an older, "failed" language. It's not on the upswing in popularity. It didn't catch peoples' hearts and minds. And if only because of network effects, therefore it's not worth learning, simply because no one else is learning it, and so therefore its ecosystem isn't expanding exponentially.
Success of technologies is far less merit than one might expect. See: VHS vs. Beta.
Learning D and Rust requires an effort Go proponents are not capable of.
Another problem is that both D and Rust try to replace C++ and C respectively. But C++ and C developers would never switch to anything else as they feel comfortable using the later, even despite all the gotcha of manual memory management.
Most people using Go today come from Python,Ruby,PHP,JS and co, not from C or C++ or Java. They want performances, without paying a price for "complexity". D is fine today, but it lacks a community behind it and a good ecosystem for web development.
If Rust had garbage collection, it would certainly be more popular but it's not going to replace C anyway. We are stuck with C and C++, they are not going away.
I understand why Rust is what it is, I also understand that most developers don't want to deal with explicit move semantics and lifetime management. Rust isn't going to seduce Ruby,Python,PHP or Javascript developers. the later only want better performances and think Go is good enough. They don't care about explicit memory management.
I'd like to see a version of Rust with garbage collection. The language itself is good.
TLDR: Rust did the hard work of convincing others to try it out and evangelize the language, and as a result, it has become popular and has grown a strong community.
the syntax seemed extremely similar, as if they took c++ and just tweaked it a bit, rather than working at least somewhat from first principles.
seemed almost comically pointless at the time. no doubt it's evolved since then.
I've tried to get into Rust on/off and each time I'm left feeling like I needed a semester of instruction just to write a trivial program. Each attempt to go back to it, I would immediately hit a wall.
Go, on the other hand, felt quick to pick up. While I don't use it a lot, it's focus on a few composition patterns, and really sticking by that, made it easier for me to learn and come back to when I go back to my Python-centric existence.
Rust on the other hand, I haven't thought about nor touched, outside seeing an HN headline.
I think your logic is not sound . If they wanted to use python2 (only with their own runtime which does not have GIL) instead of switching to go (eventually) they would write a runtime instead of transpiler ?
Please correct me, I am not 100% sure.
I only play around with it for personal projects but I would have thought that if I went from scratch and spent four days on it like the article stated that I'd be pretty productive.
It's too bad that you feel that way but lots of people like programming in Rust and don't like programming in Go. I have never before had to pay so much -- in terms of type annoyances, packaging workflow and boilerplate -- for so little.
This is a terrifically powerful, and very unusual, advantage for a language to have. Master programmers won't be choosing it as their tool of choice. It won't be used to attack the craft's hardest problems. But it allows a huge number of people to write programs they otherwise would not have been able to write, and, conversely, a huge number of programs to be written which otherwise would not have been written. There's something rather "quantity has a quality all its own" about it. As with PHP, this is something of a mixed blessing, but it certainly puts a dent in the world.
I see almost the opposite, with many new distributed systems being written in Go.
But every time I need to dig down into the source code, I quickly realize why Docker falls over all the time with weird bugs, and why Vault's high-availability backend for etcd falls over once per week, and why Kubernetes is capable of inspiring such epic love-hate relationships.
There's a ton of code in Docker where nil can sneak in, and where the types of certain data structures are harder to determine than they should be. Sometimes nil represents "none", and sometimes the empty string does. There's a bit of multithreaded stuff in Vault's etcd backend (or was) that doesn't understand the corner cases inherent in concurrency.
I'm totally convinced that these new distributed tools are awesome and a boon to our industry. I just wish that somebody had a long conversation with a good type checker and thread safety checker at critical moments during the implementation process.
This may be a classic case of the "New Jersey approach": https://www.jwz.org/doc/worse-is-better.html Software that's sufficiently innovative and which works will be forgiven odd corner cases and bugs.
Don't get me wrong, it a great, practical, engineering-oriented 90% solution kind of language; "conceptually sound" seems like computer language theory got involved, and it didn't.
None of those languages strike me as being both elegant and state of the art at the same time.
Meanwhile the "weapons for a civilized time" such as Lisp or Haskell haven't really gotten a major hold in either a Fortune 1000 company or the software giants on the West Coast.
It's like there's no correlation between "hacker points" for a programming language and the actual results delivered with that language! I'm being ironic, there isn't any. I'm open to someone proving me wrong though...
To pedantically respond to your question, note that what i said was that master programmers "won't be choosing it as their tool of choice", by which i mean that it won't be the language they dream about being able to use on their next project. Of course, if Go is the right tool for the job, a sensible and honest programmer will use it.
A large part of the reason Javascript has taken off is it's ability to "get out of your way", however you pay for that in the long tail of issues and undefined things.
Many projects in software are trying to prove out a concept, and in those cases is makes sense to move fast and find out if the core thing you're doing works. However in problem domains that are well understood or have strict performance/memory requirements Rust really shines.
I think there's a strong argument that this is a subset of software(and probably not the majority) however I feel that unless you're taking a project to 100%(remember the last 10% takes 90% of your schedule) ESR's comparison isn't fair.
So, I guess you can "ignore" stuff in other languages and feel like it's working, with less guarantees it is actually right. Most of the things you need to do in C, Rust just codifies and enforces.
What dynamic languages have as an advantage is that they allow you to more readily change your system as your understanding of the requirements change. This is where static type systems have traditionally been very weak - they create roadblocks for evolutionary change.
What would be great is a type system which catches your bugs but doesn't block you from evolving. I actually think Rust's use of type class polymorphism ("traits") goes a long way toward that goal, once you learn it.
The Go comments sound a lot like Java in the early days. Easy language. Quick to get started. Easy to get lots of programmers. If desperate, just train them. Today Java is not so simple anymore, because the Pros wanted more features (eg Generics). I believe Rust will get Generics at some point. Typesafe containers are too useful.
I certainly hope the Go authors can find an implementation of generics with a set of tradeoffs that appeal to them. Typesafe containers certainly are extremely useful.
https://news.ycombinator.com/item?id=9622417
I agree, the value in generics/templates is in not cutting and pasting an algorithm or container to handle multiple types safely. A true macro system (and Rust's is pretty good one to model after) also solves this problem, and I wonder if Go would ever consider adding such a thing. It seems like a safer approach.As an aside, I keep seeing people don't "get" this, and it is painfully unclear to me - why?. Perhaps the pool of people with 15-20 years that are still doing programming is very small, so they make very tiny noise.
I'm at 20 years of paid, professional coding, and 30+ if you count my Apple IIe/gs days and fooling around with C++ as an undergrad.
It took me about a week or two to make friends with the borrow checker, and mostly those were self-inflicted wounds from trying to write aggressive zero-copy code.
I think that Rust works very well for certain coding styles, but the learning curve is much higher for other coding styles. If you've been scarred by C++ and you're used to treating variables as mostly immutable, the learning curve is pretty reasonable. But if you work in a style with a lot of mutability and you've never wrested with "const char *" versus "std::string" in C++ (which both exist for a good reason in C++), there's more to learn. So I could legitimately see it go either way.
My handy litmus test: Do you utterly despise C++, or do you have a complicated love-hate relationship with it? If you fall in the latter group, you may fall in love with Rust on the first try. If you've never even used C++ enough to have an opinion, then it's possible you might not care about high-performance static languages and the prices they pay to go fast, and so Rust's trade-offs might not even be interesting to you.
[0] Unless that something is Rails templating because dang, that is some crazypants there.
Maybe I'll give Rust a go after all. No pun intended. ;)
When I tried Go I just didn't get what it had to offer. It felt like the wheel, reinvented. I was like "That's it?". I can see how that's appealing but, for me, Rust is a stepping stone on what we should expect from programming languages of the future.
A new language with a new paradigm is going to take longer to feel productive in, especially when the tooling and libraries aren't quite there yet. I can see how that's not good for someone who wants results now.
Rust's ecosystem is very much in its infancy. I expect 2017 to be a great year in terms of both language ergonomics (e.g. see Rust Language Server) as well as stabilization/standardization of very important things like how to do concurrent I/O. If your niche is distributed computing (e.g. I/O bound servers), yes, Rust is currently not going to satisfy you.
I think comparing Rust and Go is not fair for neither of them and, even if both are advertised as "systems languages" they are actually very different beasts filling their unique niches.
It's worth noting here there is a large, active team from the open source community working on fixing vendoring and package management right now. I believe the target is the Go 1.9 timeframe (end of Q2ish this year).
This is an interesting thing I realized after I read the postmartem report of why "rethinkdb failed".
Users want something they can get and build apps with quickly, rather than something feature perfect four years after they want to build apps.
Go essentially answered the question, "I want to write a webapp, don't want to use Python or RoR, what do I use?". It is because of the easy to understand syntax and the powerful stdlib they were able to answer that question.
The language is amazing. I don't have any idea about Rust, so won't comment on that.
Isn't this also because it's actually quite a bit different from other languages? I think how difficult something is to learn is largely dependent on how similar it is to something you already know.
I can see how from a business standpoint, being able to start coding is great, but I also feel a bit sad when I see people not really giving a language a real chance, especially when a week or two may not be all that significant in the long run, whereas choosing a technology is potentially pretty significant long term.
I started to combine channels freeform and enjoy new ideas every minute, almost no cruft, almost no dead ends ... that's a rare thing.
They did circle the concurrency pretty neatly in a nice usable interface.
It's not like that, it's not hard to need geniuses, it's just too different for most people. And different takes time to learn. Which is definitely a design flaw for a language aiming for some adoption. I don't think they can improve it at this point, but they can provide a lot of value where other languages are weak.
Rust has the same problem as C++ (to a lesser degree; maybe it'd be more fair to compare it to Java), in that if you're a casual coder who dips into a bunch of different projects in a bunch of different languages without ever really specializing, it can be overwhelming. Go is much more readily accessible; partly because it is less ambitious, and partly due to philosophical differences. I can read most Go code, today, having only worked through "A Tour of Go" on the website; I can't even begin to read Rust code after similar time/effort invested.
So, yeah, Rust really is hard. It may be necessary complexity to solve the problems they wish to solve. But, it means I'm unlikely to ever have the time to invest to make it a part of my toolbox, unless it becomes my primary job; whereas I'm already almost there with Go. I'll probably build something real in Go within the next month or two. It can be something I do for fun, in my spare time, and I can expect to get useful results.
I want to like Rust. I'm just finding it hard to get to know Rust.
For me I feel like it took time but I've formed a good intuition and understand of the rules, but I would have a very difficult time formalizing a description.
I'll quote some of the proposed vision statement here:
# Rust should have a lower learning curve
Rust unique features make it valuable, but also means there's a lot to learn.
A common refrain is "the first couple of weeks are tough, but it's oh so
worth it." How many people are bouncing off of Rust before they get through
those first couple of weeks? How many team leads are reluctant to introduce
Rust because of the training needed? 1 in 4 survey respondents mentioned the
learning curve.
Some potential avenues: improved docs/training materials; improved compiler
errors; language improvements (e.g. things like non-lexical lifetimes).
# Rust should have basic IDE support
For many people—even whole organizations—IDEs are an essential part of the
programming workflow. In the survey, 1 in 4 respondents mentioned requiring
IDE support before using Rust seriously. Tools like Racer and the IntelliJ
Rust plugin have made great progress this year, but compiler integration has
yet to get off the ground, and there's a lot of room to do more.
# Rust's community should provide mentoring at all levels
The Rust community is awesome, in large part because of how welcoming it is.
But we could do a lot more to help grow people into roles in the project,
including pulling together important work items at all level of expertise to
direct people to, providing mentoring, and having a clearer on-ramp to the
various official Rust teams. Outreach and mentoring is also one of the best
avenues for increasing diversity in the project, which, as the survey
demonstrates, has a lot of room for improvement.
[1]: https://internals.rust-lang.org/t/setting-our-vision-for-the...This was an issue as I learned. With widely popular languages, googling a simple question like "reverse a list javascript" or "sum an array php" comes up with a hundred different suggestions and discussions.
With Rust, most of the discussion is very low level, often by people working on Rust itself and usually the rare answer you find is terribly out of date.
Just having a more stable language so answers don't become obsolete is a big step, but it will still take time for those very basic questions to get answered.
let mut v = [1, 2, 3];
v.reverse();
assert!(v == [3, 2, 1]);
let a = [1, 2, 3];
let sum: i32 = a.iter().sum();
assert_eq!(sum, 6);
I'm not saying everything is simple, and there are hard parts of rust to learn. But as far as solving simple problems, I haven't ever had an easier time then with Rust. -- every single developerI can totally relate to this: I spent almost a year reading blog posts about Rust or comments on /r/rust, between the first time I read the Rust book and the time I fell confident enough to write m'y first Rust software (a cli tool).
In the meantime I learned Go in three days and I was able to work with it.
Why did I continued to learn Rust your may ask ?
Comming from web languages, learning Rust was a pilgrimage. I learned so much about low level computer sciences: what is memory locality, what's a data race, how does a memory allocator work, what is inlining, etc. It was definetly worth the time I spend on it.
And now that I'm proefficient with both Rust and Go, I can tell I prefer Rust by a large margin. Rust is a really well designed language, with a really nice community and a decision process designed to improve the language with feature real people need. Whereas Go is a monolyth controlled by its creators built around the dogma of symplicity at all cost, and they usually reject users proposal for improvements.
Besides the politics, Rust is way more expressive and going back to Go is always boring because of the boilerplate. It's also way easier to shoot yourself in the foot in Go than in Rust, by ignoring error, misusing a shared variable (forgetting to use a lock, or using it improperly) or dereferencing a null pointer.
In short IMHO Rust is more difficult to learn than Go, but you learn more and when mastered, the language is more helpful.
To all of you strugling learning Rust: carry on, it's worth it ! And also, don't wait and go on #rust-beginners [1] on IRC[2], it's really helpful.
[1] from a web browser: https://client00.chat.mibbit.com/?server=irc.mozilla.org%3A%...
[2] irc.mozilla.org
"Latency and soft-realtime performance
"Again, zero-overhead abstractions and no stop-the-world GC pauses give Rust a clear +1.
"It is worth noting that Go came nearest disqualifying itself entirely here. If it were not possible to lock out Go’s GC in critical regions Rust would win by default. If NTP’s challenges tilted even a little more towards hard real time, or its critical regions were less confined, Rust would also win by default."
As an aside, if ESR couldn't get Rust's ownership model, I wonder how long it took him to internalize how not to write memory bugs in C?
In a sense yes, although Go compiles to native code and offers completely different performance compared to an interpreted language like Python, and no JIT warmup periods of JIT compiled languages, and no dependencies on runtime environments or virtual machines, and from the outside runs confusingly similar to a native C application.
Also, C/C++ is such huge languages that they are in use in _far_ more scenarios than low level systems programming. Maybe that was the intention when they were designed, but usage exploded on e.g. Windows before the days of .NET and many still prefer it over .NET due to performance. Even if these are then desktop applications using Win32, Qt, or even MFC. C is also heavily used in development of e.g. GNOME applications with GTK+. Also a huge field of non-system level desktop applications. C / C++ is also usually preferred for games development.
This is why I think there's room for Go even in the context as a C/C++ successor simply because of the field where C/C++ is used is just so darned huge, although I do agree that if the application here is a close-to-metal application where you don't have time to wait more than a millisecond on a garbage collector or need complete control over memory use, Rust may be more useful and in this sense yes, be more like a spiritual successor to C as well.
In C++ I loathe generic programming, a template instantiation error is something I fear. Whereas in Rust I knowingly compile broken generic code all the time, because the errors are (usually) good enough to help me fix it.
Rust's type system, like any type system, is limited. It enforces a certain style of safe programming and will reject other styles of safe programming.
The compiler is also not great at explaining why something is wrong. I'm not knocking the compiler writers, because it's a hard problem and they're putting serious effort into it. But from ESR's perspective, he's writing code that is safe (according to a style he's developed over decades of programming) only to have it rejected with an explanation that doesn't make sense. It's frustrating.
There are ways to improve the learning experience. You can improve documentation, improve compiler error messages, and improve the type system itself (e.g. non-lexical lifetimes). The Rust team appears to be taking all of these seriously.
I think the people who make it past the initial frustration are those who believe that it will be worth it. I'm a huge fan of type safety guarantees. I've also followed the development of Rust enough to know that the people making decisions are good at designing languages. So when I'm frustrated, I remind myself that this is probably all worth it.
But reading ESR's write-up, he's clearly not coming from the same place. He believes that Go and Rust both have "strong type systems", which is clearly false. He complains about Rust exposing an unsafe construct like mutexes without realizing that Rust mutexes are much safer than in C. But to be fair, he's also thinking about a specific project that needs an efficient epoll-style mechanism and Rust is just not there quite yet.
1. Rust never "course corrected" to implement CSP, and as far as I can tell ESR is making that up.
Rust actually implemented channels and tasks as builtins first, with no mutexes or shared state available--those came later. At some point we saw the opportunity to reduce the complexity of the language and move the language closer to the metal by moving channels and threads to the library instead of keeping them as primitives. Mutexes and reader-writer locks followed a year or two into the language's development--in fact, they were partially implemented on top of channels at first. In fact, the motivation was essentially "hey, look at this neat thing I can do with borrowing: safe mutexes!", not "let's get rid of channels".
2. The idea that channels are going away is also untrue. I've heard a couple of people wish that channels could be removed the standard library and moved to the nursery since they're a fairly complex implementation, and embedded users might want a slim libstd. But nobody has ever floated the idea of channels just vanishing outright in favor of shared state and mutexes: it's absurd. Moreover, the standard library is stable and must be supported going forward, so we can't make that change even if we wanted to.
3. Go has mutexes as well. They're right in the library in the "sync" package. They're fairly idiomatic too: embedding a mutex in your structure as an anonymous field so that your structure can inherit the Lock() method is common.
4. ESR needs to be clear about exactly what defects can arise with mutexes. If he were to enumerate them, he'd find that Rust's type system is carefully designed to avoid them.
Easy vs Hard as in: - Easy to learn - Familiar looking - I know most of it already vs - Hard to learn - Nothing works as I'm used too - It's all new to me
Simple vs Complex: - Its parts are self-contained - The parts don't depend on each other - Quick to get something done once you understand it vs - Can't separate the parts from the whole - Each part depends on other parts - Slow to get something done even if you understand it
Most programmers and businesses value Easy vs Hard, because they think about themselves, not delivery of great quality software. If you focused on delivery of great quality software, you'd conclude hopefully that easy vs hard doesn't matter as much as simple vs complex.
Having said that, I think Go is easy, and for the most part, it is also pretty simple. While Rust I'd say is hard, but also very simple. Its simple in Rust to make correct software, but not easy. C is easy, but complex. C++ is kinda hard, and also complex.
So both Go and Rust are great improvements. Go chose to still be easy, at the detriment of how far it could innovate, but it still innovates. This approach is pretty smart, because what will happen probably is that a lot of people will move to Go, as it is not a very hard change from what they know, and then they will move to Go + 1, and then Go + 2, and then Go + 2, and eventually they'll end up at Rust, or something similar. Doing it that way is easier.
There's lots of this in Rust, especially in the form of premature specialization. If you define a struct or a method in Rust, you might be forced to make some decisions about lifetime, static vs dynamic dispatch, memory representation, mutability, etc.
These things are tied together deeply in order to create a tractable space in which the type solver may operate. Granted, this may also create a tractable space in which for you to think about these same issues, but that doesn't mean its any less complected/complex.
Although in the context of the simple vs easy notion, I suggest you grep this page for "inherent complexity":
https://github.com/matthiasn/talk-transcripts/blob/master/Hi...
He talks about the inherent complexity in resource contention.
I will point out one choice quote:
"It's making things complex because that's a decision that needs to be made by someone who has better information."
Rust addresses this by forcing you to highly parameterize code statically, which is probably the least bad solution we have right now for this sort of stuff in a low-level language.
No pain, no gain, but sure.
> Translation distance
62K lines sounds like typical C with no code reuse to speak of, A clean-slate rewrite I'd hope would be much smaller, though admittedly talking about corrode and c2go speaks of the other direction.
> Concurrency
No mention of Rust being data-race-free and Go not; unacceptably lax.
> > While I give the Rust designers credit for course-correcting by including CSP, Go got this right the first time and their result is better integrated into the core language.
Wat. Rust was originally all about CSP too, but they went away from that because there was no need to stay. You can still do all the channel stuff you want but there's little benefit force that idiom. Go's special support for this is like....special-cased generics right?
> epoll
Mio? (sure future-rs is not yet ripe, but mio alone is last I checked.) Overall, ESR seems sprinkle in lot of hatred of dependencies (bloated standard libraries are such a crutch around not having a good ecosystem), which I personally find laughable as the brightest future of FOSS is large-scale code and abstraction reuse as Haskell, Rust, and the like, are just making mainstream.
Um... you can derive the amount of code reuse in a project given no other information than the number of lines of code?
If your abstraction has a real-world vs purely mathematical / programmatic purpose, it probably sucks.
Functor > UserLoginFactoryBean.
I have production systems which run several 100k goroutines at once with very little overhead.
Instead, we're layering platform-specific code in external libraries. At the raw C-level bindings, we have libc [2] and winapi [3]. For higher level APIs, we've got Mio [4] which abstracts the system APIs, and now Tokio [5], which uses futures to simplify async operations.
We're just working our way up the stack. All of these are being developed by members of the various Rust teams, so they're as "official" as everything else we're doing.
[1]: https://doc.rust-lang.org/std/net/ [2]: https://crates.io/crates/libc [3]: https://crates.io/crates/winapi [4]: https://github.com/carllerche/mio [5]: https://tokio.rs/
Thread-per-connection is the simplest way to do concurrent networking in Rust using only libstd, but it's not the way that most Rust programmers would actually use (at least, not for a production server handling a large number of connections).
This is also true about OS threads!
Goroutines are _very_ light (8KB stack size)
2kb, actually.If a goroutine calls into C, and the C code overflows or otherwise writes ‼Fun‼ onto the stack¹ … can it clobber an adjacent stack of another goroutine or other memory?
Edit: Does "But that's true of Golang as well" refer to the one thread/socket model or not having epoll? I may have misinterpreted what you were saying...
(I know it's doable; I did it for a portscanner, where I needed fine grained timer control. But I had to forego the Go networking stack to do it.)
(Early versions of Go had a "network channel" concept, but that was removed from the language: https://softwareengineering.stackexchange.com/questions/1540...)
Seems pretty similar to me.
See this very very old HN thread:
https://news.ycombinator.com/item?id=3565703
(Hopefully the standard library has improved since then.)
It just happens to offer a similar model (and have a select operation).
I'd definitely agree that at this point Go is better for network services, and the learning curve / documentation / infrastructure of Rust is a bit scattered. I believe that as Rust matures it'll be better for the non-server stuff (no GC, etc.) and eventually become competitive with Go in this space. I'm quite fond of both languages, though!
When I've worked with Rust, 90% of the time I found it just as easy as working with something like JavaScript or Python. However 10% of the time it becomes much much much more difficult. And those times I often end up going in the wrong direction, reading documentation and trying to apply a solution which doesn't fit (i.e. no syntax that will make things work because I am fundamentally doing the wrong thing).
For example, the other day I tried solving a problem in which I had to do an in-place matrix transposition on some slices and I was getting a bunch of compile-time errors for everything I tried. I googled later on and found this [0], which makes it seem like I would have needed to use `unsafe`, however maybe that's just a misunderstanding and there is a safe way.
People are making it out to be harder than it actually is. The semantics aided by the compile-time errors make most problems quick to solve. It's very expressive and gives types which help to avoid fragile code (e.g. `Result` and `Option`). The only times that it becomes difficult are when you need to reach for a solution but do not know what to search for, and I think this could be improved if some of the errors linked to related topics, and once the IDE support improves.
[0] https://athemathmo.github.io/2016/08/29/inplace-transpose.ht...
I have an idea as to why the author approached it this way: typically Rust wouldn't let you take out a mutable borrow to a vector while you're iterating over it. If Rust did allow that and you modified the collection then the iterator might reference freed memory!
A common way around this is to just use a typical `for <range>` loop and index into the array directly to limit the scope of the mutable borrow to _a single iteration of the loop_ and not _the lifetime of the iterator._ However indexing in Rust incurs a speed penalty for bounds checking, and the unsafe code here lets you skip those checks.
Really all the unsafe code is doing is saying: "I promise to initialize `rowcol` entries, and I won't try to access anything outside `rowcol`. Please don't burn cycles worrying about it Friend Compiler."
It looks to me as though this could've been written as a vector initialized with all zeroes (which possibly isn't even that expensive, since modern OSes heavily optimize the case of giving you a zeroed page.) Then in the hot loop the author could've just used iterators to avoid the bounds check. Using an iterator for that should be fine in this instance since you're immutably iterating over one matrix, and the only mutation happening is in the new transposed matrix.
That all being said: transposing the matrix in-place would run into exactly that scenario. now you could still do it in safe rust, you would only need to add the unsafe code if you wanted to turn off the bounds checking for maximal performance.
TL;DR: we have some concerns. :P
I agree 100% with this scoring. I'm not sure though why he weighted the 3 pros of Go as more important for NTPsec since the goal of the project are: "Our goal is to deliver code that can be used with confidence in deployments with the most stringent security, availability, and assurance requirements." Given this goal I would personally say that safety, security, deployment ease and performance are critical, which given his pros and cons would make Rust a better candidate.
What I do think is a fair point is Rust's learning curve. With that in mind I would like to suggest a third alternative: Nim.
Support for epoll/kqueue/IOCP has been in Nim's standard library for a while now and is already very mature. The learning curve is probably somewhere between Rust and Go. In addition Nim also offers a GC that is predictable and controllable.
I wonder if the ease of development already outweighs the efforts required to keep up with the language growth pains and writing wrappers for system libraries where needed.
The current maturity and future stability. Tokio's own page says, as of a week ago says:
"Today we are publishing the preliminary version of the Tokio stack, 0.1!"
"Corrode" needs to get a lot better before it is useful. Look at the Rust it generates.[1] It transliterates C into unsafe Rust. That's not too helpful. Doing such a translation well is a hard problem. The translator will need to figure out exactly what needs to be mutable where, which means building a graph of the program across function boundaries.
[1] https://www.reddit.com/r/rust/comments/4rv0uh/early_stage_c_...
From the author's perspective it is helpful. If the goal is to make an existing C project memory safe without sacrificing performance and memory efficiency, one way to do that is to rewrite it in (safe) Rust. An automated direct translation from C to (unsafe) Rust would result in a body of code that would not (completely) satisfy the borrow checker. But some significant portion of the code would, thus reducing the total work necessary to translate the project to safe Rust.
The thing is that you can satisfy the borrow checker by (manually) modifying the Rust code resulting from the automated translation, or, alternatively, you could modify the C code in such a way that the automated translation results in Rust code that satisfies the borrow checker. If you can manage to write C code that automatically translates to safe Rust, then the safety guarantees of the borrow checker also apply to the C code.
So the automatic translator can be used to apply Rust's borrow checker (and its safety guarantees) to C code. This would be one way to, for example, bring a degree of memory safety to embedded platforms that are not supported by Rust, but which do support C. Pretty sneaky, no? (Of course, some of Rust's memory safety is achieved through run-time checks rather than the borrow checker, so it doesn't completely solve the problem for C.)
But satisfying the borrow checker is still a lot of (mental) work, and as I've pointed out, there is an easier alternative. It would be much easier to write an automatic translator from C to SaferCPlusPlus[1]. And even for embedded platforms that don't support modern C++ (or at least its standard library), you can pull the same trick, as SaferCPlusPlus also uses a degree of static enforcement of memory safety (although not to quite the same degree as Rust's borrow checker.)
[1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus
The first step would be to make everything const that can possibly be const. Const stuff can be borrowed non-mutably. Then make all variables have as narrow a scope as possible, even if this means putting in more bracketed blocks. Variables which are not initialized at declaration should be combined with their first assignment whenever possible.
Then you have to analyze what can have single ownership and what can't. Non-single-ownership data has to be refcounted. That makes the borrow checker happy, but may result in excessive refcounting if the analyzer can't track usage through complex code.
Pointers need to be analyzed for usage. If there's no pointer arithmetic, it can become a Rust reference, maybe with a "Some" if it can be nil. If there's pointer arithmetic, the pointer is going to have to be represented as a reference and a subscript.
You need a standard C library in Rust, with Rust safe equivalents of all the string functions.
It's a big job, but not impossible. It might be a marketable product.
I felt this way too but then realized the advanced topics of Go really take time to get right. Writing correct concurrent code is non-trivial as you need to tailor your solution to the problem at hand. There is no one size fits all way to write concurrent code. In some cases a mutex makes sense whereas channels work better in others.
Programmers must be diligent when using these tools as well because of deadlocks, data races, or go routine leaks. I think this is an area Rust excels in with its ownership model that eliminates these problems.
That's basically my experience with rust and go.
go is stupid, but I can write it. It's stupid needing to write the same for loop over and over again, but it's an obvious for loop that doesn't have any surprises, and everyones for loop looks the same.
rust is smart, but I can't write anything in it (yet). Some of rusts features would be nice to have in go.
Really? Tell me what the output of this short bit of golang code is before running it then if it's so obvious. The first one is only a for loop, nothing else, the second output line is a for loop and some channels + goroutines, but nothing too complicated.
https://play.golang.org/p/g4Pd5ebrWp
I've seen these issues in the wild more times than I care to admit. Go is a trashfire. They wouldn't compile in rust.
It's literally about nothing but how the 'value' variable in go for loops is handled by the language.
To make it worse, a common solution is to do this: https://play.golang.org/p/BTRs_TCQdu
That code looks like line 10 shouldn't be needed, does nothing, and during someone elses refactoring it might be deleted and result in the code blowing up again. No warnings, just silent data corruption.
The second one is a bit complicated, yes, but again I've seen them in the wild. Again they wouldn't have compiled in rust.
When I write performance critical code in Rust I can see how I'm rewarded for all the mental gymnastics and token salad of Rust.
But when I'm writing something that's difficult or complicated in the business/algorithm sense but not performance sensitive, then I just can't let the syntax obscure the semantics.
The code has to look as simple and readable as ruby/go/Swift/c#/Python/kotlin/Nim -- or the language has failed me.
Right now I feel it's often the opposite. When I write low level Rust code the type system is usually ok. For higher level code I usually find I need more noise and type overhead (more explicit lifetimes, more Box<Rc<T>>). That I think is a big problem.
Rust, like C++ is "you pay for what you use" - but what they mean is performance. I wish it was readability. I almost wish the default was a higher level language with lots of heap allocation etc, and you explicitly declare when you don't want that (c.f C# unsafe/stackalloc and similar)
I don't know if that's really possible. Aliasable mutation just doesn't play well with the kind of memory model that Rust has. If you introduce unrestricted aliasing and mutation like most other languages, then you're going to get a flood of confusing borrow checking errors.
I suppose what I'm trying to say is that I'd really like simple code to look simple, and that it's an explcit design goal that code look as simple as possible. Perhaps I'm spoiled by languages that hide memory complexity with a pervasive GC (I am) but I still think there has to be room for improvement (and to be honest there probably are tons of already created issues with possible lifetime elision or coercions that reduce the need for Boxes inside Rc's inside boxes...).
Keep up the good work.
Nobody would consider a flute to be an instrument superior to a violin because it can be learned faster. Rust is a tool that takes time to learn. Is it worth it? How could ESR decide if not in hindsight?
My personal experience is that understanding and applying Rusts borrowing and ownership made me a much better systems programmer in C and C++. Would I write a production NTP server in Rust or Go? Definitely Go, but that's no reason to dismiss the concepts and the remarkable engineering of Rust.
In any case, Rust would probably require some rearchitecturing anyway.
But then again, it just takes time. And I have some crazy two month uptimes with my rust services eating that constant 8 megabytes of ram...
Given that Rust is younger than Go, ignoring a year's worth of development makes for an especially unfair comparison.
The issues he cited were from 2014 and 2015, regarding Rust for networking code. Moreover, on his blog post (http://esr.ibiblio.org/?p=7294) he received a clear answer that he seems to have ignored:
Stefano:
[...]
For epoll: There is a crate. You could also use
future-rs or tokio. So you have three possibilities.
Finally, the author of another networking project, TRust-DNS, used these Rust features and was quite satisfied with the elegance of the resulting code:https://bluejekyll.github.io/blog/rust/2016/12/03/trust-dns-...
More possibilities isn't necessarily better. ESR makes precisely this point: "While implementations exist in the crate system, there is not yet any guarantee that any of the alternatives will be maintained over 10-year timescales."
Having three possibilities just makes it more likely that you pick the wrong one, the one that will be dropped by its maintainers because the rest of the community chooses another one.
But I have the feeling Go became more of a Python/Node.js alternative.
I appreciate the safety+performance value proposition in Rust. More cathedral, less bazaar.
fn apply<A, B, C, F, G>(mut f: F, a: A)
-> impl FnMut(&B) -> C // must still be `for<'r> impl FnMut(&'r B) -> C`, because that’s what filter requires
where F: FnMut(B) -> G, // must not be `for<'r> FnMut(&'r B) -> G`, because regular functions do not implement it
G: FnMut(A) -> C,
B: Copy, // for dereferencing
A: Clone {
move |b| f(*b)(a.clone()) // this must do any bridging necessary to satisfy the requirements
}
this function signature must be EXACTLY like what I wrote or it won't work> this function signature must be EXACTLY like what I wrote or it won't work
This can be seen as a feature in the sense that you can't program by luck: well, this incantation seems about right and the compiler nods its head that it understands and that means something, so it must be right.
template<class F, class A>
auto apply(F f, A a) {
return [f=std::move(f), a=std::move(a)](auto&& b) {
return f(std::forward<dectlype(b)>(b))(a);
}
}
The forward<decltype> is an abomination and is really in need of a language based solution, but otherwise is fairly straightforward.[1] No type checking of the definition of course, only of instantiations. On the plus side, the returned function is polymorphic and can be called for all Bs that f can be called.
https://bitbucket.org/iopq/fizzbuzz-in-rust/src/bf4968973d73...
it gives an error when I use a generic `second` method from tool.rs
EDIT: Reworded it to be more specific
He could also use Java. It has a 'pauseless' GC in Fedora Core's OpenJDK (Shenandoah). It has an epoll abstraction in the core library. It has libraries for doing things like async DNS requests already.
It would be nice sometimes if these A vs B comparisons were a bit wider.
It's a replacement for one of the many background UNIX services, not a "primary" service that can own a machine.
That doesn't really say anything about viability for an open-source project that's supposed to run on all kinds of embedded and general-purpose hardware.
> It is worth noting that Go came nearest disqualifying itself entirely here. If it were not possible to lock out Go’s GC in critical regions Rust would win by default.
I mean, technically anything the system or runtime does on your behalf can be thought of as a 'pause'. What if you lose your timeslice half way through a function?
> Shenandoah is an ultra-low pause time garbage collector that reduces GC pause times by performing more garbage collection work concurrently with the running Java program
Funny enough, the term "pauseless" was in fact invented precisely because of people like you, who abused the original terms ("concurrent" or "asynchronous" [0]) used for garbage collectors that never "stop the world", and used it for algorithms that merely run in parallel with the mutator threads, pausing them every so often. The next term used was "fully-concurrent" and now "pauseless". But if you keep abusing these terms to mean not fully pauseless/concurrent GCs, then it will become just as useless as all the terms before it.
This language seems unnecessarily personal and accusatory.
However, whether we like it or not, Azul has established the term "pauseless" as the way to describe their own collector which before Shenandoah was the only GC that can realistically be described that way, and which Shenandoah is very similar to. This is despite the fact that Zing still pauses. Specifically, the GC moves objects whilst the program runs.
I am unaware of any GC algorithms that are truly, completely pauseless in every situation. So I don't know what you want the term to be reserved for.
So, if you are operating in a environment where you don't care about thread switching, you might also not care about GC anymore.
You are correct however, its not pauseless, that just a marketing term.
http://stackoverflow.com/questions/3770457/what-is-memory-fr...
I think sometimes it makes sense not to shove Java where it is not applicable.
http://www.slideshare.net/RedHatDevelopers/shenandoah-gc-jav...
It's true you'd need a JVM on the platforms where ntpsec runs but that's also true of having a port of the Go runtime.
I mean he also says that rust has no good epoll/select abstraction, which is wrong. And also "a welter of half-solutions in third-party crates but describe no consensus about which to adopt" I think he didn't researched well enough.
I mean it would be the same as saying that there is no good way to create a custom non blocking dns server with pure java/scala (no external library used). Rust has https://tokio.rs/ and everbody who even looked into network services with rust, stumbled across it.
Well maybe for his goals and contributor base go is prefered and that is ok, but well this article is more or less written as a rant against rust, that he/she/it does not agree with the generel design/documentation/whatever of rust.
In fact I also think that the tooling of rust sucks. rust is a language which shines with extremly good tooling. I mean rust has a godlike package manager and every tooling gets better and better.
Compared to go where the package management just sucks but the tooling even IDE completion is extremly great.
P.S.: I would not want to have a garbage collected ntp server. But for a lot of things I thing Go would be a good fit, even when it would not be my tool of choice.
I can't reiterate this enough. Rust has one of the best abstractions I've ever used over epoll/kqueue and MS' variant, MIO. MIO has picked not the crappy POSIX select, which every major OS has a better alternative to now, but instead the OS' preferred event system. The 10 year stability requirement is awkward, as I don't think anyone can predict the future, and in 10 years, who knows what will change.
As you mention, tokio is an awesome futures based abstraction on top of that, making it a breeze to write complex, fast, event driven logic.
I'm sad that after four days he didn't like Rust, I had a 100% different experience. After one day I fell in love with nearly every aspect of the language, and it was specifically because of state machines (which they mention as one of their core desires). My biggest complaint against the language hasn't changed, which is dealing with different Error types, but even that after a lot more experience with Rust has become easier.
Anyway, for NTPSec it's sad that this didn't suit their desires, but that doesn't mean that we can't write our own.
Do you mean syntactic sugar? Because there's try! and ?
Or do you mean dealing with Option and Result in a more uniform way?
Mind you, this is my biggest complaint, and it's trivial for me now, but after you grok the other major features of the language, properly dealing with errors/results is a hurdle for people new to the language.
When comparing to other libraries in other languages, MIO probably looks like it's devoid of features, but that's because it's trying to be an abstraction layer only, and tokio is probably where most people should turn for higher level semantics...
And that for me that is the way I want to do concurrency and parallelism for pretty much everything I'll ever write.
1. You can get exactly this with concurrency by spawning one thread per request. The only difference between Go and the pthread model is that Go has a userland scheduler.
2. If I tried to do my parallelism work using this model, the amount of multicore speedup I would get would be zero (actually, it would be negative). Sometimes you're compiling multiple .o files--you get lucky and the overhead of spawning a thread per work item is not restrictive. Sometimes you're shading individual pixels--spawn a goroutine per pixel and you're going to be laughably slow.
"Announcing Tokio 0.1 ... The 0.1 release is a beta quality release. ... This release also represents a point of relative stability for the library, which has been undergoing frequent breaking changes up until now. While we do intend to eventually publish a 0.2 release with breaking changes ..."
I'm not trying to take a dump on the project (breaking changes are expected and welcome for new projects), but it is obvious a lot of the Rust ecosystem is in a very immature state. Probably much to immature to base an ntp server on.
ESR knows this. It was there in the comments of his previous issue. Yet he chooses to link to a two-year old issue with one comment that says that Rust doesn't have epoll as a source of truth.
Mio can't compare to the baked-in goroutine goodies (neither can epoll in C!), but this blog post is outright dishonest.
Again, not taking a dump on mio because its authors are doing the right thing. 0.x means bugs and api breaks are to be expected. Use the software at your own risk. Basing an ntp server on it might not be appropriate (atm).
That said, as pointed out in the previous discussion about this, C also doesn't have epoll in the core language (it also isn't in the standard library there, either), and Rust can call the C epoll functions directly on the platforms that have it.
didn't it launch a week ago?
I do think that the majority of the resistance though is that the author could not get productive with Rust in 4 days. For that reason, even though the epoll and documentation issues might clear up, I don't think the author would ever select Rust, not matter how much time has passed.
Which as I write, I realize that I think that Rust would be better, lack of easy on-boarding aside.
Go also offers a lot of high level constructs that allow you to create a web server and other solutions traditionally built in higher level platforms, but that doesn't reduce its low level functionality.
C# and Java have pauses in the hundreds of millisecond range (though there are "real-time" JVMs that greatly improve this). And it's notable that Go goes to lengths to avoid generating garbage.
Rust has escape analysis and reference counting. It really isn't so different.
If you are writing a library to render the latest web image format, or implement the latest secure network protocol, then your choices are limited and Go is not an option.
Sure, you could write it in Go and then Go programmers could use it.
But if you write it in C or rust, it could be the de facto library for nearly all languages.
The article is a good one, but doesn't really influence my personal opinion much.
This is how hard adding String objects is in Rust:
a + b
A more full example shows only small complexity, really, and I include it only for completeness and fairness: fn main() {
let a = String::from("Hello,");
let b = " world.";
let c = a + b; // this is the only part that concats, really.
println!("{}", c);
}
The String::from call converts from a str& — which is effectively a pointer and length to UTF-8 data, to a managed string, more akin to std::string in C++; str& doesn't implement +, I presume b/c it doesn't know what the resulting type should be (and doesn't presume).A C programmer should easily comprehend why you can't simply add two char * s together; compare:
char *new_string = malloc(strlen(a) + strlen(b) + 1);
if(!new_string) { abort(); }
stpcpy(stpcpy(new_string, a), b);
return new_string;
(that's just the `a + b` line from Rust, in C, essentially)(hopefully I got that right. stpcpy avoids an extra iteration through a that strcat cannot; I do know about strcat.)
Essentially, in all of Python/Go/Rust, if you has the right type, string concatenation is `a + b`.
> Contemplate this bug report: Is there some API like "select/poll/epoll_wait"? and get a load of this answer:
> > We do not currently have an epoll/select abstraction. The current answer is "spawn a task per socket".
It would need to be cross-platform; so I can understand why Rust isn't there yet in the standard library. There are third-party libraries out there that do this. (And C has nothing here, either…)
You can always call epoll directly, and write the required abstraction yourself. (There are even third-party wrappers for calling epoll, so you don't even have you write that yourself either; see the excellent "nix" library.) If you want a 10 year solution…
> Relatedly, the friction cost of important features like the borrow checker is pretty high.
At first, this is true. Then I felt like I started realizing that what all the "friction" of the borrow checker was it pointing out serious bugs in my code.
Regardless, NTP would be better off in either Rust or Go instead of C, IMO.
fn main() {
let a = "Hello,";
let b = " world.";
let c = a + b;
println!("{}", c);
}
And the result is: rustc 1.15.0-beta.3 (a035041ba 2017-01-07)
error[E0369]: binary operation `+` cannot be applied to type `&str`
|
5 | let c = a + b; // this is the only part that concats, really.
| ^
|
note: an implementation of `std::ops::Add` might be missing for `&str`
|
5 | let c = a + b; // this is the only part that concats, really.
| ^
timeout triggered!What?
PS. looks like hacker news can't handle rustc error format, a pity...
Your code fails to compile because it attempts to apply + to two string slices, and that is not implemented. @deathanatos also mentioned that.
You might find the Rust book page on Strings helpful: https://doc.rust-lang.org/book/strings.html
I remember learning Java was a piece of cake. Go was too. Both were remarkably similar to previous languages I knew. Rust was/is a lot more difficult, but nowhere close to the mindfuck that is Haskell or ML.
I mean, is it that bad that it takes a month to really learn a new language if it can provide worthwhile benefits?
It only takes around a week or so though, after that you can be surprisingly productive. I never would allow myself to write the code in C that I wrote in Rust. I'm just not clever enough.
C++ helps, if you are familiar with RAII usage in it.
Had the same feeling with go. Looking into big projects like syncthing helped a bit. But first i have to get a better hang of the language. Books like "Atomic in Scala" or "Clojure for the Brave" are taking your hand and guiding you through the Language. Even when taking a peak into books like "21st century C" i learned more, then when i simply force myself through go's "Gopl" or Rust's Book. I know i am probably not the right target group. But i really want to learn one of those languages in my free time, and i had a really hard time to do so.
After understanding go better, i still want to switch to rust. The build system with cargo pleases me and looks somehow cleaner as in go. I just create a project with 'cargo new XXX --bin' and start coding and building some kind of lib in my project. No problem. I go there are 100 different ways to start a project, and most time you will only find people complaining about vendoring etc.
I have quite a few openwrt routers running with substantially less resources available to it than the worst android phones.
I don't know if go would be able to meet the cpu/memory constraints in that environment... from the blog post it seems like that wasn't even measured?
I think it's largely because C and C++ has been used in such a wide variety of applications as "good enough" languages but where there were so much room for improvement, for modernization. We're talking about an old assembly language layer and an object orientation cludge on top of that layer. As soon as you do improve on these, you observe that the application space to cover for successors is huge, so huge that there is plenty of room for two different languages.
Developing in Go doesn't feel like Java or C# to me. It feels more like C (and definitely not C++) and I love that. It's so simple, yet producing native code. It's like what you'd get if you took C and from the very start decided the productivity vs performance problem favored a garbage collector, prefering productivity. Then looked at how common and underutilized multicore CPU's are, while at the same time how synchronization is hard to get right. If you then move from these problems to solve and realize the GC is your Achille's heel and simply try to optimize the heck out of that, I guess you get something like Go.
Meanwhile, Rust during the design phase must have been in such a similar place as Google engineers were when designing Go? Once again, C / C++ were flawed and unsafe, cumbersome to work with. They took the very same productivity vs performance problem and this time saw that, no, we don't want garbage collectors, we prefer performance supporting time critical systems above all in the spirit of C, yet safety. Then looked at common crash issues and went by that, and then they got Rust.
Personally I prefer Go. It's the most fun for me to work with and feels like a very pragmatic language. Rust feels more like an academic language to me: ideas and exciting concepts allowed to materialize. It also has its place, but seems like more in niched scenarios like real time systems and device drivers, low level, critical stuff like that.
the Rust team often pretends they are open to suggestions as to how to make Rust easy or easier to learn, that's impossible given how memory management is done in Rust, especially in regard of the people i talked about in the former paragraph.
Only a developer familiar with C or C++ can appreciate Rust semantics. The others cannot.
In particular, it's my understanding that epoll and select are system calls. In that case, just call them. Or is there really no means to do so from Rust (doubtful)? Sure, you'd have to wrap stuff in "unsafe" calls, but that's par for the course when interfacing with non-Rust software.
I don't think 4 days is enough to really evaluate a language. I'm not going to dismiss Rust based on this analysis.
(Not implying Go devs are racist, I hope that's just ESR.)
It's the 4th law of HN: Wherever Rust is, Go goes, and vice versa.
I am considering just accepting this reality that people will always pit these two against each other, and maybe just accept it for it's positive merits: that the extra competitiveness will help create a better ecosystem for the two of them.
Well, unless you want people to actually use your shiny new language. If that's the case, perhaps criticisms of this type should not be dismissed out of hand. :-)
Most programmers are going to abandon something if they study it for a week without significant results. Maybe they'll keep plugging at it if their boss orders them, but they won't do it on their own. Oh, sure, there's a small subset of programmers who enjoy tinkering with weird languages for fun, but that subset is dwarfed by the number of programmers who view languages as a tool for getting things done.
If there's anything that we should learn from the history of programming languages, it's that usability trumps theory every time. The languages that people actually use are almost never the ones that theoreticians admire.
Note that most code today is written in C, JavaScript, PHP, Java (none of which would win any prizes for theoretical elegance)... rather than ALGOL, ML, Haskell, the various Wirth languages...
There's really no comparison. Lisp probably comes closest, in that it is both theoretically elegant and has been used, by the programmer's choice, to build large real-world systems, but even Lisp is basically a rounding error.
The sort of people who find major problems in Go simply won't put time and energy into the language beyond a point—why should they? There's a limit to how far I'm going to explore a tool that seems obviously inferior, even if the tool is popular. (And popularity is an absolutely terrible measure of quality!)
If you applied this standard to PHP, you'd get an implausibly rosy view of the language, because the people who aren't invested in it simply don't use it.
Hm.. Title is "Rust vs. Go" - looks like title of another one holywar flame article.
Which would ultimately be fun to follow
I've tried Rust and concluded that it solves problems I don't have. I work mostly in C++ (more like C+, I tend to keep my code pretty simple), and with unique_ptr<>s, shared_ptr<>s and judicious use of concurrency primitives I can avoid pitfalls well enough that I maybe encounter a self inflicted concurrency or memory management issue once every six months, if that. And it pays amazingly well, and there's an enormous number of libraries available. That said, when I need a high performance web server, I'll use Go without hesitation. When performance doesn't matter, Python and Flask are pretty indispensable.
Most C++ developers I talk to about Rust express the same sentiment, they usually like the idea, but aren't personally interested in learning it because it solves problems they're rarely confronted with.
I tried picking up Rust a few times since it does interest me, and I like trying and learning new things, but I currently don't have the time to really dive into it. Go on the other hand took no time at all to get into, and was promoted pretty quickly into one of the more frequently used tools in my toolbox, just like Python.
I've been writing Javascript for years and if there's one thing I've learned it's that type safety matters on the large scale. Don't get me wrong: I actually love Javascript. It's my go-to tool when I want to just get things done. But when you start scaling things out and get a lot of moving parts going, type safety really helps lift the mental burden of tracking everything yourself. That's why TypeScript is so popular.
I've been a huge fan of dynamically/weakly typed languages for a while but I've fallen in love with Rust. Yes, it can be a bit painful at the start but it doesn't take hours to get basic IO working and it's quite beautiful once you get into it. The mind-bending part is the ownership model because nothing else has ever had something like that. But, you know, that's just my opinion.
#include <stdio.h>
int main(void) {
printf("hello world\n");
return 0;
}
Rust: fn main() {
println!("hello world");
}What it fails at is making the simple things simple. Making a program that concatenates some strings shouldn't be hard, and the result should be clean and readable. That obviously hasn't been a design goal yet, but I hope the focus will turn to making tresholds lower and syntax less painful soon.
in go, you can download it and have the pieces to actually do useful stuff right away. legit productivity. not to mention putting together graphs or graph-like structures and other similar things aren't the obtuse sphinx riddles they are in rust.
End of the comparison. That's all one needs to know if he's interesting in a career in distributed systems.
[1]: https://this-week-in-rust.org/blog/2017/01/17/this-week-in-r...