How to understand what things in the program Naldo to universalize?

What do I mean?
For neglagence:
suppose you need to obtain the price of the apartment
Just like all the stored price and output
BUT
what if we need to withdraw per square meter?
-that if need be, withdraw in different currencies?(then you have to redo the database under different currency)
-what if may be discounts and it will be necessary to ivodit complete and incomplete price
I gave just an example, the question is not about him but about the situation at all
How to understand which parts of the code to do universal and which are hard to prescribe?
Despite the fact that the client does not know let's say he's going to have other currencies, etc
June 14th 19 at 20:15
5 answers
June 14th 19 at 20:17
what if we need to withdraw per square meter?

price / area

that if need be, withdraw in different currencies?

convertCurrency(price, 'RUB', 'USD')

if perhaps there are discounts and will have to ivodit complete and incomplete price

price * (1 - discount)

None of this requires a radical alteration of the system. But in any case more specifically, it is possible to discuss the issue, only when there is a specific task.
You read the question? it was just an example, the question posted in General - Roscoe commented on June 14th 19 at 20:20
I gave just an example, the question is not about him but about the situation at all
How to understand which parts of the code to do universal and which are hard to prescribe?
Despite the fact that the client does not know let's say he's going to have other currencies, etc - Roscoe commented on June 14th 19 at 20:23
June 14th 19 at 20:19
1. The cumulative value (the value produced by the formula of the end/single) maximum crushed to the individual components of the variable/dependent options and for all options, create columns in the database (what is the cost and how much is one part) and check the correctness and completeness of its content at the customer.
2. If the parameters can be different - create a separate table with ID-shnik for several parameters and there is a recorded value (for example, exchange rates, rates of quality something, different colors, etc.).
June 14th 19 at 20:21
I gave just an example, the question is not about him but about the situation at all
How to understand which parts of the code to do universal and which are hard to prescribe?
If this is not a social network, where traffic amounts to petabytes, and load on database - thousands of queries per second, then the most rational decision in such matters is, in my opinion, has long been found and it's called the PLO, including for data processing, many systems (e.g. frameworks) there is such an entity as the object (or "model" if you will), You easily can add a new property that is calculated dynamically. This works fine in most cases.

Another example of solving such "problems" - on the DB level (I suspect it is about storing data in text files is not?), for example, even in MySQL (all painfully familiar) is the mechanism of "virtual columns", which solves the problem with currencies (with proper desire) and the price per sq. m. and so on. An even easier option that exists probably in all the RDBMS use VIEWS, complementing it with new values as necessary, another option is to create a trigger on INSERT/UPDATE and add new column, whose value will be calculated automatically.

And so, plenty of examples, but, as correctly noted by the previous speaker - all depends on the individual case and no universal tool for solving such problems or for carrying out construction works (as an example) - not yet invented. Some tasks are better solved "hammer", some "drill"...
June 14th 19 at 20:23
I guess the General rule is that "if the value of something is dependent, it must be flexible."
June 14th 19 at 20:25

How to understand which parts of the code to do universal and which are hard to prescribe?


If you are just starting to do project and there is some degree of uncertainty, we should not strive for universality. Better "hard coded" rules, and even duplicate in some places code than premature to make a universal solution which in the future would be inappropriate. When the project will live for some time and requirements more or less down, you will understand what parts of the project can be made uniform.

Find more questions by tags Programming