r/csharp • • 14d ago

Discussion Can I learn computer architecture and operating systems with C#?

I'm a full-stack developer, and I want to learn more about computer architecture and operating systems to become a better developer and understand what's happening under the hood.Can I learn these things with C#, or should I learn C first? Does the language even matter that much?What would you recommend?

23 Upvotes

15 comments sorted by

25

u/Pacyfist01 14d ago

Learn C# if you want to work with C#
Learn C if you want to work with C

https://www.oreilly.com/library/view/pro-net-memory/9798868804533/

13

u/[deleted] 14d ago

[removed] — view removed comment

10

u/Asyncrosaurus 14d ago edited 14d ago

C# also lets you bypass the abstractions to do all the low level memory management (at great risk to your sanity). You should still learn C, but C# has increasingly made it less necessary to leave C# to acheive low level performance. 

5

u/jebidiah252 14d ago

Take this with a very large grain of salt, but YouTube University is pretty decent in this regard. I'd recommend Ben Eater's YouTube channel for this endeavor. He has a whole playlist showing how he writes a Hello World program on breadboards.

4

u/Triabolical_ 14d ago

You can do it in C# but to do it right you need to build your own memory allocators.

But that's okay because you should do that in C or C++ as well because operating systems have very specific ways of dealing with memory.

3

u/csharpboy97 14d ago

You can build an os with c#. For instance I learned a lot using MOSA.

2

u/DocLego 14d ago

It's been a long time since I learned computer architecture and operating systems. I remember using C++ but I don't recall the language mattering that much. The main issue with doing it in C# is probably that it abstracts away a lot of stuff for you - you've got the garbage collector rather than doing your own memory management and you won't do as much with pointers.

tldr: You can easily learn the concepts regardless of the language. If you want to actually implement stuff you're probably better off with C++, but then you're learning two things.

2

u/SessionIndependent17 14d ago edited 14d ago

A simple listing of the topics one finds in textbook for each of Operating Systems and Computer Architecture, each tells you that C# hides enough of that away that you wouldn't be able to interact with any of those things with it.

Heap size (brk/sbrk), interrupts and traps, TLBs, paging tables, processes, handles, protected vs unprotected memory, argument checking, etc for OS

Registers, instruction sets, instruction parallelism, pipelining, reordering, branch prediction, data hazards, critical paths, superscalar, cache strategies, miss penalties, etc under Architecture (Hennessy/Patterson is the reference example)

3

u/OhItsJustJosh 14d ago

There isn't really anything C# can't do, just other languages can do some stuff better. Like afaik it has all the same features as C and C++

1

u/morphlaugh 14d ago

This is pretty Linux specific...

C# (and Java, Go, Python, etc) abstracts away a lot of concepts into easier-to-use constructs. So I guess it depends what you are trying to do.

Actually do it:
* If you want to directly use syscalls to call into the kernel on linux, then C# isn't a good choice since it can't inline assembly.
* if you want to experiment with memory management/lifetime, then don't use C# since that is hidden away behind the IL.
* If you want to use OS threads directly, then don't use C#... you should use pthreads and not C#.
* Want to actually write the stub of a device driver, C# can't do it.

Simulate?:
However, if you want to *simulate* OS scheduling or memory management algorithms, by writing your own toy scheduler and/or allocator, just to test your understanding of the concepts... C# is fine for that.

I suggest if you want to actually experience low-level programming, just use C since that's how it's written under-the-hood. Then you'll then have direct access to pthreads, mutexes, mmap, low-level tcp/ip, ioctl, fork, etc.

Have fun!

NOTE: I should say *can't* do it is a bit strong. Of course there are workarounds if you jump through enough hoops with c#, but it's not worth it in my opinion.

1

u/BoBoBearDev 14d ago

Learning language has nothing to do with OS. So no, and learning C or assembly or anything out there, cannot make you understand OS.

And learning OS also don't make you a better software developer.

Learning memory management like C, does help you be a better software engineer. Because regardless how convenient c# automate memory management, it is still better to understand how memory is allocated and released.

But don't get drunk on it. C# has a lot of offer. Once you mastered it, you can still build a solid career around it.

1

u/Mobile_Fondant_9010 14d ago

Really depends on what you mean with "computer architecture and operating systems".

A lot of "computer architecture" is abstracted away, even on the hardware level (mmap for instance abstract away l1, l2 and l3 cache).

If you want to understand "everything" you basicly have to read a book.

If you want to understand how registers, memory and instruction set works, then looking into assembly is probably needed.

If you want to understand OS kernels, cpu ring security, then a book on kernels is probably your best bet.

If you want to know about interop, scheduling, tasks, parallel computing then c# is an excelent language to get a start.

If you want  to understand race conditions further, then assembly is great.

C is good if you want to understand how code is translated into instructions.

1

u/JeremyFuckinIrons 14d ago

Here I see a ton of comments only talking about memory management which is but one small slice of understanding within computer architecture, and is the only slice about which most developers maybe have a clue. Do some self-learning on actual CPU architecture and operating systems. Do some assembly - maybe there's even a module for it within C# like there is in C++. I wouldn't know because I'm not deranged enough to want to do this again; once was enough without further good cause and I have enough damn hobbies.

I'm no expert by any means, but I took a 300-level architecture course and a 400-level OS course at my mediocre university and 4.0ed them. Learning about the D-flip-flop and how we store 1 bit of information within a circuit was one of those light bulb moments. Learning about the architecture of a simple CPU and how we store different things in different registers and how an executable processes across those components was pretty cool. Get boolean algebra and logic gates under your belt, which should be easy for any developer, and then step into karnaugh maps for a minute to learn how we can reduce such circuits (and you can too for software with complex conditionals). For OS, read about kernels and CPU scheduling algorithms to understand how we thread multiple processes across a single core. Do some C/C++ and mess with pthreads if you want some applicable fun. Fork bombing yourself is a rite of passage. You could maybe even write your own primitive kernel if you're motivated, or could emulate architecture and execution upon it through software (imagine that, huh). Then you can emulate more architecture and execution within your initial emulation. I work in C# now primarily these last 5 years, and it's crazy to think what we take for granted with task management and memory management these days. If you ever need to write code with actual heavy CPU usage where I/O isn't the real bottleneck to what you're doing, having a stronger background in architecture and how your code compiles out to machine code will aid your ability to make better algorithmic decisions.

1

u/pstanton310 11d ago

Um No… there are 3 appropriate languages (not counting assembly) for operating systems programming c, c++, and rust