{'fraction_non_alphanumeric': 0.026078234704112337, 'fraction_numerical': 0.0010030090270812437, 'mean_word_length': 5.333333333333333, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
The “ Weak Generics ” Problem : Sources , Implications and Treatment

Generic design aims at achieving non-redundancy for simplification reasons, by unifying similarity patterns at design and code levels, whenever there is an engineering benefit of doing so. The extent of non-accidental repetitions recurring similar structures in programs suggests that the potential of generic design may not be fully exploited. Poor design and ad hoc maintenance are the two often mentioned reasons why programmers multiply similar code structures (often termed as clones in literature). At times, cloning is done in a good cause, for example, to speed up development, increase program’s performance or improve its reliability. Still, much unresolved similarity remains in newly developed, well-designed programs. Often a symptom of failure to achieve genericity (therefore, term “weak generics”), such situations were of our prime interest in the work reported in this paper. In the paper, we present results from four empirical studies in which we found over 60% of code contained in similar program structures, recurring many times in programs. In some cases, problems occurred, as using conventional methods a suitable generic solution was either complicated or conflicted with other design goals that could not be compromised. In yet other cases, existing mechanisms were not sufficient to define suitable generic design solutions. We believe the problems that we observed are not isolated but affect many other programs. We propose to strengthen generic design by applying meta-level parameterization and generation on top of conventional programs. We discuss one technique to realize such a “mixed strategy” solution and trade-offs involved in employing meta-level techniques. The approach is practical as it complements, rather than competes with other programming paradigms, and can be gradually adopted, starting with conventional programs. It has been successfully applied in industrial projects.