Why is Java so circuitous and tortuous compared to C/C++?

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 2627 Views - Last Post: 14 September 2014 - 09:35 PM Rate Topic: -----

#1 needycoder   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-November 13

Why is Java so circuitous and tortuous compared to C/C++?

Posted 24 August 2014 - 06:47 PM

Why is Java so circuitous and tortuous compared to C/C++?

Why everything has to be done in a round about way in Java? Instead of simple
scanf();
or
cin;
as in C and C++, you have to write

Scanner something = new Scanner(System.in); 


This is so irritating, couldn't they have made it as straight forward as it is in C/C++? Presently I'm fighting a strong urge to curse the creators of Java. Why the hell do array have to declared in such stupid in Java? I'm learning Java to write for mobile and it is so irritating. There are good things too, like Strings.

I'm presently working on a Vowel counting program and I'm finding it so hard.

It seems as if Java creators out of spite have imposed those syntax just to be different than C/C++.

Is This A Good Question/Topic? 0
  • +

Replies To: Why is Java so circuitous and tortuous compared to C/C++?

#2 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12305
  • View blog
  • Posts: 45,401
  • Joined: 27-December 08

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 24 August 2014 - 06:58 PM

Is there a question here, or an actual point for discussion?

Quote

Why the hell do array have to declared in such stupid in Java?

Everything in Java is an object. I don't see what is "stupid" about how arrays are declared.

File I/O isn't one of Java's better points, admittedly. However, some of this goes back to the OO design.

I don't see anything you've brought up worth cursing Java over. It sounds to me like you just don't like learning a new language. Languages will have features you like and don't like. Welcome to programming.
Was This Post Helpful? 3
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14045
  • View blog
  • Posts: 56,203
  • Joined: 12-June 08

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 24 August 2014 - 07:18 PM

Agreed.. languages are tools, and each one is a little bit different (else they would be all the same!) because they have different areas they shine. There's nothing to get too worked up over..

On the other hand - your functional languages can be cursed freely. ;)

Spoiler

Was This Post Helpful? 1
  • +
  • -

#4 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11041
  • View blog
  • Posts: 18,857
  • Joined: 19-March 11

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 24 August 2014 - 07:25 PM

A large part of the motivation, I think, is a desire to make a language that's suitable for writing large and complex programs in large teams that are distributed across space and time. What does this mean? Well, for one thing it means that any line of code is going to be written once, and understood many times. It also means that the person who wrote the code is not necessarily going to be there to explain it, so it should document itself as much as possible. It should also be able to do type checking, so errors can be detected early. And there was a desire to make the language more nearly object-oriented. These concerns more or less explain the issues you're pointing to.

I think the structure of java is more easily understood if we assume that the language design privileges maintainers over original writers, and that it is a generally conservative language - meaning, a language more concerned with detecting and preventing ordinary mistakes than enabling mad geniuses. These both make sense to me. As I say, code will be written once and maintained forever, so it does not make sense to come up with a write-only language design like perl - the language should facilitate comprehensibility. And obviously, in any organization that has sensible hiring policies, there will be relatively few geniuses, and geniuses are not known for working together well in any case, so designing to support the lone genius instead of the workaday programmer would be the wrong choice.

It's also worth remembering that the primary goal of Java was to avoid the perceived mistakes of C++. So rather than cursing the designers of Java, you might want to take another look at C++ and see why those decisions seemed like improvements to them. Even if you end up still hating Java, that would probably be a good way to learn a few things about language design.
Was This Post Helpful? 4
  • +
  • -

#5 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3541
  • View blog
  • Posts: 16,143
  • Joined: 20-September 08

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 25 August 2014 - 12:39 AM

Quote

Why the hell do array have to declared in such stupid in Java?

Not sure what you're referring to there either... You do know you can do the following ..?

int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };


Was This Post Helpful? 1
  • +
  • -

#6 needycoder   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-November 13

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 25 August 2014 - 02:25 AM

View Postmacosxnerd101, on 25 August 2014 - 07:28 AM, said:

Is there a question here, or an actual point for discussion?

I don't see anything you've brought up worth cursing Java over. It sounds to me like you just don't like learning a new language. Languages will have features you like and don't like. Welcome to programming.


Sorry it was more of a rant. Thanks for welcome.

View Postg00se, on 25 August 2014 - 01:09 PM, said:

Quote

Why the hell do array have to declared in such stupid in Java?

Not sure what you're referring to there either... You do know you can do the following ..?

int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };



Thanks for telling me that array can be declared like that, the Java textbooks I'm reading haven't mentioned this way of declaring the array. Having learnt C before, declaring arrays like this:

char[] something = new char{...};


seem tortuous to me. What you mentioned seems more natural, does it feel the same way to you?
Was This Post Helpful? 0
  • +
  • -

#7 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3541
  • View blog
  • Posts: 16,143
  • Joined: 20-September 08

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 25 August 2014 - 03:18 AM

Quote

does it feel the same way to you?


It certainly is more convenient sometimes. You need to know that if you do

MyObject[] foo = new MyObject[2];


You will get an array of null filled with nulls as there is no implicit ctor in Java. i.e. declaring

MyObject bar;


Will give you a null reference

This post has been edited by g00se: 25 August 2014 - 03:20 AM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#8 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7164
  • View blog
  • Posts: 14,932
  • Joined: 16-October 07

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 25 August 2014 - 04:52 AM

cin is an interesting example. First, it's only partial: you want std::cin. If you go down the rabbit hole of what drives that, it's a huge, messy, tangle of fake_istream and aliases, and so on. To get that "simple" cin to work, every type must be aware of istream and write an operator override to accommodate it. Note, that cin is an instance of istream that points to stdin...

Back to Java. Java disallows multiple inheritance and forces class based implementation. So, for an instance that talks to stdin, or System.in, you logically must create that instance. Note, Scanner is just to darling of the moment; older java programs preferred other wrappers for their System.in.

So, you have a program and you chuck in a line like:
private final Scanner kbIn = new Scanner(System.in); 



And use that consistently in the instance. This approach is consistent with how everything else in java works. It doesn't seem to be a huge hardship to do.

I'd love to see a realistic program in both C++ and Java where you feel Java is more "circuitous and tortuous" than C++. Simply stating it doesn't prove the assertion.
Was This Post Helpful? 1
  • +
  • -

#9 needycoder   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-November 13

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 25 August 2014 - 07:52 AM

With cin; for simple things you could just use like this:

cin>>i;


It's not so straight forward or convenient in Java.
Was This Post Helpful? 0
  • +
  • -

#10 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11041
  • View blog
  • Posts: 18,857
  • Joined: 19-March 11

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 25 August 2014 - 08:05 AM

View Postbaavgai, on 25 August 2014 - 06:52 AM, said:

I'd love to see a realistic program in both C++ and Java where you feel Java is more "circuitous and tortuous" than C++. Simply stating it doesn't prove the assertion.



I think this is an important point. The inconveniences of Java tend to amortize out as the code increases in complexity. For example, if you're writing a real program you're probably not going to want to just take raw input from the console. And if you do write an application that works purely from the command line, and it's any use at all, someone will surely want to make a GUI version, or possibly an android version. What this means is that your raw console input is going to be part of a larger structure that handles input - and you're probably going to be doing something like "getInput(prompt)" or something of that sort. The implementation of getInput might use a Scanner on System.in, or it might use some other mode, but you're not going to care in your larger purpose - and you shouldn't care about that.

If you're thinking about the larger logic of the program - "I get the input, I look up the appropriate user data, I do some processing, I do a little shake and a little shimmy, and I produce some output" - you should not be thinking about the details of how input is coming in from the user. That's one of the real advantages of OO programming - it lets you take a "let George do it" approach. You should try to adopt this style of programming and then see if Java seems too complex to you.


I do agree that Java is not and will never be a convenient scripting language. If you just want to open a file, grab some data by some rule, and get on with your day, then you want a language like Python. But that's not really what Java's for.
Was This Post Helpful? 3
  • +
  • -

#11 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7164
  • View blog
  • Posts: 14,932
  • Joined: 16-October 07

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 25 August 2014 - 08:35 AM

View Postneedycoder, on 25 August 2014 - 10:52 AM, said:

cin>>i;


It's not so straight forward or convenient in Java.


What is i? I can't tell from your snippet. That's not terribly straight forward. Do you know the code that's actually being called with that statement? It's probably more circuitous than you know.

int i = input.nextInt();



Here, I understand I'm calling a method that belongs to input and returns int. Again, not particularly torturous, but potentially clearer.

If you want a terse language, try Haskell; Java will generally fail you on the brevity of statement front. It's worth noting that anything serious in C++ will also get rather verbose. The ubiquitous cin is a cherry picked example. Try iterating over a vector prior to C++x.
Was This Post Helpful? 2
  • +
  • -

#12 mike73   User is offline

  • D.I.C Addict
  • member icon

Reputation: 250
  • View blog
  • Posts: 918
  • Joined: 24-April 10

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 25 August 2014 - 11:06 AM

I remember in college when class was over, and we were leaving our Java lecture and the Game Design course were coming in to do whatever, the abuse we got was ridiculous: "retarded persons c/c++" "learn a proper language" "sloowwwwww"... I never understood it. It only stopped when the lecturer asked them to show us one of their projects that couldn't be done in Java, and of course there were no takers
Was This Post Helpful? 2
  • +
  • -

#13 farrell2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 28 August 2014 - 09:39 AM

C++ is a complete mess for most problems. I don't understand why anyone who doesn't actually have to use it, would. Java is the perfect solution to most problems, including IO with NIO.2.

This post has been edited by farrell2k: 28 August 2014 - 09:41 AM

Was This Post Helpful? 0
  • +
  • -

#14 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1460
  • View blog
  • Posts: 4,726
  • Joined: 20-March 10

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 29 August 2014 - 05:45 AM

Well,

for embedded solutions C++ is short and to the point.

Also it is a faster general purpose language than Java but as computers, phones and tablets increase in speed this is becoming less important than it used to be.

Java with all it's flavours like Android is certainly a language that will become more important as processor speeds increase and speed of the JVM increases with it.

Java is indeed a great language for all sorts of stuff.

C++ is also a great language for all sorts of stuff too but you have to get into the fine details of how your machine actually works to get the full benefit of it.

If I was teaching either Java or C++ I would say the more tortuous route would be C++.
Was This Post Helpful? 0
  • +
  • -

#15 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3541
  • View blog
  • Posts: 16,143
  • Joined: 20-September 08

Re: Why is Java so circuitous and tortuous compared to C/C++?

Posted 29 August 2014 - 06:11 AM

Quote

for embedded solutions C++ is short and to the point.

To oversimplify, the chief benefit of C++ over C is that it adds object orientation. That's seldom apt in embedded contexts, so C/Assembler will normally be used there
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2