r/learnprogramming • • 5h ago

Topic C# or Java?

If you had to choose one class between the two, which would you select and why? I tried to Google the purpose of them; the immediate answers from Google felt very vague and like both of the languages are common. Is one course better for web development as opposed to apps or something? Looking at the courses I'm taking, down the line I will select one of the two. The only thing I know so far is C++, so I'm quite new.

Also, side question: why are there so many languages? The only logical thing I can imagine is there were problems that couldn't be solved with say for example C++ so someone created something new. But why not just build on the original language? Why did they need to reinvent the wheel? Or is it as simple as that: someone wanted to create their own thing?

1 Upvotes

30 comments sorted by

View all comments

3

u/a3th3rus 4h ago

It depends on your programming skills and what you want to build.

For me, as a language, Java has less features than C#, so it's easier to learn, but if you are a polyglot and have a decent amount of experiences, then you may find that Java sometimes lacks one feature or two you want. Java also has a bigger market than C#, unless you are going to develop video games.

Why are there so many languages? Because all languages are somewhat opinionated, and they are trying to solve different common problems but are willing to sacrifice performances in solving other common problems, like C/C++ focusing on raw speed, Java initially aiming for cross-platform execution, Ruby aiming for developers' happiness (though it fails to deliver that for large projects), and Rust for memory safety while keeping raw speed, Erlang for self healing and horizontal scaling, so on and so forth. Theoretically, C/C++ can solve all problems that can be solved with programming, but to solve some problems you need to write hundreds of thousands of lines of code in C/C++ but you don't even bother to think about it in Erlang.

2

u/Mughi1138 4h ago

Oh, and you forgot Go (aka GoLang), which was created so that Google could hand it to brand new college grads and it would keep them from shooting themselves in the foot or in having to need too much experience to be productive. Also so that it could be compiled to native instructions to execute on farms of many different architectures but with each being more of a monolithic block of target requirements on fairly new hardware.

1

u/Vafireems 4h ago

I guess it doesn’t make sense to me why one language would be better at doing something than another. Maybe that’s because I haven’t seen other languages written out.

Are the commands more complicated or something? Is command the correct terminology for things such as cout/cin, for, else, if, etc. we were never told if these statements had a name but calling then commands makes sense to me.

4

u/romecodes 4h ago

Each language is comprised of 3 main categories: Tokens, Expressions, and Statements. cout/cin are actually function/method calls, which are considered expressions. Loops like "for" and "while" are considered iteration/loop statements. You can think of tokens as the smaller units that produce statements or expressions. The assignment operator "=" for example is a token. The name of a variable is a token. A primitive data-type like the integer 4 is a token.

But none of the syntax or semantics suggests a clear difference. For devs, what matters is the trade-off between ease-of-use and performance. We measure so many different things: readability, portability, security, modularity, etc..

But each language has it's own ranking in each. Some languages are slower in execution, some languages are better suited for web, some languages too touchy about typing. The preference comes from gaining enough experience with them to know how to approach each of them and whether it's worth the trade-off to use in a particular case.

2

u/a3th3rus 3h ago edited 2h ago

Maybe it's time to just pick a language and learn it until you can build something useful (does not have to be big or perfect) with it, then pick another language as different as possible from your first language.

I first learned Java, then vanilla JavaScript, then Ruby, then some PHP, then Elixir, then Haskell, then Rust, then Zig. Some languages I didn't learn but somehow I can use are C#, Python, and Golang.

1

u/romecodes 3h ago

That's actually a good point. In university, we had to take a Principles of Programming Languages course, where we were introduced to some of the x86 instruction set, boolean arithmetic, an overview of compilation, programming language paradigms at high-level, and then learn C++, Prolog, Schema, and Python (for those who didn't already know it). But it reinforced the more extreme differences.

1

u/SmoothScenario 2h ago

Java's the safer bet if you're coming from C++ and just want a job, the syntax will feel familiar enough and the demand is massive in enterprise. C# is great too but it's more tied to the Microsoft ecosystem and game dev with Unity, so if neither of those are your jam Java opens more doors

the language thing always tripped me up early on too, it's basically like why we have different types of saws when a hacksaw can technically cut anything. sure you could cut a 2x4 with a hacksaw but a circular saw makes it trivial, same idea with languages being specialized for certain problems. what annoyed me was learning that some languages exist just because a big company wanted control over their stack, looking at you Google with Go

if you're already doing C++ I'd lean Java, you'll pick up the OOP concepts fast and the JVM ecosystem is ridiculous for backend web stuff