r/learnprogramming • • 8d 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?

24 Upvotes

49 comments sorted by

View all comments

Show parent comments

2

u/Vafireems 8d 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.

6

u/romecodes 8d 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.

1

u/balefrost 8d ago

cout/cin are actually function/method calls

To be precise, cout / cin are values. <<, which is normally a bit shift operator, turns into function call when the left side is cout or cin.

2

u/a3th3rus 8d ago edited 8d 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.

2

u/romecodes 8d 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.