IS "wrong" use any type of output that demonstrates what you have on your system, such as a printStackTrace
for example. Because, besides the screen getting messy, ugly and the user does not understand anything, someone more knowledgeable can see the names of classes, methods, and depending on the case up version and type of server you are using, which is a security flaw.
System.out
is not recommended because it will be printed on standard output application, and this output is often disregarded or even disabled. If you make a java -jar app.jar &
or run the application as serviço
, that exit will no longer exist.
If you are making a WEB application, or something complex, the ideal is to log with the error and alert the user with some message handled, and if possible a code, type a javascript Alert same.
For a method main
basic, System.out is OK, as long as the messages are handled and you don’t leave a stackTrace
pass by.
A better approach would be to use LOGS, such as log4j for example, and use functions such as log.error("Mensagem", Exception)
or log.warn()
or log.info()
, etç, depending on what you want to log in.
It’s not wrong, but showing off somehow might be. This case of yours is pretty shallow to suggest what is "correct", but if you look at the current televisions, they show a volume indicator when Oce increases or reduces, some simply show the empty bar when no volume or the full bar when it is loud. No textual message was necessary.
– user28595
What I mean is that not every kind of message needs to be a text or an alert. Sometimes signs or figures work better.
– user28595
I think a better idea is to say which methods should restrict to the minimum messages to the user, only what is necessary. To say that is wrong... is wrong. Nothing is absolute.
– StatelessDev
In my example I quoted, instead of showing something to the user I could do this,setVolume(10) ,10 in case as was the maximum volume ?
– rafael marques
Instead of you telling the user that it has increased more than allowed, why not simply set a maximum volume value and once that value is reached, just don’t increase the volume anymore? That’s what happens in real life with Tvs, right?
– StatelessDev
Thinking specifically of Tvs, I think most simply do nothing when it reaches maximum volume. You could then do
if (this.getVolume() < 10) { aumenta }
- when the volume is >= 10, it does nothing. But it all depends on what is defined, will some product manager want to be shown some message, I don’t know– hkotsubo
Got it, Thanks for the answers.
– rafael marques
Without knowing the context of the statement, what we can do is speculate. I, for example, believe that the error lies in the fact of method to do more than one thing than your name indicates. I would expect a method called
aumentar
only increased the sound. Maybe at most return a value or cast an exception indicating that the operation failed. From then on, if visual feedback is required, it is no longer the responsibility of this method.– Leonardo Lima