News for hackers. Stuff that matters.
Re:My favorite Rust function by jchw on Saturday October 12, 2019 @07:43PM (#21237148)
> or making the language unacceptably crippled like Go

Gotta say, I lost a lot of respect for the author at this point. It’s not like I don’t love Rust - quite the contrary - but if the only takeaway from Go for you is that it is “unacceptably crippled” then I feel you have missed a lot of insight. Go has been one of my languages of choice for over half a decade now, and for good reason.

Re:My favorite Rust function by AdieuToLogic on Saturday October 12, 2019 @10:37PM (#21237944)
> > or making the language unacceptably crippled like Go

> ... if the only takeaway from Go for you is that it is “unacceptably crippled” then I feel you have missed a lot of insight.

Perhaps the author used a poor choice of words and instead could have phrased their intent along the lines of:

Go lacks the semantic density needed to express solutions in both a concise and consistent manner.

Were this the case, it would be hard to disagree as Go does, indeed, lack linguistic capabilities present in other programming languages which enable developers to encode system constraints within the language itself. Some might see this as a benefit, but I do not. YMMV.

A similar philosophy of "keep the language dirt-simple so anyone can code in it" was a driving force behind Java (the language) and JavaScript. What people have discovered is that when a programming language does not assist in expressing intrinsic problem complexity explicitly, it becomes implicitly intertwined within the source itself.

Re:My favorite Rust function by ErotemeObelus on Sunday October 13, 2019 @12:06AM (#21238288)
I think it's a syntax problem. ASCII doesn't have enough bracket characters to simply & clearly represent necessary language features. So it's harder for an intelligent human to sort and categorize these aspects.

Pre-generics Java is about the appropriate amount of language complexity for our current lingua franca

Re:My favorite Rust function by AdieuToLogic on Sunday October 13, 2019 @01:43AM (#21238582)
> Pre-generics Java is about the appropriate amount of language complexity for our current lingua franca

I am not sure to whom you are referencing as being "our", so I can only say I disagree as there are many developers which are quite adept in languages having more complexity than "pre-generics Java."

Perhaps you meant to reply to a different comment?

Re:My favorite Rust function by pjmlp on Sunday October 13, 2019 @02:11AM (#21238669)
It surely isn't mine, otherwise I wouldn't be happily using Java 13 right now.

Also even Google does have more stuff going on Java, C++, Dart, Kotlin and TypeScript than Go, which has more uptake outside Googleplex.

Re:My favorite Rust function by erik_seaberg on Sunday October 13, 2019 @03:11AM (#21238908)
Java is tolerably mediocre now but vintage 1996 Java was awful (and slow). I enjoy Scala, but even I can see why it's more than most of the industry is ready for. If there's a sweet spot, Kotlin seems close to it.
Re:My favorite Rust function by coldtea on Sunday October 13, 2019 @12:23PM (#21241215)
Err, we had 10x times the features of "Pre-generics Java" even in 1970s Lisp and Smalltalk...
Re:My favorite Rust function by Gene_Parmesan on Sunday October 13, 2019 @03:35AM (#21239009)
I will gladly trade a little bit more language complexity if it means the complexity of the code that I write using that language is simpler.
Re:My favorite Rust function by erik_seaberg on Sunday October 13, 2019 @05:00PM (#21242994)
This. When a platform refuses to solve a problem, that problem doesn't go away. The users are forced to roll their own solutions, none of which have the same test coverage and optimization opportunities.
Re:My favorite Rust function by EdwardDiego on Sunday October 13, 2019 @03:40AM (#21239030)
Generics don't make Java that much more complex for your workaday Java coding.
Re:My favorite Rust function by jjoonathan on Sunday October 13, 2019 @02:17AM (#21238693)
Speak for yourself.
Re:My favorite Rust function by bsg75 on Sunday October 13, 2019 @11:35AM (#21240932)
> Go lacks the semantic density needed to express solutions in both a concise and consistent manner.

That is a difficult statement for a Go user to parse.

It is referring to a lack of language features that result in verbosity or boilerplate?

Re:My favorite Rust function by coldtea on Sunday October 13, 2019 @12:22PM (#21241210)
There's a lack of language features that result in verbosity, boilerplate, less performance and/or less type safety.
Re:My favorite Rust function by viraptor on Saturday October 12, 2019 @08:09PM (#21237274)
It may be an unnecessary dig, but the author may indeed be familiar with Go and still think it's unacceptably crippled for all their use cases. The whole post is just their opinion.
Re:My favorite Rust function by root_axis on Saturday October 12, 2019 @09:51PM (#21237741)
In my anecdotal experience, the type of programmers that evangelize and talk shit about programming languages tend to be on the less informed side of the knowledge spectrum.
Re:My favorite Rust function by vertex-four on Sunday October 13, 2019 @03:28AM (#21238977)
I occasionally program Go because it has an amazing amount of libraries - I basically use it for random microservice type things that glue systems together. (Most recently, an HTTP login endpoint that sends and receives XMPP messages to authenticate the user.)

I don't like it. I program Rust the rest of the time. I'm considering learning Perl5 so that at least my type system lets me do vaguely expressive things - I'm utterly fed up of half my code looking like:

    foo, err := something()
    if err != nil {
        return nil, someErr{err}
    }
I got very used to Rust's try!() macro, now ? operator, and being able to map over Results to convert between error types in a single line that feels much less noisy - I have functions in Go that are a dozen or so lines that would've been 3 in Rust, and tbh I struggle to follow what the function actually does when 3 out of 4 lines are to do with the failure case.

I would consider "unacceptably crippled" to be a reasonable description of Go, even if it's the best tool I have for some jobs.

Re:My favorite Rust function by root_axis on Sunday October 13, 2019 @12:05PM (#21241113)
"unacceptably crippled" is a pejorative meant to insult, not a descriptive criticism.
Re:My favorite Rust function by AdieuToLogic on Saturday October 12, 2019 @11:23PM (#21238146)
> In my anecdotal experience, the type of programmers that evangelize and talk shit about programming languages tend to be on the less informed side of the knowledge spectrum.

Or maybe they have just expanded their "knowledge spectrum" and are experiencing an effusive moment?

Re:My favorite Rust function by root_axis on Saturday October 12, 2019 @11:43PM (#21238221)
Talking shit isn't effusive. It's possible to enjoy a programming language without openly denigrating others you regard as inferior.
Re:My favorite Rust function by AdieuToLogic on Sunday October 13, 2019 @01:35AM (#21238565)
It's apparent you have dealt with negative situations such as you describe. Here is a haiku which may be helpful:

  Those who can will do,
  Those who cannot will seek to,
  Hide that fact from you.
HTH
Re:My favorite Rust function by AdieuToLogic on Sunday October 13, 2019 @12:39AM (#21238392)
> Talking shit isn't effusive. It's possible to enjoy a programming language without openly denigrating others you regard as inferior.

Both points you make I agree with. I simply was offering a possible explanation for those whom exhibit overly passionate opinions when they become enlightened.

When people take an epiphany to the point of denigrating those around them, then they likely have issues beyond what any programming philosophy could possibly encode.

Re:My favorite Rust function by jchw on Saturday October 12, 2019 @08:16PM (#21237304)
Sure, and my opinion is that this is a very shallow takeaway. My whole comment is just my opinion.
Re:My favorite Rust function by bsder on Saturday October 12, 2019 @10:00PM (#21237788)
> if the only takeaway from Go for you is that it is “unacceptably crippled” then I feel you have missed a lot of insight.

Um, the whole point of Go was to be "opinionated and acceptably crippled". That's why the creators built it the way they did. Go has more than a few things where "Me, but not for thee" rules--the compiler can do X but you cannot. If you find that is an acceptable tradeoff for the other features of Go, great!

Lots of modern languages, however, are trying to go the other way. They are trying to give the programmer every bit of power that the library/compiler programmers have. This has its own failure modes that you may find unacceptable. That's fine too.

I personally dislike the Rust vs Go discussions. Those two languages in particular really don't have domain overlap and are like comparing apples to screws.

Re:My favorite Rust function by legends2k on Saturday October 12, 2019 @11:52PM (#21238251)
Minor nit: would've been better if you'd put 'screws and apples'. 'Rusty screws' and 'Go apples!' sound better then when interchanged :P
Re:My favorite Rust function by mav3rick on Saturday October 12, 2019 @09:53PM (#21237752)
It is crippled admittedly by the authors themselves. The error checking pattern, no generics etc. are all to keep it "simple" yet are things most other programming languages have. Have you used Rust ? The borrow checker makes a lot of sense.
Re:My favorite Rust function by jchw on Saturday October 12, 2019 @10:10PM (#21237830)
I feel like I shouldn’t have to answer this question, but Yes, of course I’ve used Rust. Why do you question this? I said nothing about Rust at all, other than that I like it, and whether Rust is good or not has little to do with Go being “crippled.”

But of course, Rust is not flawless. In fact up until recently it was kind of annoying, before non-lexical lifetimes became a part of the language. It’s also a very large and complex language compared to Go. This is not unilaterally a bad thing, but just as every line of code comes at a cost, so to does every language feature, and if enough language features fail to pay the rent your programming language will end up feeling bloated.

What Go lacks is exactly its strengths. If you criticize C for not having Java-style exceptions, people will look at you funny. There is some divide in the community over error handling but I defend that Go’s verbose and stupid error handling pattern is my favorite part of the language, and changed how I code inside and outside of Go. I also appreciate Go’s simple but effective patterns for composition-based object oriented programming, and for having a decent concurrency model (not that it is without flaws: the limitation of Go’s memory safety is definitely an issue here.)

Everything comes at a cost. The borrow checker brings immense promise for security, but that does not mean other approaches to memory safety or language design are suddenly obsolete. It’s more complicated than that, and I consider failure to understand this to be a sign that someone is not keeping an open mind.

Re:My favorite Rust function by enraged_camel on Sunday October 13, 2019 @02:21AM (#21238707)
>>What Go lacks is exactly its strengths.

Surely you understand that this is a very self-serving attitude, though?

It's like someone points out that your car is crippled because it has a turning radius of 2 degrees and also has no brakes, and you go, "no but you see, what this car lacks is exactly its strengths! And it's those strengths that I enjoy the most when driving this car!"

Re:My favorite Rust function by baby on Saturday October 12, 2019 @11:07PM (#21238078)
“Crippled” has a negative connotation. I’d say it is not crippled but kept self-contained without a multitude of overlapping features.
Re:My favorite Rust function by baby on Saturday October 12, 2019 @10:23PM (#21237870)
I work with Rust only these days, it’s really an awesome language and I wish everyone working with system languages would switch to Rust. Yet, I find Golang to be a much clearer language to read (and I read a shit ton of code). I hope they don’t add generics, but I wish they would options, results, sum types in general, redeclaring variables, the ? Operator, etc.
Re:My favorite Rust function by EdwardDiego on Sunday October 13, 2019 @03:45AM (#21239053)
Interesting, I've been reading a lot of Golang of late as we move into k8s world, and I find it hard to read, mainly in terms of package layout - types and their related functions are often in very different places.

But it's certainly less semantically dense compared to Rust or Scala etc.

Re:My favorite Rust function by saturn_vk on Sunday October 13, 2019 @03:08AM (#21238889)
I doubt that any genetic syntax will significantly impact go readability. The only syntax overhead will be in type definitions, not in type usage, and the later is present a lot more than the former. Couple that with the current need to add extra type assertion on type usage, and you may be looking at overall readability improvement
Re:My favorite Rust function by emptysea on Sunday October 13, 2019 @02:07AM (#21238656)
How would Option<T>, Result<T, E>, and sum types work without generics?
Re:My favorite Rust function by baby on Monday October 14, 2019 @02:41PM (#21251393)
Native support is the answer.
Re:My favorite Rust function by rumblefrog on Sunday October 13, 2019 @02:28AM (#21238728)
Empty interface perhaps.
Re:My favorite Rust function by EdwardDiego on Sunday October 13, 2019 @03:39AM (#21239024)
Crippled is a good way of describing "use a map[T]struct{} when you need a set of T" in my mind.
Re:My favorite Rust function by goto11 on Sunday October 13, 2019 @07:06AM (#21239750)
Regardless of the merit of his criticism, it clearly derails the whole discussion about this blog post, which was just about a cool feature of Rust.
Re:My favorite Rust function by zozbot234 on Sunday October 13, 2019 @02:48AM (#21238810)
Go is a fine GC language - in many ways, it's a lot better than the likes of Java! But it's nonetheless way too clunky for many use cases, which is what the OP may have meant by their remark. And the concurrency support comes with a lot of nasty pitfalls, especially compared to Rust or even Pony.
[dead]
Re:My favorite Rust function by shhsshs on Saturday October 12, 2019 @11:10PM (#21238092)
> Enumerations

    type myEnum int
    const (
        someValue myEnum = iota
        anotherValue
        moreValues
    )
> Sum types

Consider thinking about the types in your sum type and what they have in common, and define an interface that they share.

> Recursive types

Not sure what you mean. This is valid Go:

    type tree struct {
        value int
        left *tree
        right *tree
    }
> Parametric polymorphism

Yes Go sucks in this area. `sort.Interface` is a good example of a workaround, but it isn’t ideal in any way.

> There is no this in GOLANG:

Is this not acceptable?

    var x interface{}
    json.Unmarshal([]byte(“[1,2,3]”), &x)
And if you don’t like that you get back a `[]interface{}` that happens to hold `int`s that you must type assert, just do it the better way:

    var x []int
    json.Unmarshal([]byte(“[1,2,3]”), &x)
Re:My favorite Rust function by crimsonalucard on Saturday October 12, 2019 @11:39PM (#21238207)
> Enumerations

- those are integers not enumerations. In Golang they have a type Bool which is either true or false. Can I define my own type using the same convention in GoLang? No. I can't. Ideally I want the ability to do this:

   type Bool = Enum {
      True
      False
   }
or

   type Tri = Enum {
      True
      False
      QuantumTrueFalseDuality
   } 
But in Golang I'm locked in with what the creators provided as primitive types. I can't go deeper. Rust you can.

> Sum types.

I don't think you know what a sum type is. This is what I mean by lack of knowledge. For sum type (A | B), A and B do not need to have a single thing in common and they do not need to share an interface. Think of a product type (A, B) as A and B and a sum type (A | B) as A or B.

The most glaring replacement of sum types in go are done with product types that contain errors from IO functions in GoLang. The Error type does not have anything in common with the Value it usually shadows and therefore both cannot be represented with an interface.

> Recursive types.

That's somewhat recursive. But that's a pointer. This works and is valid. Ideally though it shouldn't be a pointer but for efficiency during memory allocation this is a viable restriction. Recursive types only with pointer types.

> Parametric Polymorphism

I agree with you.

> Is this not acceptable?

No it is not acceptable. Interface is unusable until you make the type concrete with your asserts. Asserts are you executing a guess on a possible JSON permutation. In your second example you are guessing the type to be an array of INTs. What if that string was arriving over the wire as IO and you don't know what configuration it will be in? What if the typing was more complicated?

   jsonString = "[1,2,True,[1,2,\"hello\"]]"
or

   jsonString = randomJSONFromIO()
The assert also leaves an opening for a runtime error which is unacceptable.

imagine syntax like this:

   type JSON :: []JSON | Struct{string: JSON} | bool | int | string | null
   var x JSON = json.Unmarshal("[[1,2,True,[1,2,\"hello\"]],{}, null]")
JSON is a type represented using sums (|), products (Struct) and recursion (JSON). There is no possibility of run time errors here as you don't need to guess a specific permutation of JSON. You don't need to guess because such a type system can fully represent JSON. You see what is missing with go?
Re:My favorite Rust function by shhsshs on Wednesday October 23, 2019 @08:06AM (#21333692)
> Enumerations

I don't see the value in defining a custom underlying type for an enum. If it's for efficiency, sure. I've never had to use enums in a heavily performance-sensitive context so I don't personally relate to that.

> The assert also leaves an opening for a runtime error which is unacceptable.

You can handle errors gracefully.

    // default to 0
    maybeInt, _ := myValue.(int)

    maybeInt, ok := myValue.(int)
    if !ok {
      // do something else
    }
> imagine syntax like this:

In my opinion JSON with multiple types like that is poor design.

Regardless, even with sum types the programmer has to write code for most possible states each value could be in. You have the same capability in Go with type assertions.

    // Rust
    match myValue {
        int => ...,
        string => ...,
        // etc.
    }

    // Go
    switch myValue.(type) {
        case int:
            ...
        case string:
            ...
        // etc.
    }
Re:My favorite Rust function by crimsonalucard on Wednesday October 23, 2019 @10:03AM (#21334717)
This isn’t about personal opinion. This is about understanding the fundamental mathematics behind types. In type theory there are two fundamental composite types. Product types and sum types. Sum types are types that can be A or B or C. Product types can be A and B and C.

An example of a product type is any type that can hold multiple typed entities, whether that’s a list, array, structure or map.

An example of a sum type is polymorphism defined using inheritance. The children of a parent type are encoded into the type itself, but the type instantiated can only take the form of one of the children.

Note that my example for the sum type is isomorphic to a typed enum. It’s literally the same concept. Sum types and product types are mathematical opposites. Every language that has algebraic data types has this concept encoded into it. Go is one of the few typed languages that doesn’t have it.

Let’s get away from the mathematics and talk about practicality. Your example of the switch and pattern matching. Let’s say myValue is an int, a string or a float.

Let’s also say that when you are coding you miss checking for the float case and you add an extra invalid case where the code checks for Double? What happens in rust or go? In go nothing happens because go doesn’t truly know the underlying type so by doing this the code compiles and you have encoded a runtime error into the code.

For rust exhaustive type checking will catch both the missing handler and the invalid case. That’s right rust will know you have missing logic based off of the type. This is a powerful feature that is encoded into most languages that have algebraic data types.

Now let’s take the conversation back to math. The fundamentals. Have you ever thought about what an Int actually is? Looks like an enum doesn’t it?

   type int = 0 | 1 | 2 | 3 ...
If you really want to get deep an int is actually a recursive enumeration similar to json.

   type int = 0 | (int, 1) | (int, 2) | (int, 3) | ... (int, 9); 
So for example ints are instantiated like this..

   0 = 0,
   1 = (0, 1)
   2 = (0, 2)
   .
   .
   .
   12 = ((0, 1) 2)
   .
   .
   .
   456 = (((0, 4), 5), 6)
Operations like addition and multiplication are defined in terms of inductive mappings between enumerations.

This fundamentally what a type is. Any language missing the ability to define this is missing a mathematical primitive. It is incomplete. Go is a language that simply has an arbitrary enumeration (int) defined and the rest of the code needs to build off of it as there is no mechanism to define your own. Ints should be encoded as enumerations not the other way around.

Re:My favorite Rust function by HeyImAlex on Sunday October 13, 2019 @01:13AM (#21238504)
Isn’t that JSON example the same in python, javascript, and ruby?

Unmarshalling into an interface is really just a shitty enum; the number of permutations is finite. A type switch here is like a match but less type safe because it won’t check exhaustiveness of the branches.

Re:My favorite Rust function by crimsonalucard on Sunday October 13, 2019 @01:46AM (#21238589)
>Isn’t that JSON example the same in python, javascript, and ruby?

No. Python doesn't have type checking. That example is a made up syntax of golang if golang had all the correct type primitives.

In this example I am defining a type in the first line, similar to how you would define a struct in golang. Then using the type in the second line.

There is a bit of an error, but it's too late to edit it now. the Struct in the type line should be map[string]JSON.

>Unmarshalling into an interface is really just a shitty enum; the number of permutations is finite.

The permutations of JSON are infinite. In the real world there are APIs describing deeply hierarchical data that have unpredictable deeply nested data structures. If I had a random JSON string generator, it's not that straightforward how you would save that JSON to a correctly typed variable in a GO program.

Unmarshalling you will have to define a new type for every permutation. It makes more sense to traverse the data structure to find it's structure rather then take a wild guess.

Either way in golang that "guess" happens at runtime so it will spit out an error at runtime, while with sum types and match you are type safe before the program even runs.

Re:My favorite Rust function by HeyImAlex on Sunday October 13, 2019 @02:22AM (#21238713)
I mean... that’s the point I was making. Interface is just like using a dynamically typed language. So saying python can do this but golang can’t is wrong. They are effectively the same.

RE: Permutation, the unmarshalled value will only ever be float64, bool, string, interface[], or map[string]interface. The nested interfaces are recursively defined. It’s literally just like doing it in rust, except the compiler won’t do exhaustiveness checks for you.

Re:My favorite Rust function by crimsonalucard on Sunday October 13, 2019 @04:01AM (#21239133)
Hm. Ur right bad examples. The only advantage rust has then is more elegant syntax and safety for JSON. Ur also right about python and ruby. It is effectively the same.

Overall though the need for assert is a sign of a crippled type system.

Re:My favorite Rust function by speedplane on Sunday October 13, 2019 @04:10AM (#21239159)
> Overall though the need for assert is a sign of a crippled type system.

Given that most (if not all) new applications have to ingest data from third party systems and export outgoing data to other third party systems, the need for assertions and data validation is not going away, even in strongly typed systems.

JSON is becoming the de-facto data transfer format, and thus JSON input validation is necessary in both weekly and strongly typed systems. Assuming this JSON trend continues, we can predict stronger JSON type checking built directly into languages.

Re:My favorite Rust function by crimsonalucard on Sunday October 13, 2019 @11:37AM (#21240948)
Uh no. Type assertion is not always required. This is false. Also type assertion is not a good thing in a strongly typed language. This happens in Golang exactly because the go type system is flawed. It doesn’t need to happen.

There is a huge difference in guessing a type using assertions or writing handlers within the boundaries of a domain. Alex’s point that writing such code is effectively the same as rust because the amount of code is the same. However safety is lost. There is literally no point of having a type system in place when unmarshalling Json in go because you have no type safety. In go if you assert the wrong type or if your missing a required assert the error may be hidden and if it’s not hidden you can only see it during runtime. In rust there is no type assertion, only type checking, so such a program won’t even compile.

Re:My favorite Rust function by dullgiulio on Sunday October 13, 2019 @04:42AM (#21239268)
Those above are not integers but type that you have to explicitly cast integers to if you really want. Please don't make uninformed comments.
Re:My favorite Rust function by crimsonalucard on Sunday October 13, 2019 @11:41AM (#21240975)
I don’t understand what you are referring too. Why don’t you clarify, then we’ll see who is truly uninformed. I readily cop to my mistakes and errors. Will you?
Re:My favorite Rust function by blub on Sunday October 13, 2019 @01:28AM (#21238543)
Rust was born as a critique towards C and C++ and putting down other languages is part of the community DNA.

Go is a favorite target, but Python, Ada, Java, C# etc didn't remain unscathed either.