I really really hate C#
it’s far from the worst language I’ve used, but I’m trying to learn Unity and unfortunately that means I’m forced to use C# for all of my Unity code. and it is absolutely full of design decisions that I find bafflingly bad
for example, instead of having a module system, every C# file is imported in every other C# file, all the time. they’re all just dumped into each other’s namespaces and there’s presumably no way to opt out of that
but it gets worse, because you can make things even more confusing with using statements. for example you can type using UnityEngine; and C# will happily dump every single thing inside of UnityEngine into your current namespace too. it’s the equivalent of Python’s from UnityEngine import * (which is considered bad practice for reasons that I hope will become clear in just a bit)
so those are already two design decisions that lead to a lot of confusion, but it gets even worse: when you’re accessing an attribute of a class, you don’t have to write this.attributeName - instead you just write attributeName and the this. is implicit
so that means if I’m reading somebody else’s code that looks like this:
using UnityEngine;
public class SomeClass : MonoBehaviour
{
// blah blah
void SomeMethod()
{
return someVariable;
}
}
I have no easy way of knowing, without using an LSP, whether someVariable is coming from:
UnityEngineSomeClassMonoBehaviourMonoBehaviour‘s inheritance chainI think an important feature of any language is for the code to be unambiguous, and unless I’m missing something this is the exact opposite of that: it introduces a ton of ambiguity every single time a variable is used, anywhere in C#. and I’m not even sure what they were trying to accomplish by doing things this way?
if my experiences with Haskell and Common Lisp have taught me anything, it’s that if I don’t like a language in the beginning then studying it more deeply is only going to reveal even more things that I don’t like, and deepen my anti-appreciation of it. but unfortunately I do have to learn this language despite my feelings. I’m going to complain the entire time, though
@kasdeya Many of the design decisions of C# are explained because the syntax is aiming to closely imitate java, which was maybe the biggest language when C# first came out. At the time, it was normal to have to carefully organize your code into namespaces, module systems are a relatively newer invention. And both C# and Java are languages where people are expected to be using IDEs to write them, so access to static analysis tools is taken as a given. I agree the design is superceded by modern module systems, but I think the decision was a sensible one at the time the language was being designed
@kasdeya i’m a bit of a fan of C# actually, theres things i really don’t like, but it makes up for it by having a really nice type system. The generics allow you to statically check a lot of stuff that would be a runtime check in most languages (even in other language that have generics). The reflection is useful too.
In my last company I wrote a class that would call our backend API, but there was just one method “request”. You provided a request body of the type associated with the API u wanted to call, and it would automatically figure out the URL and everything else based on that. Which led to some really elegant code with very solid separation of data from the logic. Everything was automatically validated by the JSON library too, it was great.
@raeaw oohh that is really cool! I’ve noticed that in C# it seems like you can do operations on type parameters as if they’re arguments to the function - which confused me a lot but I can see how it could lead to some really elegant code
type systems still confuse me a lot lol. not the basics of them but as soon as I have to do algebra-type stuff with them I get lost really fast. but I’m hoping I can figure them out for C# since it’s statically typed - and I’ve heard that its type system is way better than Python’s or TypeScript’s anyway so maybe I’ll gain an appreciation for static typing through learning its type system
@kasdeya yeah i started with statically typed languages, and while I do like Lua, Python etc for some things, I find the static typing really helps you reason about the code, you can enforce rules that make it much harder for you or coworkers to misuse them, and it provides built in documentation as well ^_^ e.g. u never have to worry about magic strings because u have enums that list out all the possible values and statically type check them.
Typescript’s types are pretty okay, the problem for me is people can just bypass it with any or by casting (and often have to do so to get stuff to work)