Live data from Hacker News

From Python to Go to Rust: an opinionated journey (2018)

tech.allo-media.net

71–78 of 78 posts

Re: From Python to Go to Rust: an opinionated journey (2018)

#71
post #69
post #68

Earlier quoted context omitted.

I don't see it in Java or C# for instance. You have to explicitly opt into it by (1) declaring default (parameter-less constructors), and (2) exposing fields you want mutated via setters. On the other hand, golang does not have the ability to prevent "default constructors", and the fact that it has no ability to make types file private further makes this an issue.

Java initializes variables to their zero values. If you want to hide Go struct members from other "files", you can do that trivially by putting them in subdirectories.

> Java initializes variables to their zero values

I know, but that's not what I'm referring to here. I'm referring to someone writing:

    type A struct {
        A int
        B int
    }

    a := A {A: 1, B: 2}

then modifying `A` by adding another field `C int`

The code continues to compile, with `C` being initialized to 0, which can be incorrect.

In Java or C#, you'd add a third value to the constructor, resulting in a compile time error for all constructor invocations.

As I said, I've seen this issue come up in production resulting in bugs.

Re: From Python to Go to Rust: an opinionated journey (2018)

#72
post #71
post #69

Earlier quoted context omitted.

Java initializes variables to their zero values. If you want to hide Go struct members from other "files", you can do that trivially by putting them in subdirectories.

> Java initializes variables to their zero values I know, but that's not what I'm referring to here. I'm referring to someone writing: type A struct { A int B int } a := A {A: 1, B: 2} then modifying `A` by adding another field `C int` The code continues to compile, with `C` being initialized to 0, which can be incorrect. In Java or C#, you'd add a third value to the constructor, resulting in a compile time error for…

I don’t doubt it causes bugs. I wish Go had option types, as well. I’m just saying that it’s not unusual behavior, and you’re going to single languages out for the bugs they enable, you’ve a long future of boring arguments ahead of you.

Re: From Python to Go to Rust: an opinionated journey (2018)

#73
Biggest issue for me is the compile time. Especially in comparison to Go it's a huge difference. At work we have a huge codebase with over 1M LOC. I guess for bigger projects you need proper interfaces so you can split up your code into multiple libraries.

Re: From Python to Go to Rust: an opinionated journey (2018)

#74
post #5

I love Rust. Rust can be frustrating for those who didn't do enough c/c++ but once your brain and eyes get used to it, it becomes a joy to develop with. I never felt so excited writing code unless with Rust nowadays and back when I learned C++ for the first time more than 10 years ago when I was still a teenager. Rust is the closest thing to a perfect language ever existed imho. EDIT: for some reason I get mass downv…

I took a look at your comment history and it seems clear that the downvoted comments were the ones that broke the site guidelines, while your thoughtful and substantive comments have positive scores.

It's true that a fine comment sometimes gets an errant downvote (if nothing else, remember that people misclick). But most of those get corrected by other users who will notice the unfairness and give a corrective upvote. They won't do that, though, if you get upset by downvotes and lash out like this—because then you've broken the guidelines, and that will result in downvotes and flags.

https://news.ycombinator.com/newsguidelines.html

Re: From Python to Go to Rust: an opinionated journey (2018)

#75
post #24
post #6

> I compiled the code and … no error message. Everything went fine. But?! I just added a field to a struct, the compiler should say that my code is not good anymore because I’m not initializing the value where it should be! This is your big hangup with Go? You added a new field, didn’t use that field anywhere, and the compiler didn’t complain? I’ve heard a lot of valid criticisms of the language but this is a new one…

I wouldn't have left Go just because of these but before you write this off as minor thing, I would suggest you look this as one of the core language design decision. It reveals two important language philosophies: 1. Go doesn't follow "you pay for what you use" model. 2. Go isn't too deeply invested in compilation as means for catching errors. Above are not binary language decisions. If you go in one direction stron…

I believe Go is weaker than Python. Python dataclasses/attrs (effectively structs) raise an error instead of silently doing the wrong thing, if you omit a constructor keyword parameter. You can still supply default values, which makes the corresponding constructor parameters optional.

Keep in mind that dataclass defaults suffer from the same "mutable default arguments" issue as function parameters.

Re: From Python to Go to Rust: an opinionated journey (2018)

#76
post #71
post #69

Earlier quoted context omitted.

Java initializes variables to their zero values. If you want to hide Go struct members from other "files", you can do that trivially by putting them in subdirectories.

> Java initializes variables to their zero values I know, but that's not what I'm referring to here. I'm referring to someone writing: type A struct { A int B int } a := A {A: 1, B: 2} then modifying `A` by adding another field `C int` The code continues to compile, with `C` being initialized to 0, which can be incorrect. In Java or C#, you'd add a third value to the constructor, resulting in a compile time error for…

[deleted]

Re: From Python to Go to Rust: an opinionated journey (2018)

#77
post #7

As a Python dev getting into more Rust development, I'm surprised whenever I hear of this as a progression towards better tools, rather than a way of adding new tools into my belt. Django/Flask are great tools for spinning up a CRUD application with authentication/authorization, API endpoints, and a template language if I don't want to build out a React or Vue SPA. Rust is a great language that's opened me to new dom…

I get the fascination people have with Rust and I love to use Rust myself. Part of the fascination certainly is it’s tooling and that Rust nearly seems to force you to make the right decisions. I’ve never wrote in a language were I were so focused on the structure of my program rather than hammering in what I felt. And when you hit compile and it works, it usually does so flawlessly.

However I use Python very often still, just not for every task. Just like you said: Rust is another tool in the tool box and it isn’t that single purpose machine that you buy and use once for a single project, it is that japanese handsaw that is incredible useful and powerful in the hands of the right person. But sometimes you just need to make many cuts fast and then the handsaw (no pun intended) doesn’t cut it.

Python certainly has it’s place for me, but so does have Rust..

Re: From Python to Go to Rust: an opinionated journey (2018)

#78
post #62
post #61

Earlier quoted context omitted.

In this case though, it's the addition of a "feature" that causes bugs, so lack of said feature will improve correctness.

Zeroing out uninitialized memory is a feature, one which significantly improves correctness over C/C++. Meanwhile, the scenario described in this blog post is shared by virtually every mainstream implementation language other than Rust.

> Meanwhile, the scenario described in this blog post is shared by virtually every mainstream implementation language other than Rust.

I don't believe that TypeScript, which is mainstream, has zero values if strict mode is enabled. (I could be wrong though; plugging all the "undefined" leaks is hard in JS.)

Post reply on HN