Another Gotcha in the code window OOP dog class


public void bark() {


the interpreter will only accept bark() no spaces. Ridiculous !

And Again

public void bark() {


That's going to be something you'll have to learn to live with.

Strings are a pain in the ■■■. In every language I've learned so far (Java, C++, JavaScript, VBA,...), it's always the same thing. Programming languages are extremely intolerant regarding Strings. That's just the way it is.

Golden tip if I may.
If you ask the user for a String-input and you're expecting a certain answer (e.g. "yes").
Always use the Trim and toLowerCase methods before evaluating. User input sucks to work with.


Yeah, @betarockstar54455 is right about dealing with user input from the console. It's good policy to try to catch variations on expected answers. For instance, if the user is expected to enter either a string, "no" or "yes", then your code should try to process such strings as "no", "NO", "nope", or "nosirree!" all as equivalent to "no". For that particular situation, you could first trim the string that the user entered to chop off whitespace at either end, then truncate what remains down to one character, set it to lowercase, and finally test for "y" or "n".


I wasn't talking about strings. It's about the use or lack of whitespace between code. The parser is very inconsistent and seems to have been written without consideration for dropping all whitespace when present. I use whitespace in code lines to improve readability


But what made you think it was strings that I had a problem with ? And why are programming languages intolerant of strings ? There is very well defined code to deal with strings, especially with object oriented code. My first language was C and believe it or not, you had to create most of the code yourself, unlike today where everything is handed to you on a plate. And you have intelligent IDEs to do the hard yards for you. Not so years ago, you had to use your brain.


I know, I've been there with C too. Controlling microcontrollers.

Indeed, there are a lot of IDE's out there, and certainly they help a lot. But teaching coding (in my opinion) should still happen in a low-help environment. (Does that make sense?) That way, you have to search for your own mistakes, losing time and realizing that next time, you're not going to make the same mistake again. (or you won't have to search so long anymore).

Forgive me if I'm wrong, but I still think that coding languages are very intolerant towards Strings. Probably because it's raw input. But that's probably just an opinion.

The reason I thought that Strings were the problem, is because you have to print out a String to the console.
So, the interpreter could easily find a mishap there because you put a whitespace too much. (Which was also a part of your question, the whitespace). Now I think I understand what you mean, you probably meant the whitespace after the word bark().
Well, there I can follow you. I learned to block my code. Like this:

public void bark()
    System.out. .......

I didn't really pay attention if the interpreter goes with this or not... :confused:

So, no hard feelings :wink: Just here to help, like everyone else.


Can you elaborate on why You think compilers are intolerant of strings ? Is it for the same reasons that
geomaticmashups explained ?
I'm comfortable with using strings and String classes so that's why I don't have a problem obviously.

I found this too with some parts of the Java course. I think the Python course is much better done and handles input errors more professionally