Live data from Hacker News

Should I Rust or Should I Go?

kerkour.com

151–160 of 178 posts

Re: Should I Rust or Should I Go?

#151

Earlier quoted context omitted.

Static == final?

static methods, they won't be virtually dispatchable, and will be potentially inlined.

That is a good point, but soulbadguy was pointing out that if you make a (non-static) method "final" then you can't override it in a subclass, which should have the same effect, without having to change the semantics by making the method "static".

That said, if there are no actual subclasses of a given class, the JVM will know that, and should be able to inline functions as necessary. That is complicated quite a bit by the fact there is no exhaustive list of which classes are available (the JVM only knows which classes it's seen), and that new classes can be added during the runtime (e.g. Tomcat will load a WAR at startup which will add new classes, or Maven might download a plugin and execute code). But if that _doesn't_ happen, i.e. you load a class and the JVM never sees a subclass and it decides to optimise that part of the code then it will inline what it can (and un-inline it if a subclass shows up later.)

Re: Should I Rust or Should I Go?

#152
> Rust was Stack Overflow's most loved language for 7 years in a row ... and yet, was ranked as the 14th.

Go is ranked 13th. Seems weird to use language popularity as a criticism when you're only choosing between the 13th and 14th place options.

Besides, in 2023 their "All Respondents" usage is almost identical, with Rust showing stronger year-over-year growth than Go.

Re: Should I Rust or Should I Go?

#153
post #115

Earlier quoted context omitted.

> that it has a standard library that is world class for building a worldwide ads serving network What does the golang standard lib have for that use case that Java doesn't have, or do better? > but the argument is that forcing programmers to use a quite limited set of abstractions makes code more readable There's a good balance. Sure you can probably argue that Scala opens the door for many different ways to write a…

I agree that Java definitely strikes a middle ground. It has enough features you can write code in the ways you want (generics, first class functions) but not so many you can create unintelligible messes (implicits). I generally tend to think of Java is "truly general purpose" because it has enough speed/scalability to implement a database while being generally easy enough for beginners to learn and providing enough…

> Java I would still call verbose, it's more verbosity than I tolerated when I was greener but I have come to appreciate a certain amount of ceremony isn't necessarily bad - if it helps to efficiently communicate the intent of the programmer.

In my experience the trick with Java is to use a purpose built editor like Eclipse or IntelliJ. Once you've achieved competence with an appropriate tool the syntax kind of fades from your attention and you focus on the important parts. Kind of like how experienced Lispers using an appropriate editing mode don't really pay much attention to the parentheses.

Re: Should I Rust or Should I Go?

#154
post #147

Earlier quoted context omitted.

> these days with @NotNull and powerful editors like IDEA stopping you from doing dumb things I'm so sick of these half-arsed "features" that somehow get adopted into Java code bases. Stop what you're doing and go write a unit test for @NotNull (or @NonNull). Watch the null value happily bypass those "checks". Or, use (or write) a notNull() method (I happen to use commons-lang3) and watch it actually work.

I agree - but in a comparison of Java vs Go - in Go there's no support for checking nulls at all, which is surely worse than Java's situation. I mean you can literally assign nil to a "func" type, and then call that func and it'll panic at runtime. Neither the compiler nor the JetBrains IDE will warn you about that, and there are no @Nonnull type annotations you can add (even if they're not ideal as you rightly point…

Here's my last week story. I was trying to debug an NPE, so I added the `notNull(` line in the follwing:

  @PUT
  @Path("/{rest}/path")
  @LogBody
  public Answer controllerMethod(
    @PathParam("param1") UUID param1,
    @ApiParam(required = true, value = "body") @NotNull @Valid Body1 body1) {
        notNull(body1, "Annotations are a joke. This null value made it through reqired=true, NotNull, and Valid");
        return service.serviceMethod(param1, body1);
  }
And sure enough that line was hit:

  2023-09-08T07:34:34,511 ${env:K8S_POD_IP}  WARN  org.eclipse.jetty.server.HttpChannel - /api/v3/service/rest/path
    javax.servlet.ServletException: javax.servlet.ServletException: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException: Annotations are a joke. This null value made it through reqired=true, NotNull, and Valid
      at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:162) ~[jetty-server-9.4.44.v20210927.jar:9.4.44.v20210927]
      at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:179) ~[jetty-server-9.4.44.v20210927.jar:9.4.44.v20210927]
      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[jetty-server-9.4.44.v20210927.jar:9.4.44.v20210927]
I just don't know what is to be done at this point. I don't know how the median Java programmer doesn't walk away after getting burned by this one.

Re: Should I Rust or Should I Go?

#155

Earlier quoted context omitted.

static methods, they won't be virtually dispatchable, and will be potentially inlined.

That is a good point, but soulbadguy was pointing out that if you make a (non-static) method "final" then you can't override it in a subclass, which should have the same effect, without having to change the semantics by making the method "static". That said, if there are no actual subclasses of a given class, the JVM will know that, and should be able to inline functions as necessary. That is complicated quite a bit…

I also read in internet that JVM inlines all method calls by default, and fallbacks to virtual dispatching if finds out it is needed.

Re: Should I Rust or Should I Go?

#157
post #154

Earlier quoted context omitted.

I agree - but in a comparison of Java vs Go - in Go there's no support for checking nulls at all, which is surely worse than Java's situation. I mean you can literally assign nil to a "func" type, and then call that func and it'll panic at runtime. Neither the compiler nor the JetBrains IDE will warn you about that, and there are no @Nonnull type annotations you can add (even if they're not ideal as you rightly point…

Here's my last week story. I was trying to debug an NPE, so I added the `notNull(` line in the follwing: @PUT @Path("/{rest}/path") @LogBody public Answer controllerMethod( @PathParam("param1") UUID param1, @ApiParam(required = true, value = "body") @NotNull @Valid Body1 body1) { notNull(body1, "Annotations are a joke. This null value made it through reqired=true, NotNull, and Valid"); return service.serviceMethod(pa…

I get what you mean, it's certainly confusing.

There are various different @NotNull so I'm not sure which you're using, some (but not all) of them are more compile-time contract type things. So if you called that method with null then you'd get an error from a code analysis tools. But that @PUT method is called by the framework at runtime based on an incoming REST request, there's no line in your code which calls the method with null, therefore nowhere for the code analysis tool to see the error and report it.

So yeah, all really confusing, and doesn't always do what you want. Nevertheless, I feel that at least there is a chance to use them and they do sometimes find bugs, which is better than Go's situation of having no way to specify that a method shouldn't be called with null. So if you do call such methods with nil in Go, even in a way that could never work, and which would theoretically be detectable at compile time, you just always get a runtime crash.

Re: Should I Rust or Should I Go?

#158
post #17

In what world is Go more reliable or faster than Java? Especially modern Java (or other good JVM languages like Kotlin). It compiles faster but that is about it. Which is a good thing too because it's verbose AF and heavily reliant on code generation even after generics shipped so that compiler lines/s actually matters. The only knock you can put on Java for reliability is null-safety but lets be real, nil pointers,…

Having worked on one of the largest golang code bases on the planet, I agree completely. I would always think to myself how much simpler and more reliable the programs I saw would have been in Java. But hype is hype I suppose, not to mention so many unsubstantiated claims.

Could you please tell a bit more about your project, I'm very curious.

Re: Should I Rust or Should I Go?

#159
post #142

Earlier quoted context omitted.

Also work in cloud and we only do .NET, Java, and node, coupled with C++ when needed. Anecdotes.

That's surprising to me, I don't think .NET or node are approved languages at Google. Are you part of some acquisition?

I work in cloud, as in, cloud native development, targeting AWS and Azure based infrastructure.

Re: Should I Rust or Should I Go?

#160
post #142

Earlier quoted context omitted.

I work in cloud and every single one of our new projects is in go

Also work in cloud and we only do .NET, Java, and node, coupled with C++ when needed. Anecdotes.

This particular thread is about golang use in google. So your comment doesn't appear to apply.
Post reply on HN