17
Sugar
217d

Java: String foo =“bar”;
C#: var foo = “bar”;
Go: var foo string = “bar”

I just started learning Go and I’ve been cringing since.

Comments
  • 17
    foo := "bar"
  • 13
    But don't worry there are plenty of other things to dislike Go for
  • 5
    What’s the cringe? I just looked it up and Go does seem to have type inference just like C#.

    What I find cringy is that neither of them has constants (var is mutable).
  • 3
    Indeed variable inference is there like mentioned in reply above. But every data type is following behind the variable name

    func foo(x int) int {

    return x

    }

    The syntax is like a hybrid python and Java or C# so it’s easy to get hands on per say but very awkward for me to read intuitively lol
  • 3
    @Sugar it’s a more modern way I’d say.
    See TS, Dart, Swift, Kotlin, for example, where types come at the end.

    You’ll get used to it quickly and may find it better after some time.
  • 0
    @Lensflare oh I see!
  • 7
    Java has var foo = "bar" too starting from java 10
  • 6
    @Lensflare You have the const keyword in both languages.
  • 4
    ever seen visual basic? i think it'd upset you even more
  • 2
    @Sugar there are plenty of things to complain about in Go but I feel this is where you are the problem because you are set in your ways. It's like when they moved a button in your favourite program to the more logical place but now you feel you go wrong every time. Go is both consistent and has a good reason for it. I now find it actually exactly as how it is logically processed.

    See the accepted answer here and the link to the blog in the comment for full background https://stackoverflow.com/questions...

    @Lensflare what do you mean about no constants? There is const it's one of the few keywords go has.
  • 0
    @Lensflare neither of them have const?
    Golang has them: https://gobyexample.com/constants
    C# has them: https://docs.microsoft.com/en-us/...

    Edit: oh, people already said it. Sorry for repeating it.^^

    Imo there is no language feature that C# doesn't have.
  • 0
    Anyways, it's almost always done the way @12bitfloat wrote it.

    You only really use var if you don't have a value for the variable you're defining.
  • 3
    @hjk101 You’re right. I’ve been doing game dev and working with older languages. Will definitely need to shift my mentality.
  • 1
    @Sugar it's natural I do it too. Just realising it is enough. I'm sure you get used to it and come to hate other things. Like seriously lacking things you found in C++#.
    Sometimes it feels like a scripting language but when you really start using it, you'll notice it's far from it and GC is just about the only thing provided, rest is manual labor
  • 1
    char *foo = "bar";
  • 1
    @ars1 @hjk101 @nitwhiz
    C# const works only for a very limited set of primitive types like int.
    You can’t have constants of instances of own types like classes for example.
    And in C# const doesn’t work with type inference. So no const var.
    So that doesn’t really count for me.
  • 0
  • 2
    @nitwhiz "imo there is no language feature that c# doesn’t have"

    Try Swift or Kotlin and you will start to miss plenty of features in C#. 😄

    * constants for arbitrary values and with type inference (like I mentioned)
    * sum types
    * powerful extensions (not just for methods and instances)
    * conditional conformance
    * type inference for type members
    * opaque types
    * actors

    I don’t say C# needs all of this, but there are many languages with features that you and me don’t know about. Many of them are awesome.
  • 1
    @Lensflare interesting! I really need to look into Kotlin, it's on my list for ages... :D
Add Comment