5 ms·
Too much abstraction?... Or not enough abstraction? $project_folder = "/whatever"; $input_folder = $project_folder . "/input"; $output_folder = $project_
by DerSaidin 8y ago
Too much abstraction?... Or not enough abstraction?
$project_folder = "/whatever";
$input_folder = $project_folder . "/input";
$output_folder = $project_folder . "/output";
- aserafini 8y agoThis does not solve the problem. The input and output folders had different roots in the production app.
- dwaltrip 8y agoHowever, that abstraction is very localized and thus easy to remove (once the new understanding has been gained), so I'd say it is better.
- im3w1l 8y agoYeah that looks nice. An overabstracted example would be $project_folder = "/whatever"; $in = "in"; $out = "out"; $suffix = "put"; $directory_separator = "/"; $input_folder = $project_folder . $directory_separator . $in . $suffix; $output_folder = $project_folder . $directory_separator . $out . $suffix;
- MattHeard 8y ago$in = "in"; $out = "out"; Those are not really abstractions, just extracted variables. An abstraction would change the concept language. $suffix = "put"; This is also not an abstraction, as the language of the term "suffix" comes from its role in string concatenation, which is the same as the role of the original string literal. It doesn't change the "level of abstraction". This isn't an over-abstraction, it's an over-extraction. Each abstraction should be non-trivial. $project_folder = "/whatever"; is a good abstraction. Looking at the string literal "/whatever", I cannot determine it's "role", but $project_folder is a good name and changes the concept language from being about string concatenation or arbitrary names into a concept language about projects and folders.
- xorcist 8y agoNow you've just obfuscated that string for no apparent reason. Nobody can grep for that literal string anymore and you gained an extra line of code. Those paths are not the same data repeated twice just because they share common substrings. They are two paths that serve distinct purposes. The developer likely chose that syntax because it looks like a setting that can be changed. It could just as well have been read from a settings file.
- femto113 8y agoIn the spirit of the original article I think point is not whether it was too much or not enough abstraction--it was the wrong abstraction. His abstraction eases one potential change (changing the project folder, which would imply changing two path strings in the original code but one in his), but at the same time makes a whole bunch of other potential changes much harder (or even impossible) to handle. We all would have been better off if he'd just left the duplication in place.