Hot answers tagged

3

Assume you were not the one who has written this library, but someone else. You don't know the lib, but you get the task of reusing functions from it if possible. Now you want to check if it contains a specific functionality for your current email-related use case. do you think you would find out easily there is function "email" in it - among 100 other ...


3

Does any programming language have this kind of thing...? Yes. All statically typed languages support this. For example, in C# I could define the type that getBody will return: public class Body { ... public string Name; ... } public interface MyInterface { public Body GetBody(); } This way, every implementation of MyInterface must ...


2

As talking about content-type headers only makes sense in the context of a remotely rendered view, as it typical for web-applications, I will assume that is the case here as well. The content-type header, as well as other headers, are part of the communication mechanism for transferring the View information from the back-end part to the front-end (view ...


2

Yeah its a code smell to check the type of an object. The whole point of polymorphism is that you shouldn't have to know the type. In your case the code will break if I pass in some other derived class of Account. In terms of performance, searching the lazy loaded lists either way is going to be slow. Splitting it down into private and public accounts ...


1

A number of considerations: Can you spot clusters of arguments that are related to each other, that belong together somehow, more than to the others? If so you may be missing a class. You could create an object and pass that instead of the loose arguments. This would be more meaningful. Like a rectangle instead of left, top, width and height. The rectangle ...


1

function makeAssembly(array $params) { $pump = $factory->fromModelNumber($params['modelNumber'], $params['stages'], $params['x']); $motor = $factory->createMotor($params['frameId'], $params['productId'], $params['x']); } The unforgivable sin here is that you force the users of this function to reverse engineer knowledge of what keys ...


1

Yes, wrapping your functions in a class is probably a good idea. In some other languages the class would be unnecessary, and it would be better to just write stand-alone functions. But PHP classes have one big advantage over functions - they can be loaded on demand via autoloading. Standard practice is to distribute libraries via Composer, which provides ...


Only top voted, non community-wiki answers of a minimum length are eligible