31

working on two projects.
at the same time.
for 2 different companies
2 completely different scenarios
2 completely different languages

nodejs and golang

Comments
  • 1
    Same boat brotha/sista
  • 2
    How do you like Golang??
  • 1
    golang is good if you stay away for on jsonapi, which my employer did not understand
  • 1
    am working on a personal project and doing the same thing just to learn golang and improve in node.keep yourself polyglot.
  • 1
    @grolofson golang can be nice to you if you use it nicely. stay away from things like jsonapi compliance and you will be just fine. proto buffers are also supported but the thing I hate is that it cannot me nil. complicates the matter a lot more
  • 0
    @rohithzr what's the best way to handle json api? I was being shown how this lang works and the syntax looks all kinds of weird and I was told that when you run template execute you can only pass on thing in which complicated things I the template when you want to range over different things.. Is this true??
  • 1
    @grolofson look the best parts are the range func, multi var return

    bad part is what you said, so normally (node.js) we send a json as request and on server we place it in a var and use it.

    but in go you'll have to define a struct of what exactly will be in json.

    but the problem is unlike json things(keys) cannot be null(nil) this causes mayhem.

    if req is PATCH /me -d {name:"Rohit"}

    and in go struct is
    {name string, optionalInfo string}

    on parsing it you will get optionalInfo as blank string.

    now you won't know if the user wants is to be blank or he just didn't send it
  • 1
    unmarshalJSON and *string check for nil .
  • 0
    @rohithzr thanks that was very informative, so could I build say..

    Type user struct{
    Name string
    Age int
    }
    Type student struct{
    Class string
    School string
    }
    Type career struct{
    Field string
    Position string
    }

    users := []user{
    user{
    Name: "John"
    Age: 23
    }
    user{
    Name: "Frank"
    Age: 42
    }
    }
    students := []student{
    student{
    Class how do you put array of class here?
    school: "UCLA"
    class: "welding"
    }
    student{
    school: "Caltech"
    class: "CIT-90"
    }
    }
    careers := []career{
    career{
    field: "medicine"
    position: "Dentist"
    }
    career{
    field: "automotive"
    position: "engineer"
    }
    }

    How to wrap this so I can pass them?
    Data := struct{
    User: user[]
    Student: student[]
    Career: career[]
    }
    err := tpl.Execute(os.Stdout, Data)
    if err != nil {
    log.Fatalln(err)
    }

    How does this help? I'm used to Ruby on Rails and a data base where all variables are always available.
    Sorry for the long example/ question..
  • 1
    @grolofson :D

    OK first yea you are fine with the approach. to put array of classes in your student struct use `Class: []string`

    then you can send `Class : []string{'1',2'}`

    look I did not say that you cannot manage json, I am managing it in my project and we are doing strict jsonapi. so it is an OK approach that you are taking, at least from the first looks
  • 1
    @skonteam well if we unmarshall a json into a struct and in our json there is some column with no data we do not get nil in our struct we get "" quotes empty.
  • 0
    @rohithzr well that's just the first way I thought of doing it, but I'm extremely new to go.

    What would be the best way to store date to make user profiles?? If I don't know the data before hand Google datastore?
  • 1
    @grolofson store it in string, you do not want anything else. if youbwant manipulation capabilities then you need to parse into Date
  • 1
    @rohithzr yes , and to know if the user sent empty field or didn't send the field at all, you can use string pointers instead of strings in your structs and test for nil , if the field is nil then we did not receive it.
    Also you can implement this logic in an unmarshaljson having your struct as a receiver .
    PS: am on my phone I all send a gist later.
    good luck.
  • 2
    @skonteam your both helped me more the the hours before trying to wrap my head around it m. Thanks you ++
  • 1
    @grolofson happy to help
  • 1
    @skonteam hmm. OK I'll try it but the problem I face is because we use protobuffers pointers get messed up. will try this though.
  • 1
    @skonteam i suggested this to my project's "QA" guy.

    he is probably right, anyways I was not allowed to do so :P

    `Don't get me wrong: your friends is right and it may work. It's after all the strategy used by Kubernetes, Docker & Google Protobuf. But it's also the easiest way to strengthen the memory pressure. A garbage collector has to find position of every pointer and a multiplication like this of the number of pointers is just awful. Also, instead of 4 bytes for a number, you store 12 (8 for the pointer + 4 for the number itself). If it was not enough, each pointer access requires a nil check, meaning branch prediction, meaning it's magnitudes longer than a simple number access.
    `
  • 0
Add Comment