r/Jai • • 19d ago

Why Jonathan doesn't like C#?

2 Upvotes

17 comments sorted by

13

u/Warshrimp 19d ago

Generational garbage collection introduces non-deterministic performance degradation.

10

u/DogWasTakenAway 19d ago

It was never meant to be a Systems Language, which is basically the only category of language he cares about. It was inspired by Java and has garbage collection. It would be a massive surprise if he did like it.

8

u/Ashken 19d ago

Garbage collection, for starters

1

u/InSight89 18d ago

GC simply makes it easier for developers to use because they don't need to worry about freeing dead references. You can easily bypass the GC in C# but then you'll be responsible for memory management yourself just as you would C++ etc.

3

u/Itchy_Response_7773 18d ago

behold behold, if performance is one of gour main constraints, you do not want a GC introducing random lags, performance impacts that are not predictable. GCs are good for every day apps with basically no performance implications, for example a webserver (even if using a GC there is poi tless as hell too), your random script doing things, automation and other stuff. Games, DBs, OSs, Drivers etc, pretty much anything matters. Also, GCs do not really make your life easier, it just allows you to know less, which not always is a good thing

1

u/InSight89 18d ago

I'm not arguing with you on those examples. They are valid. All I'm saying is that C# is flexible enough that you can use it without worrying about GC.

You can use structs, pointers and unmanaged memory to completely avoid GC. And long lived reference types (eg static classes) live for the length of the application so have no GC impact.

You can also engineer your project so that GC spikes happen around predictable times (eg scene transitions etc).

Other languages such as C, C++, Rust etc are going to ultimately be better in this regard because they don't even have GC. But I feel like the GC argument against C# is a bit of an overreaction.

1

u/positivcheg 15d ago

Nah, writing no GC code in C# is disgusting.

1

u/InSight89 15d ago

In what way?

It's incredibly common to use value types, ref, and Span which avoid the GC in C# already and that's before you touch unmanaged or unsafe code.

1

u/positivcheg 15d ago

Span is a view, not an allocation.

I’m writing Unity that does lots of 0 GC code and believe me managing IDisposable is incredibly shitty.

C++ has std::shared_ptr, Rust has Arc. C# is shitty. Some things are doable bug in general it’s ugly as hell.

1

u/InSight89 15d ago

Span is a view, not an allocation.

It's a ref struct which allocates an 8 byte pointer to the underlying memory. Value types are automatically freed once they go out of scope. No need to deal with IDisposable. If the Span were a class then it would absolutely put pressure on the GC in hot loops.

The only time you have to deal with IDisposable is when you want to free unmanaged allocations. And you have to do something similar in C++ and Rust.

C++ has std::shared_ptr, Rust has Arc.

These are just shared ownership of a pointer. There's nothing particularly special about these and you can create these in C# as well.

With C++ each owner has to call .reset() before the allocation is freed. Rust does this automatically when each owner goes out of scope but you can call drop(owner) to do it beforehand.

1

u/positivcheg 15d ago

Are you for real. Span<T> does not allocate. It’s a view over some array, period. WTF did you even write.

IDisposable - yes, to “deallocate”. But problem is that you need to explicitly call it. My comparison with C++ and Rust was that they have RAII like mechanism, resources will be cleaned up automatically when the variable goes out of scope. In case of C# you need to explicitly manage that cuz if you have some struct that is IDisposable and allocates unmanaged array you pass it to some method it is just copied, there is no management provided by the language like in C++ or Rust.

1

u/InSight89 14d ago edited 14d ago

Are you for real. Span<T> does not allocate. It’s a view over some array, period. WTF did you even write.

I'll begin by stating I'm no coding expert so I'm probably wrong. But my understanding of allocation is any memory that is used (aka allocated) for any particular purpose.

A Span contains an 8 byte reference to the underlying memory in which it views along with a 4 byte integer for length. That's not free or zero memory. The span itself is allocated on the stack and lives within the scope of the method it was created.

In case of C# you need to explicitly manage that

Perhaps. But it's not particularly difficult. A minor inconvenience at best. And there are some tricks you can use to automate this. For example, Unity's native collections. You don't need to dispose Temp allocations because it's done for you at the start of every frame.

you pass it to some method it is just copied

You can pass it by reference. No need to copy. In fact, Microsoft recommends any value type greater than 8 bytes should be passed by reference.

2

u/MBKH 18d ago

others already answered the question, i'm here just to give the source:

https://youtu.be/TH9VCN6UkyQ

2

u/-goldenboi69- 18d ago

Who does?

1

u/Ceigey 17d ago

He’s a big fan of manual memory management, but also doesn’t like a language with too many features, so like Zig, Odin etc (themselves inspired by Jai), the idea is “for the features we want to have, how can we maximise the language around only those things”.

C# is like Java (but beyond it in complexity) and more like Kotlin, in that the market is completely different: “we have all these enterprise programmers who know C#, how can we let them build EVERYTHING so our (Microsoft’s) clients don’t have to find alternative solutions (aka other languages)”.

Kotlin is similar but prioritising the Java and Google ecosystems. Eg Kotlin Multiplatform is basically “how can we get merge these (ex-)Java peeps with the Android peeps?”

To extent the JS ecosystem is similar, but more vendor agnostic, and different starting point with all the weird outcomes that result from that.

Now with AI, apparently the plan is “tell Claude to make everything in Rust”. This is still not attractive to Jai’s target audience because they are generally very memory-conscious people and just because Rust gives AI guardrails, doesn’t mean it optimises intentionally unless prompted carefully, in which case, why not write the structs and allocs yourself?

1

u/th3W3n 15d ago

Not low level enough I guess?

0

u/Additional-Wait-7567 19d ago

For obvious reasons, but when did he talk about it?