I understand Rust being type safe, but Im seeing syntax that Ive never seen in my life in Go which looks too messy

var test int < bruh what?

:=

func(u User) hi () { … } Where is the return type and why calling this fct doesnt require passing the u parameter but rather u.hi().

map := map[string] int {} < wtf

  • BatmanAoD
    link
    fedilink
    arrow-up
    3
    ·
    5 months ago

    In both cases, Go and Python, the operator will assign a variable a value and also use it as an expression.

    That is absolutely not true. foo := <expr> is a statement in Go, full stop. Just try something trivial like assigning to the output of :=: https://go.dev/play/p/nPINGc7LO8B

    It’s true that if and for let you use := but don’t let you use var, but you still can’t use the result of the assignment directly. So for instance you need if foo := <expr>; foo { ... } rather than just if foo := <expr> { ... }.

    • thingsiplay@beehaw.org
      link
      fedilink
      arrow-up
      3
      ·
      5 months ago

      Ok I see, I stand corrected then. Its a misconception I had without actually going through all of this, so my bad (will edit my replies to mark them). At least in Python we can do this print(foo := (bar := 3)) but not on its own as foo := 3 .