Recently I thought about the beauty of my code.
A big question arose when it seemed to me that the arguments in a function should go in a different order than now. Take, for example, a function (in C ++, but the language does not play a special role here, the question is different):
int FindСitу (string *СitiеsList, string сity_nаmе, int сitiеs_cоunt);
The function returns the
id city (from the
сitiеs_cоunt ), the name of which is
What is the best order to write the arguments to this function? What would you do and why? Is there a standard for the correct placement of function arguments?
Of course, there is no single standard, but I would say that in 9 cases out of 10 the parameters
сitiеs_cоunt would go one
And in 99 out of 100 cases the names would be written in the
СitiеsСоunt , or
citiеsСоunt , or
The programming language is, of course, important, and there are often official guidelines on the style of code for a particular language, but often the conditions are dictated by specific frameworks, libraries, platforms, their observance is even more important.
You also need to understand that for an English-speaking programmer, a program is written almost in their native language, and there is a natural desire to replace
to a more meaningful
But often monobase
api more important
количество(базаДанных) вставить(базаДанных, запись1, запись2...)
In functional programming languages, they try to bring the program even closer to a natural language, for example, in
1 to 10 by 2 map (_ * 2) // Vector(2, 6, 10, 14, 18)
this is just an alternate notation for the chain of use
1.to(10).by(2).map(x => x * 2)
Haskell currying, partial application, and infix function applications allow you to do this kind of thing.
Prelude> on f g x y = g x `f` g y Prelude> add x y = x + y Prelude> mul x y = x * y Prelude> addOnMul10 = add `on` mul 10 Prelude> addOnMul10 3 7 100
This also places restrictions on the order of the arguments.
In general, use an order that you think is natural, but with an eye to how others do – excessive individualism is rather harmful.