Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
How important is it to use labels in Java? I haven't seen labels used, except in academic books.
I saw them used with jump statements such as break and continue.
You can use labels, but they are considered bad form in general, sort of unrestrained jumping within a method, it makes the code harder to maintain and can introduce bugs if not handled carefully.
As a rule with OO there is usually an easier/better way to achieve things.
In too many years of coding Java I have never used a label.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am very new to Java so excuse me if this sounds like a dumb question.
Why is such a big effort made when following the state-design-pattern (creating an interface, context and concrete sub-classes for each state) when you could just save the state of a given object in a variable and then make decisions based on switch and if-else statements later on?
if-else and switch statements encourage brittle code and responsibilities mixing.
Every time you add/remove/update a state, the same class and method has to be changed or a sub method invoked, so you increase the odds of introducing regressions in any state logic, whereas you would change one of them instead.
By separating the concerns, the states are not coupled; you could easily modify them without risking changes to any others. You could even validate this with unit tests.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm building a MicroSerive and I was planning to publish services using this URI naming convention:
https://host:port/api/v1/service1
https://host:port/api/v1/service2
https://host:port/api/v2/service1
https://host:port/api/v2/service2
But I've also seen URIs named like this (ie vx and api 'swapped'):
https://host:port/v1/api/service1
https://host:port/v1/api/service2
https://host:port/v2/api/service1
https://host:port/v2/api/service2
In my opinion, the first approach is better. Are there any reasons to go for the second approach?
Technically it doesn't matter
But within an overall REST approach the URL should be easily readable and comprehensible by a humain.
using your first approach is the correct form as it's easily readable as
The Api of Version 1 that exposes ...
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Most contests have a limit on time and memory taken by the processor to compute the answer, and if the code is written in Java, which runs on a virtual machine, there would be an overhead and requires more time for the program to compute compared to many other ones. Many contests also base the ranking of contestants based on the time taken for the program to run.
So I like to know about the evaluation based on the choice of programming language used to submit the solutions.
Thank you.
As with everything, it depends. Are you doing something that requires high performance? Is it scored by time/memory efficiency, or does it just require that you don't go over the limits?
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
As in the topic name, I wonder what is the best convention
The answer to this question is essentially another question: what makes your code easier to read and maintain?
Martin Fowler, a well-known author and programming guru, suggests a refactoring called Replace Nested Conditional with Guard Clauses.
I am definitely more of the mind to use guard clauses because they usually make the code cleaner and easier to read. However, once in a while there is a scenario where the intent of the code comes through clearer without them.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Why doesn't Java support multi-line strings? I know they dont, but I dont know why. Is there a good reason? Several other languages have this capability, even older ones, so why doesnt Java? As far as I know (not very far) it shouldnt be too had to add this functionality to your lexers/compilers.
Edit: For clarification, I dont mean a string with a newline character in it. I mean something like this:
String s = "Hello
World";
Edit2: I dont know why people thought I was asking for opinions, I most certainly am not. I specifically asked for good reasons. I suppose I need to explicitly say based on facts as well?