News for hackers. Stuff that matters.
Re:Why is Rust difficult? by josephg on Monday January 22, 2018 @03:49AM (#16202905)
> Go is another programming language I like, ... Fearless concurrency is a wonderful feature, but for embarrassingly parallel problems Go works wonderfully.

I adore Go's concurrency model but loathe go's actual language. The constant repetition in error handling, lack of generics and lack of parameterised types and Option<> make it feel like a children's toy set version of C instead of a useful modern language akin to Rust and Swift (and modern javascript).

I really really love the concurrency model though. And as far as I can tell there isn't much like it available elsewhere. You can make a similar concurrency model in rust, but you have to use much heavier OS level threads to do it, and all the other crates don't support it. Erlang / elixir do it but come with a much higher runtime performance penalty. Pony is interesting but very new - there aren't a lot of libraries for it and when I was playing with it the compiler seemed crazy slow.

I'm a little bit tempted to make a simple compile-to-go language. I'd get lynched at Go meetups for fragmenting the ecosystem, but it might be worth it. I like almost everything about go except the language itself.

Re:Why is Rust difficult? by matthewmacleod on Monday January 22, 2018 @06:33AM (#16203580)
I'm a little bit tempted to make a simple compile-to-go language. I'd get lynched at Go meetups for fragmenting the ecosystem, but it might be worth it. I like almost everything about go except the language itself.

I would love this; I feel entirely the same. The runtime is pretty good, performance is nice, concurrency is great, the tooling is wonderful (if you ignore the GOPATH nonsense and thew lacklustre package management solution). The language itself is quite frustrating to use, full of needless repetitive boilerplate and a mediocre type system.

I'd love a similar language with all the goodies that I find make development safer and more productive: proper enums, pattern matching, sum types, generics, and a handful of other features.

Re:Why is Rust difficult? by brightball on Monday January 22, 2018 @09:23AM (#16204501)
The Elixir performance penalty compared to Go isn’t as big as people think. It largely depends on what you are doing but the perk that your get is consistency of response time.

This is one of the better articles that shows both when comparing Python, Go and Elixir.

https://medium.com/unbabel-dev/a-tale-of-three-kings-e0be17a...

Re:Why is Rust difficult? by quodlibetor on Monday January 22, 2018 @09:08AM (#16204398)
The nice thing about Rust not having Async IO built into the language is that arbitrary third-party implementations are possible on a level playing field with the async framework being developed by the core team.

For example, there is the May[1] concurrency library. It provides alternative implementations of the standard library's IO interface, but does Go's automatic suspend/resume, so it still looks like blocking code, which is nice. From what I can tell it's still early days on a one-person project, but it is interesting, at least.

[1]: https://blog.zhpass.com/2017/12/23/may-announcement/

Re:Why is Rust difficult? by Rapzid on Monday January 22, 2018 @06:14PM (#16209063)
Let me offer a counter point. Every language I have used that has gone the route of "let the community make their own concurrency libraries" has turned out a mess; specifically Ruby and Python.

On the other hand, the concurrency OOTB languages have all had much better ecosystems and experiences; C#, nodejs(now and w/TypeScript), F#, Golang, etc.

Re:Why is Rust difficult? by barrkel on Tuesday January 23, 2018 @05:03PM (#16218210)
"Batteries included" is almost always better than "level playing field" because of network effects. The larger the set of common types / protocols available, the higher up the abstraction stack interfacing between two unrelated third party components can be. Minimalist environments have to pay taxes in the form of glue code and adapters for different ways of representing the same underlying concepts (though the costs are reduced in duck-typed languages). Even worse things happen when you try and use two third-party components and they share different versions of a common dependency - sometimes there's no easy way out.

Inferior approaches sometimes do get baked in to standard libraries. Having a culture of versioning, deprecating, migrating, is better IMO. But it's even better again to do a really good job first time around. Not easy, but I didn't say it was!

Re:Why is Rust difficult? by steveklabnik on Monday January 22, 2018 @09:58AM (#16204766)
It also has possibly irreconcilable soundness issues :/

libfringe is another extremely interesting player in this space.

Re:Why is Rust difficult? by stjepang on Monday January 22, 2018 @10:25AM (#16205005)
I'd like to read more about those soundness issues - do you have a link?
Re:Why is Rust difficult? by steveklabnik on Monday January 22, 2018 @10:42AM (#16205175)
Re:Why is Rust difficult? by rqs on Monday January 22, 2018 @08:34AM (#16204185)
> I'm a little bit tempted to make a simple compile-to-go language. I'd get lynched at Go meetups for fragmenting the ecosystem, but it might be worth it.

I don't know about "might be worth it" part, and I don't think Go is success is because of it's concurrency model. Instead, I think Go wins because it can get thing done quickly, in one stop.

The concurrency model has been designed to help achieve that, and the huge battery pack came with the language is also for help achieve that.

I'm not discouraging you from design your language, though. In fact, I could be very happy to see a new language which can give me all the benefits that Go gives me and at same time just ... simply be a better language.

My ideal language (in my opinion) is a combination of Go and Rust: Big standard battery (Help me get things done and encourage to it's ecosystem)(&BTW, it don't have to be in the standard library), and fearless programming (Help me avoid mistakes).

Sadly Rust don't want to have a big battery for some reason :(

Re:Why is Rust difficult? by roblabla on Monday January 22, 2018 @08:39AM (#16204211)
Rust does want to have a big battery. There have been works about promoting some crates as "the" tool to handle certain tasks. See the rust cookbook[0].

Rust is against pulling it in the standard library because that forces them to make additional stability guarantees. When you do that, you end up like python's `urllib`/`urllib2` situation.

[0] https://rust-lang-nursery.github.io/rust-cookbook/

Re:Why is Rust difficult? by phyrex on Monday January 22, 2018 @06:38AM (#16203621)
Have you looked at Clojure’s core.async? It’s a port of Go’s concurrency model to Clojure.
Re:Why is Rust difficult? by dawkins on Monday January 22, 2018 @10:58AM (#16205319)
> I'm a little bit tempted to make a simple compile-to-go language.

That's what I did for my current project. I love Go but for web apps is not the best in my opinion. I had some spare time and ended up building a VM that compiles typescript to bytecode. The performance loss is minimal, I still use the Go std library but it is a pleasure to use VS Code, generics (the VM ignores types but the TS compiler gives you static type safety, autocompletion, refactoring, etc...) Also exceptions is great for web apps where usually there is nothing else you can do but save all the info that you can and show an error to the user.

Re:Why is Rust difficult? by unethical_ban on Monday January 22, 2018 @10:04AM (#16204809)
I write somewhat simple programs and webapps for my job, from time to time. I use Python and its standard library, some modules, and the Bottle Framework. Pulling data from APIs, doing analysis, taking some user input, editing configs, etc.

I hardly ever use classes unless I'm extending a vendor library. I have never used generics. Why are generics such a critical component of a programming language that every thread about Go mentions it? It's an honest question from me.

Re:Why is Rust difficult? by rspeele on Monday January 22, 2018 @10:44AM (#16205191)
Python is a dynamically typed language so when you say you've never used generics, that makes sense -- the concept does not apply to dynamically typed languages. But I bet you frequently use lists and dictionaries, and perhaps occasionally use higher-order functions like map, filter, and reduce. All of those would be generics in a typical statically typed language, because with static typing you don't just have "a list" but "a list of ints" or "a list of strings".

Go has built-in generic arrays, slices, and dictionaries, but nothing else, and you can't define your own functions that work on those without specifying the type. So say you write a function that shuffles the elements of an array, like Python's random.shuffle(list). You can't make your function work for all kinds of arrays. You have to have a different function to shuffle arrays of strings, arrays of ints, arrays of FooBarClass, etc. even though the shuffling logic doesn't give a damn about what sort of thing is in the array.

I have a suspicion that this occasionally leads developers to write code inline that they previously would've extracted into a utility function. See the answers here:

https://stackoverflow.com/questions/12264789/shuffle-array-i...

Re:Why is Rust difficult? by unethical_ban on Monday January 22, 2018 @05:16PM (#16208510)
Thanks. I took a year of CS ten years ago and haven't had to do statically typed development of any size since then - certainly not developing libraries.

So essentially, containers and function overloading is damned near impossible. Got it.

Re:Why is Rust difficult? by ralfn on Tuesday January 23, 2018 @06:21AM (#16212670)
Python doesn't need generics because it doesn't try to statistically type your code in the first place.

    def example(a):
        return a
Would be perfectly legal python code. But in Go you would have to choose the type of A and duplicate the function under a different name if you want it to work with a different type.

So, when a language implements static typing without generics they actually mean 'lots of code and approaches legal in Python would be rejected'.

So it doesn't add a feature to the expressiveness of the code. It fixes a bug in the type system so that the expressive code is considered legal. Of course better type systems have existed since the 70's, but the set of people that know the ins and outs of how to implement those and the trade offs behind it does not include Rob Pike. His interests and skills are different (and the cause of some of the better features of Go)

Re:Why is Rust difficult? by gerad on Monday January 22, 2018 @10:46AM (#16205204)
When you don’t have type safety you don’t need generics. Example: in python you can call a function with any arguments (numbers, strings, whatever) and it can return anything (usually something of the same type). With go you can do this as well, but you lose compile time type safety, have to add a bunch of gross code, and incur a small performance penalty.
Re:Why is Rust difficult? by krylon on Monday January 22, 2018 @12:33PM (#16206168)
> Why are generics such a critical component of a programming language that every thread about Go mentions it?

Personally, I do not feel that strongly about generics; it would be nice to have them, but for my purposes, I can live without them.

But still: generic container types would be very nice. I don't need to use it very often, but Go's sort.Sort is very uncomfortable to use. If Go had proper generics, it would be easier to define a "generic" interface to iterate over things - currently, Go's builtin slice and map types are privileged over user defined types. There are probably more issues I cannot think of right now.

None of those are deal breakers for me. Go is highly compatible with the way my mind works, to such a degree I can easily forgive it all the things I do not like about it. But I also work in C# from time to time, and seeing how the .Net framework uses generics makes me wish Go had them, too.

Re:Why is Rust difficult? by steveklabnik on Monday January 22, 2018 @10:39AM (#16205147)
Here's a framing I found useful: as a user of a library, you may not particularly use generics. But as an implementor of a library, on the other hand, they're extremely useful.

However, comparing to Python won't make much sense; people see generics as essential to statically typed langauges. You don't need them for dynamically typed ones!

Re:Why is Rust difficult? by untog on Monday January 22, 2018 @11:07AM (#16205413)
> Here's a framing I found useful: as a user of a library, you may not particularly use generics. But as an implementor of a library, on the other hand, they're extremely useful.

Agreed. Something that's been underlined for me since picking up TypeScript in addition to JavaScript. I can take or leave TS when writing a script, but I consider it indispensable when writing a library.

Re:Why is Rust difficult? by smaddox on Monday January 22, 2018 @10:41AM (#16205161)
In Python, duck typing provides the benefits of generics, minus the static guarantees. If you're using duck typing in python, then you should be able to understand why generics can be useful.
Re:Why is Rust difficult? by dullgiulio on Monday January 22, 2018 @11:09AM (#16205430)
Go uses structural typing which feels like duck typing but it's actually checked at compile time.

That's the reason why the Go community feels generics are not the top priority (euphemism.)

Only in very specific cases (implementing data structures, for example) you can feel the need for generics. Maybe also in serialization, although that's really normal to pass a generic container (object, void *, interface{}) and use introspection.

Re:Why is Rust difficult? by dullgiulio on Monday January 22, 2018 @04:33AM (#16203101)
I do hope it's not true that people from the community would attack you for writing a compile-to-go language.

I don't think it's such a bad idea, considering how stable the language itself is, it's a pretty solid bet.

Re:Why is Rust difficult? by pjmlp on Monday January 22, 2018 @04:55AM (#16203192)
Spend some time on golang-nuts, proposing ideas from "languages for academics".
Re:Why is Rust difficult? by flavio81 on Tuesday January 23, 2018 @12:06AM (#16211170)
>writing a compile-to-go language.

Why not fix Go instead?

Re:Why is Rust difficult? by stubish on Tuesday January 23, 2018 @02:03AM (#16211608)
You can't fix Go directly. You have to convince the language designers that it needs fixing. The fastest way of doing that would likely be at least a proof of concept, or better yet, a complete tool that gets significant community uptake.
Re:Why is Rust difficult? by flavio81 on Tuesday January 23, 2018 @07:47AM (#16213128)
Ah, unlike programmable languages like Scheme or Lisp, where I can modify the language as needed, by using code.
Re:Why is Rust difficult? by krylon on Monday January 22, 2018 @12:07PM (#16205944)
> Pony is interesting but very new - there aren't a lot of libraries

The lack of libraries is what drove me away, too. The type system is gorgeous, though. I really hope Pony grows a decent library ecosystem soon, the language itself was very pleasant to use once I got past the initial learning curve.

Re:Why is Rust difficult? by stubish on Tuesday January 23, 2018 @01:52AM (#16211570)
> I'm a little bit tempted to make a simple compile-to-go language. I'd get lynched at Go meetups for fragmenting the ecosystem, but it might be worth it. I like almost everything about go except the language itself.

If you rephrased that as 'a templating language for generating Go code', it would slot into the 'go generate' build stage and people would love you (if you got it right ;) ). The only current solution to boilerplate and lack of generics is code generation, but the templating languages all seem to suck for Go code generation so people are stuck with writing Go programs to generate Go code (like the various enum generators), or attempt to marry Go code with the standard text templating which is awful to work with (like, say, Xo).

Re:Why is Rust difficult? by gkya on Monday January 22, 2018 @09:33AM (#16204579)
I haven't used Go all that much, but arent the interfaces meant to be used as generics, i.e. in your function you need some data X, and you'll do something with that X. The way you need to achieve this is that expect an X that satisifes a given interface, say Exampler. If a particular X does not support it, you write the method(s) on X's type to satisfy the Exampler interface. IIRC Pike said somewhere that you don't need generics because there should be at least a singleton interface that all possible values of a function parameter satisfy.

(Edit: BTW I do not necessarily agree that)

Re:Why is Rust difficult? by zeugmasyllepsis on Monday January 22, 2018 @10:40AM (#16205153)
There is certainly some overlap between those features, but I think they largely cover different usecases.

For example, consider trying to implement a List data structure in Go. What type does the List hold? It poses no constraints on the type of things put in it, except that they must all share that type.

The List can store `interface{}`, but then there's nothing to stop you from adding two different types to the list. And what type of value would a method like `getFirstItem()` return? Just an `interface{}`, forcing the user to cast.

Go's interfaces express constraints on individual types (e.g. type A has methods Foo and Bar) but not across functions defined on a struct (e.g. the type that a List stores is the SAME type that the getHead() function returns).

Re:Why is Rust difficult? by TheCoelacanth on Monday January 22, 2018 @10:37AM (#16205126)
Pike clearly doesn't even believe his own argument because he added generics for lists and maps. He just doesn't allow users access to the same capabilities.
Re:Why is Rust difficult? by mikojan on Monday January 22, 2018 @08:50AM (#16204277)
Kotlin has coroutines, channels and select.
Re:Why is Rust difficult? by dullgiulio on Monday January 22, 2018 @11:12AM (#16205457)
They are a very fresh addition in a very fresh language. But they look pretty well implemented (explicitly designed after those of Go.)
Re:Why is Rust difficult? by jrs95 on Monday January 22, 2018 @08:30AM (#16204161)
I don’t like any of these things either. But if adding them made compilation take as long as Rust or Swift, I’d rather not have them personally.
Re:Why is Rust difficult? by always_good on Monday January 22, 2018 @07:11AM (#16203785)
On the other hand we ripped out channels and went back to mutexes. And my experienced Go-developer friends seem to have all the same reluctance to use channels after ending up in channel hell.

There are good aspects of Go concurrency like how the whole ecosystem is async by default (like Node's), but truly praising the model is something I mainly hear from beginners.

Re:Why is Rust difficult? by stubish on Tuesday January 23, 2018 @01:44AM (#16211537)
This is something I noticed with Go. Channels are great and all and occupy a decent chunk of the tutorials and whatnot, but they see to be rarely used apart from a fairly cumbersome way of handling timeouts and cancellation. It seems if you stick concurrency in your libraries you end up in knots, and its left up to the code that uses the libraries to wire up all the synchronous & blocking bits.
Re:Why is Rust difficult? by FullyFunctional on Monday January 22, 2018 @08:19PM (#16209987)
I don't know Go, but could you point to more details on the "channel hell"? I would have assumed it was a good way to structure parallelism so I would like to see why not.