352 points · by mperham · 12y ago · 302 comments
Go isn't bad for writing routine server-side web stuff that has to scale and run fast, which is why Google created it. Go is a modern language with a dated feel. No user-defined objects, just structs. No generics or templates. It was designed by old C programmers, and it looks it. Go has generic objects - maps and channels - and syntax for creating object instances - "Make". Only the built-in generics are available, though; you can't write new ones.
Go's "reflection" package thus tends to be overused to work around the lack of generic. This means doing work for each data item at run time for things that could have been done once at compile time. "interface{}" (Go's answer to type Any from Visual Basic) tends to be over-used.
Go (especially "Effective Go") has a lot of hand-waving about parallelism. Go's mantra is "share by communicating, not by sharing", but all the examples have data shared between threads. The channels are just used as a locking mechanism. Race conditions are possible in Go, and there's an exploit which uses this. (That's why Google AppEngine limits Go programs to single threads.) Go doesn't use immutability much, which is a lack in a shared-data parallel language with garbage collection. If you can make data immutable, you can safely share it, which is a way to avoid copying without introducing race conditions.
Rust, like Erlang, takes a much harder line on enforcing separation and locking. I haven't used Rust myself yet, so I can't say more on what it's like to use it. My hope is that Rust will provide a solution to buffer overflows in production code. After 35 years of C and its discontents, it's time to move on. I really hope the Rust crowd doesn't fuck up.
Over & over I see language aficionados ding Golang for not taking advantage of immutability and for allowing shared data --- or, in your case, going a step further and reducing all communication among processes in Golang to instances of synchronized sharing.
What I'd like to know is: why don't all those hundreds of thousands of lines of concurrent Golang code out there, including all the library code I can just "go get" and whose authors have been encouraged by Rob Pike to use, basically, threads with near total abandon (watch his video about designing a lexer!) --- why don't all those libraries and programs randomly deadlock and corrupt themselves all the time?
Because my experience is that Golang code is quite a bit more reliable than, for instance, Python code.
What am I missing? The "share by communicating" model in Golang seems to work pretty darn well, especially given the extent to which Golang begs programmers to make programs concurrent.
† OK probably you more than me but still.
The simplest answer would be "they do." In aphyr's recent presentation on Jepsen, where he tested etcd (a Go database implemented on top of Raft), he noted that when he started using it he encountered a ton of easily reproducible races and deadlocks (which he sarcastically noted was surprising because he thought goroutines were supposed to make concurrency issues a thing of the past).
I am not saying that Go channels don't help the situation at all--and the inclusion of a race detector doesn't hurt either--but you still have plenty of ways to shoot yourself in the foot. The thing that probably helps most is that GOMAXPROCS is 1 by default, since data races are a multicore phenomenon in Go.
Maybe I'm wrong and etcd was riddled with concurrency problems between the goroutines of a single etcd process?
In any case: as anyone who has worked on a large-scale threaded C++ codebase can tell you: Golang programs simply do not exhibit the concurrency failures that conventional threaded programming environments do. It would be one thing if Golang code only used concurrency for, say, network calls. But goroutine calls are littered throughout the standard library, and throughout everyone's library code.
I'm hoping that as Swift evolves over time, it will slowly become that sort of language. Right now it's pretty hard to write any real-world code in Swift that doesn't work with the Cocoa frameworks, and the Cocoa frameworks are typed in an objective-c-compatible way (even if new frameworks are written in Swift they'll need to maintain obj-c compatibility), which means you don't get the strong typing that's necessary for this property. Pure Swift code has the potential to behave like this, although you probably need to avoid the ImplicitlyUnwrappedOptional feature (the ! suffix on types), which of course primarily exists for ease of obj-c integration anyway.
I'm bringing up Swift because, with Apple's backing, it's very quickly becoming a "mainstream" language. I put that in quotes because it is only usable with iOS and OS X programming (for now at least), but iOS is large enough that obj-c should be considered a mainstream language despite the fact that almost nobody outside of iOS/OS X uses it, and therefore as Swift supplants obj-c it becomes appropriate to call it mainstream.
Regarding parallelism, I've been in love with Rust for a long time now, and one of the biggest reasons is because Rust makes parallelism safe. As an iOS/OS X programmer by trade, I think thread safety is far and away the biggest elephant in the room. Despite the fact that we've known that multithreading is the future for years, and despite the wonderful Grand Central Dispatch library on iOS/OS X, most programmers still think in a single-threaded mindset and don't even consider how their code should operate if invoked on a separate thread. This was one of my bugaboos with Go back when I was using that language (which was from the day it was announced right up until I discovered Rust, though admittedly my usage was in hobby projects and nothing serious).
I applaud the fact that Go has a data race detector now, which I used to finally uncover a lurking data race that plagued one of my programs for months (and which was ultimately caused by the Go library using two goroutines where I expected one, and therefore data which I expected to be on a single goroutine was actually mutated from two goroutines simultaneously). But I think Rust is absolute proof that a modern language can be designed such that data races are prohibited at compile-time without sacrificing any language flexibility.
I don't think it is at all obvious that Haskell won't become mainstream. It's already exerted a tremendous influence over many other mainstream languages and there's only so long that can happen before people just start going directly to the source of the innovations (or one of its direct descendants).
To wit, Lisp never became mainstream despite exerting a huge influence. Likewise Smalltalk.
If it is obvious then you should be able to explain why in a few sentences.
One sentence. Is that sufficient?
The basic rule is if you see a segfault or a data race, search your code for any `unsafe {}` blocks, and the cause will always be found inside one of those. And as a corollary, never use `unsafe {}` if you can possibly avoid it.
Just to add a clarification on the implied comparison: Rust only protects against data races at compile time. Other forms of race conditions are still possible.
The way structs are supported, it feels much more like objects than C structs. I prefer it much more than say, OOP classes. It's something you need to immerse yourself in to appreciate, IMO.
What about "user created objects" would you miss?
Go felt that way to me — it was good at everything, but nothing grabbed me and made me feel excited in a way I wasn’t already about something else in my ecosystem.
He's apparently using each language to write relatively small command-line utilities. If Go is "amazing" at anything, its usually cited as a language of choice for (1) networked systems, and (2) large yet maintainable systems. I'm not sure his initial foray into the language would have provided enough experience to accurately assess those merits one way or the other.
Rob Pike once expressed surprise that people migrating to Go weren't C++ programmers, but Ruby/Python/etc. programmers who needed more performance. That leads you to wonder: (EDIT: removed pejoratives) if a programmer desired to switch from C/C++ to another language but hasn't by now, why not?
1. They require the performance benefits of C/C++ (and as humanrebar pointed out, manual memory management).
2. They're tied to legacy code, with too little incentive to switch.
3. They have an organizational mandate.
Any programmer who wasn't subject to the above constraints and wanted to switch could have done so before Go showed up on the scene. And if a programmer uses C or C++ solely because the above constraints, Go isn't likely to change that.
Rust may have a better chance of converting C++ programmers, if it offers the performance and control demanded by programmers who are using C++ by necessity. It will be interesting to see if people migrating from Python/Ruby to a higher performance language will choose Go or Rust in the future. Kind of like the OP, I like Go but I'm excited about Rust.
I (and many others) "still" use C++ (which is a very different language from C) in 2014 because it's an extremely powerful language that's still evolving and has produced many innovations that haven't been replicated by many other languages, such as destructors/RAII, strong compile-time type checking, generic programming, and ownership/move semantics. To me, Go looks like an update of C that has ignored all the good innovations of C++. It has no destructors, uses GC instead of ownership/move semantics, and requires runtime type checking instead of providing generics. I see it as a big step backward from C++, so unlike Rob Pike I'm not surprised it hasn't attracted C++ programmers.
Rust, on the other hand, has taken many of the good parts from C++ and developed them even further, without the baggage of C++. Thus, while I haven't coded any Rust yet, it looks like a step forward from C++ and has me quite excited.
>> [C++ is] still evolving and has produced many innovations
You're absolutely right, those features extend beyond performance/control.
>> Go looks like an update of C that has ignored all the good innovations of C++.
Yes, Go feels much more like an updated C to me too. And it makes it all the more surprising they expected C++ programmers to jump on board. I double-checked the quote, and actually C wasn't mentioned at all.
However, it's not the best at anything. If you need super performance and the ability to control the machine directly, you still need C++. If you want super productivity and the ability to quickly try out ideas and see if they work, you still need Python or Ruby. If you want to write for web browsers, you still need Javascript. If you want to write for iPhones, you still need Objective C. If you want to write for Android, you still need Java. If you want to be absolutely certain your program will work as intended when it compiles, you still need Haskell.
I guess Go is the best mainstream language available in one area, networking concurrency. And that's where we see its successes so far - Cloudflare and Doozer (Heroku's Paxos implementation) and dl.google.com.
But virtually all the money in the tech industry is made on the margins - by being the best in the world at one specific task. If you want to build the fastest, most memory-efficient database possible - you still need C++. If you want to crawl, parse, and index the most pages on the web - you still need C++. If you want to have the highest-quality graphics at the best frame rate possible - you still need C++.
I could see Go getting pretty widespread adoption within the enterprise (as in, software departments of companies whose primary product is not software), much like Java has. There, you don't need to be the best in the world at something, you only need to make the best use of the computing resources you can with the staff you have available, and a language that gives you a good trade-off works out well. But these people moved away from C++ a decade ago; the enterprise is all Java land now. The people who still are on C++ generally work for product companies where performance is critical; because of the economics of the software industry, it pays for these companies to hire a few more expensive developers and ensure that their product remains better than the competition than to switch to a more productive language and take the risk that their technology stack won't let them achieve the goals that make them competitive.
The only other language I currently do any meaningful amount of coding in is F# and for me that replaces any need for a scripting language like Python or Ruby. I've used and liked Python but I really missed static typing.
who is still using C/C++ in 2014, and why?
Systems programmers. Embedded programmers. Kernel developers. Compiler developers. Language runtime developers. Safety critical software developers. I guess you can group them under "performance benefits" but it's as much about the ability to drop down, write arbitrary bits to arbitrary addresses, and (re)implement low-level constructs as it is about performance.The most obvious example of the need for a powerful language is manual memory management. For C and C++ developers, manual memory management isn't a drawback of their language but a feature.
If you want that sort of freedom to rebuild from the ground up, the only mainstream choices are C and C++. We'll see if Rust gets it right too.
All that being said, I think there's more room in the systems programming space. Both C and C++ tend to pick fast (or reverse-compatible) over correct when deciding which way to go on a feature. There are many, many applications that could really benefit from a "safety first" attitude towards systems programming. Browsers are the driving example but encryption libraries, medical systems, safety-critical software, and many other domains would benefit from a new perspective on things.
elliptic.nim: https://github.com/def-/bigints/blob/master/examples/ellipti...
elliptic.py: https://github.com/wobine/blackboard101/blob/master/Elliptic...
Others have reported success converting Python codebases directly to Nim. To put it in perspective [1]:
> The problem asked students to do a hundred runs and to try sample sizes of 10 and 100. For kicks, I did 1000 runs with a sample size of 1000. This took nearly 4 minutes in Python (macbook pro retina with i7 or i5? I forget...) and under 5 secs in Nim.
[1]: http://forum.nimrod-lang.org/t/589
Rust and Go vs Nim: http://goran.krampe.se/2014/10/20/i-missed-nim/
For reference, doc.rust-lang.org is the only place to look for documentation for the standard libraries; any other hosting of those docs is likely to be out-of-date.
1. I will fix it later today/tomorrow, busy right now
2. I did actually search quite a bit, but that was what I as an outsider found. Consider this an "issue" to fix :)
I think the issue was that the words I was searching for are not the words used to describe these mechanisms.
Anyway, if you can give me a proper link to the canonical place where error/exception handling in Rust is documented - I will link it. Going to http://doc.rust-lang.org/0.12.0/reference.html I still can't seem to find it.
Plus some of us actually really like C++ and/or C :)
From his rookie mistake of using path package instead of path/filepath to join system file paths [1], to non idiomatic naming with underscores, and what he describes in general.
It's interesting from the perspective of what a fresh perspective on both languages is, but the comments have less value once you've spent significant time with either language and used them to build large projects.
[1] https://gist.github.com/adamhjk/5a475b8dd45971a4e814#comment...
Go is in this weird place where they insist that you have to be 100% Go or not at all, at least with the official Go package (gccgo is different, but this divergence in the ecosystem doesn't exactly inspire confidence). This is convenient when you have small isolated processes, but completely prevents Go adoption in other environments.
I'm working in an electronic design automation software system which is basically a large number of C/C++ shared libraries/plugins loaded into a Tcl interpreter which you do not want to rewrite (lots of tricky and finely tuned optimization and design analysis algorithm).
Go is not a good fit in this environment because of its all-or-nothing attitude. Rust, on the other hand, is fairly easy to imagine as an addition to the toolset from a purely technological point of view (ignoring the social and management issues which add a huge amount of inertia). There is an unfortunate impedance mismatch between idiomatic C++ and idiomatic Rust, but communication is possible via a thin C interface.
https://dennisforbes.ca/index.php/2013/07/23/the-most-powerf...
I have never seen anyone suggest Go for large systems or seen any open source code that even comes close to enterprise system size. I would argue that Go is inadequate for large systems compared to the JVM languages. The absence of operational tooling, exceptions, declarative annotations, runtime management etc all make it much harder to support and scale to large numbers of developers.
Go seems perfect for micro services, command line utilities and single purpose applications. Which is where it seems to have gained a lot of traction in companies to date.
>>
>I have never seen anyone suggest Go for large systems or seen any open source code that even comes close to enterprise system size.
I might be moving the goal posts a bit here, but I think go's C heritage, and focus on message passing -- possibly coupled with something like protobuf or similar -- encourages breaking large systems into small services. So if you view a system as a "sum of functionality" -- I think one might still use go for "large, yet maintainable systems".
Now, it is of course possible to write micro services both in C++ and java -- but historically it appears at least in the java world, you end up throwing everything into a massive jboss container, exposing yourself to thousands upon thousands of lines of code.
With go, you deploy (relatively) small binaries, and a service can live as 20 binaries on one box, or as 20 binaries (along with some load balancers like haproxy or what not) across 300 machines. Or something in between.
I'd argue that some of the more sane java frameworks and projects also revolve around simplicity and separation of concerns -- typically leading to micro services. But a lot of people seem to end up working with large, poorly architectured beasts. That's probably more of a culture thing, than a language thing -- so I think people will make huge swats of unmaintainable go code as well...
That's as much of a curse as it is a blessing. To some extent, small services are handy for dev/ops type folks, as they can quickly see which specific part of an application is misbehaving with memory or cpu or diskspace, so they like it.
But small services means that you lock down the interface between parts of the system by using another language to specify the communications protocol (e.g. protobuf, json, ...) and 2 different codebases have to understand it. And even if you manage to get the code to change, now you have the problem of migrating the running program.
In other words, the interface is now set in stone. Nobody will ever touch it again. This is exactly what you do not want to happen. Small services are the enemy of large, flexible programs.
Contrast this to Java/C# (and, somewhat less perfectly, C++) and their refactoring tools. What a difference. Changing an interface is something that is mainly done by computer code, not by a programmer, and all parts are modified and all problems identified.
There are points where this is not a problem, like a file system interface, or a socket interface, that sort of thing (and even there you may change your mind ...). Places where flexibility is not needed or wanted (I would argue, looking at linux file systems, that the POSIX API is not, in fact, a good API for quite a few file systems, but looking at the kernel I can see why this is not going to change. Of course, half the distributed file systems are user space libraries, partly for this reason). This is exactly the sort of thing C programmers deal with.
Speaking of Maven - `go build` normalizes build systems so there is less time twiddling builds. It's not a silver bullet, but it's specifically intended for large systems.
Go's strong decisions around formatting (`go fmt`) are another example of planning for enterprise-size. There is no need for a style guide for go programs - it's built into the language, and with an approach that feels less pedantic than Python.
Go isn't perfect, but it's certainly designed for large-scale systems.
I agree with you that the JVM languages have better large-scale system support currently (20 years does give you something) -- but Go's goal is not dissimilar to the one Java eventually settled on after the applet craze.
Contrary to what you've seen, Go seems (to me) to be a go-to language for new companies principally concerned with distributed systems / cloud infrastructure (particularly those that once might have hired a hybrid of C and scripting language devs). One of the trends in those communities is toward microservices / SOA / etc, but the total codebases managed are certainly enterprise-scale.
All that said I have absolutely no significant opinions on Go vs Rust :) Just had to take issue with the "go is not enterprise scale" idea.
How is that different from the 40 years old Unix utility indent? Pretty much every single non-trivial programming language has its own code formatter. Auto code formatting is neither novel nor unique to Go.
Saying it's not for large systems is just showing ignorance of what it's already being used for.
Another reason to use C for your project is the ubiquity of C compilers and C bindings to other languages. Software like Lua and SQLite wouldn't be as widely-used if they were written in another language.
Just an example. In the previous months I had to re-write a medium-sized project (~5000 lines of C++), and I chose to use Free Pascal instead of C++. The old C++ code took ~1 min to compile, while Free Pascal only requires ~1 sec! It is so fast that my makefile uses the "rebuild all" switch every times it calls "fpc". In this way, at each recompilation all the hints/warnings are printed again and again, and there is no risk that I miss any of them.
Another thing that C++14 lacks is a decent set of features in the standard library. How can it be possible that the STL includes esoteric features (see "partition", "is_permutation"...), but not a printf-like formatting facility à la "boost::format"? I cannot stand the usage of ios::setw et similia!
Here is a gem: https://groups.google.com/forum/#!topic/golang-nuts/RKymTuSC...
There's a chance you'll laugh at the people dismissing higher order functions as nonsense, in which case Go might not be for you. This is a good test of whether you want to try it out or not.
* Golang doesn't have generics. This comes up so often on the mailing list that it's in the FAQ:
http://golang.org/doc/faq#generics
* Golang has a similar attitude to idiomatic functional programming tools as Python; it doesn't have map() and it's not easy to write a general-purpose map.
(I'll take Golang's lack of generics and map over Python's busted closures, and so call it a draw).
If you want to write programs in functional style, you don't want to use Golang. Pretty simple.
>>> map(lambda x: x*5, range(5))
[0, 5, 10, 15, 20]As long as your language has "everything is a pointer semantics" you should be able to write your own map and filter in a 2 or 3 lines of code.
map(F, [H|T]) -> [F(H)|map(F, T)];
map(F, []) -> [].I especially enjoyed the demonstration of map would look in Go code, complete with a useless anonymous function:
> bar = map(foo, func(e T) { return f(e) })
And this guy who doesn't seem to understand the concept of function pointers:
> You seem to equate the function f with a single character, which it's not. The user must write it's implementation, which you have omitted for your own benefit.
> The power of the map/filter abstraction starts becoming more apparent when you do things like
> Filter(someFunc, Map(funcWith3args, vecA, vecB, vecC))
> And you realize you should swap map and filter for your particular app for better performance.
met with this reply:
> vs > [10 lines of code for two for loops doing the same thing] > Using range makes it obvious that there is a performance hit in the first place.
The other choices are certainly there.
Although I'm not sure if there is an F# code formatter tool. Which is made up for by F# being a vastly more capable language.
Tabs vs. Spaces is decided at the language level (it's spaces or it doesn't work) but other things are often a matter of taste. It doesn't tend to matter too much though because (well written) F# code is expressive almost regardless of minor formatting issues (poorly written code in any language is a comprehensibility mess, regardless of "neatness" or newline consistency!)
Also, at this point the language syntax itself is basically locked. And from everything I've seen, they are focusing more on the runtime and tooling before they make any serious changes to the code language.
Could you show me a code snippet of maps and filters used that you believe is more readable than for loops? Maybe I'll get a laugh out of that. :)
This rounds back into Go's generics debate. If they give in with implementing map/reduce, they might as well start implementing some form on generics.
I think Go is for people who are in-line with the golang crew's views on language design. For the rest, use any other strongly typed language that has sort form of type-abstraction/generics (which pretty much they all do).
So it does just come back around to generics but people are solving this with code generation, like gen which looks very interesting, and I imagine that is quite acceptable for the time being, for those who really want it.
To a language user the benefits might be clear but the problems not.
To a language implementor the problems will be much clearer.
fn main() {
let args = os::args();
let washed_args = args.iter().map(|arg| arg.as_slice()).collect::<Vec<_>>();
match washed_args.as_slice() {
[_, "review", opts..] => review(opts),
_ => usage()
}
}
although I might actually suggest the alternative approach: fn main() {
let mut args = os::args().into_iter();
args.next(); // skip program name
match args.next().map(|s| s.as_slice()) {
Some("review") => review(args.collect::<Vec<_>>()),
_ => usage()
}
}
(this approach requires `review()` to take a `Vec<String>` instead of a `&[&str]`, but that's not a difficult change, and we could fix it using a second line of code if we wanted but at the cost of introducing a new allocation, like the original code does)For review() I'd suggest changing the original code:
let cwd = os::getcwd();
let have_dot_git = have_dot_git(cwd.clone());
let dot_git_dir: &Path = match have_dot_git.as_ref() {
Some(path) => path,
None => { panic!("{} does not appear to have a controlling .git directory; you are not in a git repository!", cwd.display()) },
};
to the following: let cwd = os::getcwd();
let dot_git_dir = have_dot_git(&cwd).expect(format!("{} does not appear to have a controlling .git directory; you are not in a git repository!", cwd.display()).as_slice());
This actually leaves `dot_git_dir` as a `Path` instead of a `&Path`, but I think that's better anyway. It also requires `have_dot_git()` to take a `&Path` instead of (what I assume it takes now,) a `Path`, which is an appropriate change as there's no need for cloning the path. let dot_git_dir = have_dot_git(&cwd).unwrap_or_else(|| panic!("{} does not appear to have a controlling .git directory; you are not in a git repository!", cwd.display()));Way back when, when I first was learning C, I didn't comprehend it very well. I was OK with it. A friend gave me some CDs with FreeBSD on it, one with the OS, and one with program sources. It was that source code which really opened my eyes, and you could digest small programs (like chmod) and see, you know, this is working, production code, and it's not hard, and you can do this.
That's a pretty bad reason for using a language and usually leads to some pretty ridiculous criticism.
This post was not that, I think they nailed a lot of the good and bad things about Go, in fact, they could have been a lot more harsh. There is a depth lacking in just checking out a language in this way though as there's no evaluation of some of the larger reasons Go exists, like concurrency and and fast compile times. Then again, most people probably don't even need/care about these.
Hell, very few of us would be using Javascript if it weren't for it's ubiquity/community/popularity. I sure as hell am not using it because it's a well designed language.
On Javascript you're missing the causality. Some people are learning Javascript because it is popular of course, because they've read on some forum that learning popular things gets them hired, but those people are totally uninteresting in the pool of developers that learned Javascript because they had shit to do and things to build and Javascript was the answer.
There's a big difference between learning X because you want to make your job easier, because you want to build things in a new way, because you want exposure to new ways of thinking, because there isn't an alternative to what you're trying to do, etc... and learning X because that's fashionable. In the former case, it's pretty much a gamble but you might actually get something out of it. In the later case all you're earning is the ability to slap another keyword on a resume that only mediocre HR people care about, being actually a time waist as it's keeping you from learning things that might actually be of interest for the things you're trying to accomplish (other than getting a shitty job of course).
Just as people that learned PHP or Java back in the day found out, learning for the sake of getting a job is a sure way to land you a shitty and boring job in which you are replaceable cog. Managers love popular languages and frameworks, of course they do. And the interesting jobs that are out there, that make people happy and that pay well - well, let me tell you, those companies aren't looking for keywords on your resume, but for things that you've actually built.
And after some years from now, when you'll be over 40, you'll find yourself either a manager that does LinkedIn searches for keywords, or an obsolete developer that can't find a job because everything you've learned is obsolete and you waisted your time in learning syntax, instead of learning new abstractions, algorithms and mathematics - you know, stuff that never gets old.
Because I had the good fortune of starting with Rust early, I now have several foundational libraries under my belt in the Rust ecosystem. This has certainly been of great interest in interviews, and might just lead to me landing a pretty 'hip' internship over the Australian summer. Of course it won't be in Rust, but it's better than being at a hum-drum corporate placement. Being a pioneer definitely sets you apart from other candidates, and also culls the pack of potential employers to those that value curiosity and initiative, and actually care about exploring new ideas.
Guess who's going to get a job:
A) The fool who just learned JavaScript and Angular.js
B) The university student who only knows Java
The answer will be (A) every single time because companies don't have the time to train people for months.
"It’s important to be clear about what we mean by stable. We don’t mean that Rust will stop evolving. We will release new versions of Rust on a regular, frequent basis, and we hope that people will upgrade just as regularly. But for that to happen, those upgrades need to be painless." [0]
There is a Docopt implementation in Rust[1], which is used by Cargo. It tracks master and is regularly updated.
Interestingly, I've found people either love or hate Docopt, so maybe you knew about it but don't like it. :P
/shameless plug
It is broken now, but with the collection reform landing, what isn't broken.
It's passing now that Travis updated to the new nightly.
(But yup, it was collection reform.)
I think Go does really well in tooling, but it doesn't feel as great in syntax or language features that I would really like. The two big ones I wish Go had were named parameters on functions, and immutable data structures.
It's probably a blub paradox thing, but my ideal language has immutable data structures and named function parameters. Kotlin, Scala, and Swift all kind of nailed these features, but Go has not.
For me, named parameters and a little verbosity goes a long way to allow me to communicate intent in my code. Immutability allows me to have a built in sense of safety that once the data is set, it stays that way.
In my experience, a whole class of problems goes away when you have those two features (alongside the many other features we'd expect form a language like Go).
What I felt from Go is that a year ago when I was playing with it, that they didn't care much about either of those two features, which is fine, but it keeps go from being my ideal language.
Swift I wish was a bit more general purpose, Kotlin and Scala don't compile as fast as Go, and Ruby doesn't have a compiler to do some of the checking I wish it would.
Go's fast compile times with something like Ruby's syntax and a feature set similar to Kotlin/Swift would be darn near perfect.
For me, there is no perfect language.
(I'm a Scala guy myself and I understand OCaml has no higher-kinded types and worse performance (in terms of throughput of the code), and its syntax is weird. But it's a general purpose programming language with an emphasis on immutability, at least some kind of keyword arguments, strong types and allegedly fast compilation (though probably not at the same level as go))
For example: I've recently attempted writing a small service in Go and it only took a few hours for me to figure out how weak a language could be without some sort of type-abstraction or generics: I had to implement a FindValueInArray() twice for two different types. This should be a big issue in any respectable language. (I mostly like Go otherwise though!)
for _, x := range foo {
if someCriteria(x) {
// do something
}
}golang goroutine let me built a standalone binary with embedded https server and websocket support. Would Rust be able to do that even at 1.0 release without relying on low-level C library wrappers ?
In any case, Rust 1.0 is not aiming to be feature complete in language or library, it is just the point of guaranteed backwards compatibility and additions and improvements will continue. See:
- http://blog.rust-lang.org/2014/09/15/Rust-1.0.html
- http://blog.rust-lang.org/2014/10/30/Stability.html
The Rust standard library is not aiming to have async IO at 1.0, but external libraries have exactly the same low-level power as the standard library, so this functionality can be written externally, e.g. mio[0], and the Cargo package manager makes it super-easy to use them in your own applications (with reproducible builds, so no risk of upstream changes accidentally breaking the build).
Lastly, are you saying "(low-level C library) wrappers" or "low-level (C library wrappers)". The former is exactly what Rust will have, it has highly efficient FFI (a Rust -> C function call is the same as C -> C function call) and so can bind to the high-performance libraries other have written without any overhead. However, there's no reason that people can't build a nice and high-level API above the direct bindings though (this is exactly what happens, e.g. the game-development community has quite a few nice-to-use libraries[1] that are thin layers above the low-level C functionality).
[0]: https://github.com/carllerche/mio
[1]: https://github.com/rust-lang/rust/wiki/Computer-Graphics-and...
That said, Rust does encourage message passing by default, but also gives you the ability to safely do shared-memory concurrency if you need.
> which rust decided not to do recently.
It's more subtle than this. Rust's I/O libraries are being re-done to remove the M:N stuff, yes, but Rust is low enough that I/O is just a library; anyone can implement alternate I/O stuff, it's not privileged other than coming with Rust. See mio as an example of an in-progress alternative.
OTOH, M:N and 1:N both require you to do more to handle actors in the runtime, which potentially adds overhead to everything, M:N may not always be a win compared to 1:1.
(We also used to say "Erlang-style" in our marketing, but eventually removed it)
Edit: Evidently I should have put a /s at the end of that first sentence. I know what the idea behind compile-time checking is, but I don't see that the given example actually illustrates it.
No, it means there's memory safety and a strong type system. Unless you specifically and explicitly break that, the language prevents you from doing things like accessing undefined memory or returning nulls where you haven't explicitly said you can return nulls, and the strong type system allows libraries to prevent you from accessing closed resources.
People say Haskell prevents lots of classes of errors at compile time, and yet even that has escape hatches. panic!() shouldn't be a part of idiomatic Rust code, it's primarily for use during initialisation, small scripts, and the odd place where an application design would be a pain to deal with if it had to deal with a one-in-a-million chance that something particularly odd happens, and the application can't continue if it does.
Go's type system is, by comparison, pretty minimalistic. In the example you mentioned, Go would rely on you learning to write idiomatic Go code to check the value of the returned error. If you skip that step, Go will happily crash and burn as you try to do something with the nil value returned alongside the error.
Of course any function can be forced to crash by inserting some crash-inducing code into the function. You can always make a function that assumes that value is of a certain form, and crashes the program if it is not (like unwrap for extracting a value from an Option, or crashing if it there is no value). In order to have "code that works if it compiles" (comparatively speaking; often used as an exaggeration), you have to have the discipline to use the facilities that the language provides you.
I guess a language would need some kind of totality checker in order to make sure that you couldn't make function diverge in some way. Like for example Idris has.
Rust also has the `!` type, aka bottom, for marking functions that diverge.
> So far as I know the fail! macro still exists in Rust.
What should that do? Crash the program? If so it should have been renamed to something like `panic!` now, since "fail" now is associated with Error types, while "panic" is associated with crashing the program/exceptions.
It crashes the current task (thread/process), not the whole program, and has in fact been renamed panic! recently: https://github.com/rust-lang/rust/pull/17894
Edit: Also, I missed a good overview of features in one language and lacking in the other. In that respect, I find the wikipedia page [1] deeply broken, but that aside.
[1] http://en.wikipedia.org/wiki/Comparison_of_programming_langu...
What's not stable is everything around the core ideas. Many things are in flight at the moment in anticipation of 1.0 stability. The core collection libraries had a major refactor land last night. How error handling works got changed earlier this week.
If you're interested in writing libraries for a new ecosystem, now is the time to get into the language. I've tried to get into Rust a couple times since the 0.4 timeframe and I couldn't keep up with the pace of change. My current attempt started at 0.11 and while there are steady chanes, I've found them to be manageable.
If you want to have idioms and ecosystem relatively settled, hold off until the 1.2 or 1.3 timeframe (6 week cycles). I say this because a lot of the current RFCs are split between things that need to happen before 1.0 and things that need to happen after. This generally means the base functionality in-place for 1.0 with the sugar/convenience stuff to come later. I expect it'll take a few cycles after 1.0 before Rust settles into what most people are thinking when they think stable.
Huh? I'm seeing comments in this thread about people using Rust right now in production. How... why... what?!?
We don't recommend it currently, but some people are just eager. :)
Nope. That will take many years. But it definitely is in a state where you can start building real things with it, if you don't mind some of the usual costs of being on the bleeding edge, like documentation that's hard to grok, frequent trips to irc, and frequent breaking changes. But breaking changes will be going away very soon, the documentation gets better all the time, and the irc room is far friendlier than others.
Trying to figure out new things tends to be an exercise in reading obsolete code examples and then asking for someone in #rust on irc.mozilla.org to translate. Stuff that gets deprecated isn't well documented in my experience and one of the best resources I came across (Rust by Example) also contains a lot of out of date or deprecated features.
Obviously, this is a side-effect of a rapidly evolving language that is still in pre-1.0 phase, but anyone going into it should be aware of the potential breakage that tends to happen at a fairly high clip at the moment.
That said, Rust does encourage message passing by default, but also gives you the ability to safely do shared-memory concurrency if you need.
I would like to know the thoughts of someone experienced with Rust.
You blindly assume the regex found a match, because you ignored the part of the docs where they tell you how to check for a match: http://golang.org/pkg/regexp/#Regexp.FindStringSubmatch