All Questions
Tagged with programming-practices clean-code
31 questions
-3
votes
2
answers
699
views
Is throwing an error in programming is good Idea at all? [duplicate]
I am wondering if throwing an error in programming is good Idea at all ?
While programming we throw error when something unexpected or invalid has occurred. But if we have thrown exception and it is ...
9
votes
2
answers
1k
views
Should function names describe their parameter types?
If you wish to perform the same action using different parameters, you can either make differently named functions:
public Apple findAppleById(long id){
return repo.findById(id);
}
public Apple ...
1
vote
1
answer
139
views
What is the best approach to use a common variable in multiple method in a request in laravel [closed]
I have a $c variable that is calculated at the beginning of the request. After calculating this several nested methods use it as a part of their job. Is it better that I pass down the $c variable to ...
20
votes
8
answers
22k
views
Is an empty 'while' loop bad practice?
Consider the following:
public boolean maybeUpdateTime() {
if (this.timeReference.isAfter(lastInterval.getBeginning()) {
this.timeReference = lastInterval.getEnd();
lastInterval = ...
-1
votes
1
answer
195
views
Angular: send form or object?
My question is about clean code or best practice. I have a big formGroup and in my opinion its more difficult to map the form to an object than to send the form to the backend.
best regards
1
vote
1
answer
206
views
counting identifiers and operators as code size metric
I'm looking for a code metric for monitor and track over time the size of several projects and their components.
Also, I would like to use it for:
evaluate size reduction after refactoring
compare ...
0
votes
1
answer
166
views
Visibility of constants
Should constants of my class only be public if I know that they will be used from their users or doesn't it hurt to make all of my constants public per se?
Is not exposing all constants cleaner?
12
votes
6
answers
4k
views
Passing Objects vs. Primitives
What is the best practice when it comes to passing variables around? Is it better to pass objects (models) or is it better to pass primitives that will be required by the called method? What are the ...
138
votes
17
answers
15k
views
How do I know how reusable my methods should be? [closed]
I am minding my own business at home and my wife comes to me and says
Honey.. Can you print all the Day Light Savings around the world for 2018 in the console? I need to check something.
And I am ...
0
votes
3
answers
541
views
Bug-preventing vs clean code
If I'm faced with the decision to write clean, beautiful code, but I'd be opening up a new path bugs could take to appear, should I take it? (Provided I'm not willing to spend the time to come up with ...
0
votes
4
answers
460
views
Best practice to populate a `container` class
lets say I have several objects Object A,Object B,Object C in different parts of my project. I have defined a Object X that is only used to store some specific values from the objects mentioned above ...
4
votes
6
answers
1k
views
How to deal with Law of Demeter in the product - owner relationship?
I want to display the product, and the product card has a lot of information about the product and the owner. How to deal with Law of Demeter in this product - owner relationship?
In controller I ...
8
votes
6
answers
5k
views
What is more important? SOLID or KISS?
What is more important? SOLID or KISS?
To be consistent with SOLID I would have to inject Decorator and Footer classes and create interfaces for them.
public class HelloService {
String name;
...
7
votes
5
answers
8k
views
What to do with long variable names?
First example:
countryRepository.getCountriesFromAsiaWhereAreTheMostPlanesAndBoats();
countryRepository.getCountriesFromAfricaWhereAreTheMostCars();
Are these names too big? How else do we call these ...
-3
votes
3
answers
491
views
Writing quality code [closed]
I know there are many books on writing clean, modular, readable and whatever else you can say but frankly speaking I find it very hard to remember every advice given on those books. Frankly speaking ...