News for hackers. Stuff that matters.
Re:Why Go and Not Rust? by qaq on Monday September 16, 2019 @11:43PM (#20991208)
Would you post an equivalent code in Ruby ? (that like above does validation of inputs)
Re:Why Go and Not Rust? by tinco on Tuesday September 17, 2019 @06:26AM (#20993444)
If you need input validation like that, which you normally wouldn't in Ruby because your models should do it for you, I'd probably use grape or something similar:

  require 'grape'

  params do
    requires :age, type: Integer
    requires :name, type: String
  end
  get "/hello/:name/:age" do
     "Hello, #{params[:age]} year old named #{params[:name]}!"
  end

In any case, my beef is more with the macro than with the function annotation, which is rather spiffy. The macro hides the fact that string manipulation in Rust definitely requires a little bit of manual reading. And I feel that as soon as your app becomes more complex Rust will just start getting more in the way. And to an experienced Rust dev that might not be a big deal, because an experienced dev knows how to work with strings or which memory management strategy so it won't bog them down. But if you're just working on something and you quickly want to whip out a service that tells people what age they are, I'd definitely go for a quick Ruby or Go service.
Re:Why Go and Not Rust? by steveklabnik on Tuesday September 17, 2019 @11:13AM (#20996118)
One of the things this API can do for you is not give you just strings, but fully typed instances of structs. And you don’t need to do the conversions yourself. So you’re not wrong, but it’s easier than you may imagine.
Re:Why Go and Not Rust? by johnlinvc on Tuesday September 17, 2019 @02:36AM (#20992289)
Not exactly the same, since there's no UInt8 in Ruby.

    require 'sinatra'
    get %r{/hello/([^/]+)/(\d+)} do |name, age|
      "Hello, #{age} year old named #{name}!"
    end
Re:Why Go and Not Rust? by qaq on Tuesday September 17, 2019 @02:49AM (#20992370)
I am guessing age would be a string though?
Re:Why Go and Not Rust? by johnlinvc on Tuesday September 17, 2019 @03:12AM (#20992495)
yes, the regex part handles the validation.