W
W
web-quest32017-05-07 08:02:58
PHP
web-quest3, 2017-05-07 08:02:58

Unique features or more?

1- Is it better to make one function (method) with a bunch of parameters?
For example
Select all books from the book table by date (from and to)
Select book by ID
Select books by date with a specific author.
2 - Or such things are not molded into one function?
3 - What literature will help to build the code correctly. (I am interested both in general and precisely in the question of functions, how to write them, what it is (a unique solution or a point), why it is better this way and not otherwise, ideally with examples.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2017-05-07
@web-quest3

method != functions. There is a method in OOP, and in OOP you need to understand that methods must work with data that belongs to this class. That is, by itself it should be displayed which methods should be in this class, and which in another.
But even in procedural programming, you need to write functions in such a way that it is easier for YOU to figure it out and fix it later. That is, the function code should not be too heavy to fit in the programmer's head so that it can be read, understood and corrected, and not read-read-read-misunderstood-start-read-again.

V
V Sh., 2017-05-07
@JuniorNoobie

You can make one function where you pass an associative array as a parameter. Inside the function, depending on which parameters are passed, add conditions to WHERE.

A
asd111, 2017-05-07
@asd111

It does not matter. Both options are working. It is much more important to design the database correctly, so it is better to look at the literature on the topic of database design, when normalization is needed, when not, and how to design, taking into account the possible division of one database into several parts (sharding). And about replication it is worth reading. And more about indexed full-text search (elastic search, sphinx) and caching (redis, memcache, etc.).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question