What Is Generalization

In the context of software development, a "generalization" is a broad solution derived from a specific solution.

Quite often, generalization happens when one sets out to "solve the general case" for a specific requirement. While general solutions are often "better" by some measure, the act of deriving them carries risk, particularly when the requirements for a general solution are imagined. See PrematureGeneralization.

Are there generalizations outside of solution space? What is the measure by which general solutions are better? Wouldn't that have to do with a class of problems? ---

An example of generalization might be to create a function "TwoPlusTwo" with no state or parameters that always returns 32 bit integer 4. This is a very specific function, and of little general use. There are lots of ways to make this function more general and more widely usable. You could add one or two parameters to specify the input values. Independently, you could add a parameter that specified the operation. Also, you could declare it part of a class and give it state, mutating it (perhaps) to a "PlusTwo?" function.


The generalization of a function is a change which increases the size of the domain in which it can be applied.

Examples:

As you can see, as the function becomes more general, you can use it in more places. But, it may also become more difficult to use, may be more difficult to maintain, and may communicate less to the maintainer at the point of call.

[Try framing the above in terms of mathematical functions and relations, to add a bit of rigor to your arguments. For example, is "two plus two" really a function?]


A generalization of an item (method, class, whatever) is any action which requires additional specification provided by other items to maintain its original operation.


Generalization is language invention.

Think of natural languages rather than focusing on programming languages.

I would try and abstract away from thinking of programming language/mathematics, and frame this question (or rather, the answer) as a philosophical one; generalization is close to language and understanding. Generalizing a piece of code, introduces a mini language (the subroutines/classes/methods/named things) to the calling code, which to the user (reader) of the code might make it simpler - if the language "makes sense" - or obfuscate, if the language isn't grokable/suiting. Related: LanguageIsGeneralization? but do keep in mind that ProgrammingIsManagingDetails?. Constant conflict. ---objarni


EditText of this page (last edited November 22, 2013) or FindPage with title or text search