Theory of programming theory. When to write single-purpose functions?

I'm sorry, but I can’t identify this “thing” that I’m trying to understand.

When writing functions, we can use different approaches, I made several examples of "placeholders":

--------A---------
getImageSmall();
getImageLarge();
getTextSmall();
getTextLarge();
--------B---------
getImage('small');
getImage('large');
getText('small');
getText('large');
--------C---------
get('image','small');
get('image','large');
get('text','small');
get('text','large');
--------D---------
get(array('type'=>'image','size'=>'small'));
get(array('type'=>'image','size'=>'large'));
get(array('type'=>'text','size'=>'small'));
get(array('type'=>'text','size'=>'large'));
--------E---------
get('{"type":"image","size"=>"small"}');
get('{"type":"image","size"=>"large"}');
get('{"type":"text","size"=>"small"}');
get('{"type":"text","size"=>"large"}');

I could also include objects, but for now I prefer to stay simple.

The array in "D" is a php array to show the difference between the example "E" that json uses.

, , , . , "" , , , , .

:

  • ? ( )
  • ?
  • ?

/questions/ .

+5
3

. , " ". . ,

http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

YouTube " ", , , .

, . , , Get, , . , , . , , - , , , . , , , .. -.

. , . , .

+2

, , , . downvotes - .

, ; -API MVC. , - , get ( ), , .

API , , .

? ( )

, .

, ?

. , (, ), .

?

- - , , .

+1

C D/E , . C D E :

  • , . .

  • , , , , .

  • There are many optional arguments in your function. PHP does not support named arguments, so if you want to call a function with 15 optional arguments and you supply 5, it is much easier to pass an array of arguments than to remember which of the 15 positions contains your 5 arguments and write a lot nullbetween them.

For functions that take a small number of arguments that require all or in most cases, C may be useful because it makes it easier for other readers of your code to see the design of the function and its requirements at a glance.

0
source

All Articles