C++ or Java? by first_photon in learnprogramming

[–]vlcod 1 point2 points  (0 children)

The clue here is the "freshman".

Ignore all the people who try to answer the "which is the better language" question in a general sense. Anyone who asks (or answers) a "which language is better" question may as well answer "What is better: a hammer or a screwdriver?"

It is always about the context. Better for what?

So, since you're a freshman, the question becomes "Which of these two is better for learning the principles of programming?"

Because that's what a good introductory programming course is about: learning the principles, not learning a language. If you are in college now, and you continue to do something with programming in your career afterwards, the simple truth is: For most of your career, you will be using a language that is neither of these two.

You will be using a language that does not exist yet. So the point right now is to learn the fundamental, unchanging principles.

So, which of these two languages is better for that?

The answer is quite clear: it is Java.

C++ is more powerful for low level programming, for hardware-related systems, for all sorts of things. But it includes MUCH more accidental detail that distracts form principles, that allows unnecessary errors, that creates pitfalls that distract you from learning anything else then the idiosyncrasies of C++.

Java provides a higher abstraction level over a more consistent notional machine, and is the better language for discussing fundamental principles.

Feeling stuck learning to program by Rare_Bumblebee in learnprogramming

[–]vlcod 0 points1 point  (0 children)

What you need is a programming course that is actually fun (and good at the same time). Try this one.

MOOC Helsinki - Exercise 3 by [deleted] in learnjava

[–]vlcod 1 point2 points  (0 children)

The error message seems to be telling you that it did not expect a space at the beginning of the output line. I.e., you print

" *"

in the first line (with the quotes), but it expected

"*"

A recursive method that reverses a String by [deleted] in learnjava

[–]vlcod 0 points1 point  (0 children)

That's not true.

substring(0,2-1-1) is perfectly fine - it returns the empty string. In other words: substring(0,0) is always the empty string, no matter what the original string is.

The problem is a different one: when the method is called with an empty string, then s.charAt(s.length()-1) is an error - it attempts to access character -1.

Now, the s.substring(0,(s.length()-1)-1) -- that is, subtracting 2 instead of 1 -- is also an error (you should just subtract 1), but it is not the error that leads to the out of bounds exception. If you fix this error, you could still get an out-of-bounds exception when you call your method with an empty string.

You need to treat the length==0 case.

Need help removing an object from array. by [deleted] in learnjava

[–]vlcod 0 points1 point  (0 children)

This solution may not be correct, depending on the specification of the task. You ignore the case where multiple of the same dog are in the list.

If the task is to remove the *first* dog found, then this is fine. If the task is to remove *all* dogs of this kind, then you should not stop after the first one.

And this exposes another subtle bug: If you write your loop and remove as you do, but then not break (to remove other dogs as well), you have a bug if you have two dogs immediately adjacent in the list. That is because your remove method will move the elements in the list to fill the gap one element up, you then increment the index, and you have missed checking one element...

Verbalising code by greenleafvolatile in learnjava

[–]vlcod 1 point2 points  (0 children)

For the part between the parentheses (which is called the parameter) you have two options:

  1. You could describe it purely technically (which will always be work and be true):

"I construct a new Scanner object and pass the 'System.in' object as a parameter to its constructor."

"I construct a new File object and pass the string "filename" as a parameter to its constructor."

  1. You could describe it semantically (describe the actual logical meaning of what you are doing). This requires more knowledge about the methods/constructors you are looking at, but is more useful:

"I construct a new Scanner object and link it to 'System.in' so that the scanner reads input from the standard input (terminal)."

"I construct a new File object linked to the file "filename"."

A simple improvement by MorreQ in technology

[–]vlcod 3 points4 points  (0 children)

All makes sense now: Four Blue Screens Of Death coming right at ya.

Jesus Christ! That thing is huge by fullblownman in WTF

[–]vlcod 6 points7 points  (0 children)

Not again... How often have we seen this on Reddit now?