B
B
beginer1232017-10-04 14:11:00
Programming
beginer123, 2017-10-04 14:11:00

How to understand what things in the Naldo program should be universalized?

What I mean?
For clarity:
let's say we need to get the price of an apartment
It seems that we just store the price and display it
BUT
- what if we need to display it per square meter?
-what if it will be necessary to display in different currencies? (then it is necessary to redo the database for different currencies)
-what if there are possible discounts and it will be necessary to display the full and incomplete price
This is just an example, the question is not about him, but about the situation in general
How understand which parts of the code should be made universal and which ones should be hardcoded?
Despite the fact that the client does not know, let's say he will have other currencies, etc.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
X
xmoonlight, 2017-10-04
@xmoonlight

1. The total value (the value formed by the formula from the final / single ones) is maximally divided into single components of the variable / dependent parameters and for all parameters we create columns in the database (what makes up the cost and how much one part costs) and check the correctness and completeness of its content at the customer.
2. If there can be several parameters, we create a separate table with ID-shniks for several parameters and enter their values ​​there (for example, exchange rates, quality gradations of something, different colors, etc.).

E
Eugene Wolf, 2017-10-04
@Wolfnsex

I gave this just an example, the question is not about him, but about the situation in general
. How to understand which parts of the code should be made universal and which should be hard to prescribe?
If this is not a social network, where traffic is calculated in petabytes, and the load on the database is thousands of requests per second, then the most rational solution in such matters, in my opinion, was found long ago and is called OOP , incl. for data processing, in many systems (for example, frameworks) there is such an entity as an object (or "model" if you like), in which you can easily add a new property that is calculated dynamically. This works great in most cases.
Another example of solving such "problems" is at the database level (I suspect that we are not talking about storing data in text files?), for example, in the same MySQL (painfully familiar to everyone) there is a "virtual columns" mechanism, which solves the problem with currencies (if desired) and with the price per sq.m. etc. An even simpler option, which probably exists in all RDBMSs, is to use VIEWS, supplementing it with new values ​​as needed, another option is to create an INSERT / UPDATE trigger and add a new column, the value of which will be calculated automatically.
Well, etc., there are a lot of examples, but, as the previous speaker correctly noted, it all depends on the specific case and the universal tool for solving such problems or for carrying out construction work (as an example) has not yet been invented. Some tasks are better solved with a "hammer", some with a "drill" ...

A
Andrey Romanov, 2017-10-10
@andrew-r


How to understand which parts of the code should be made universal and which should be hardcoded?
If you are just starting to make a project and there is some degree of uncertainty, do not chase universality. It is better to “hard-code” the rules and even duplicate the code in some places than prematurely make a universal solution that will turn out to be inappropriate in the future. When the project lives for some time and the requirements more or less settle down, you will understand which parts of the project can be made universal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question