xiaoyifang / goldendict-ng

The Next Generation GoldenDict
https://xiaoyifang.github.io/goldendict-ng/
Other
1.72k stars 95 forks source link

refactor: change `DEF_EX` macro's underlying implementation to template #1939

Closed shenlebantongying closed 1 week ago

shenlebantongying commented 1 week ago

Fun stuff :)

sonarcloud[bot] commented 1 week ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

xiaoyifang commented 1 week ago

template and extra fmt::format? not easy to understand compared to #define. the previous version is ok.

shenlebantongying commented 1 week ago

Now it is easier to modify them. Macro don't have types, but template code have some types.

In IDEs, the code can be edited like normal code with inline hints, type warnings...

And there are no warnings anymore.


The single line fmt::format is technically better

From

std::string( exDescription ) + " " + value_

to

fmt::format( "{} {}", description, message_ )

One std::string construction and " " concatenation are removed.