[mapserver-dev] Modernizing code base: C99 and maybe C++ ?

Even Rouault even.rouault at spatialys.com
Wed Nov 27 10:25:33 PST 2019


On mercredi 27 novembre 2019 11:26:10 CET Steve Lime wrote:
> I don't think anyone has ranted about moving the code-base to C++ before -

And this is exactly was really surprises me. I should
really have written that email 10 years ago (well maybe not about C++11
10 years ago :-)), I blame myself for not doing it, but everytime I touch
MapServer code base, this is the first thing that comes to mind.
Maybe I've been "spoiled" too much lately with practicing C++11 in GDAL
or PROJ, but the syntaxic sugar really lowers the cognitive burden from the
language features to the interesting algorithmic part. I can tell you that PROJ 6
would have never seen the light if it had to be written in C89 (some might
have seen that as a good outcome maybe :-)). Or I would still be chasing for
memory leaks all over the code.
Anyway as a PSC member I think it is my duty to raise the issue, be it in
a rough form. This is an "open source" project, for better and worse, so
anyone can see by themselves how the code looks like. Eh, isn't that our
main differentiating argument w.r.t proprietary software :-) ? And this
is probably what a new contributor would do.

> Still, it's likely a lot of work depending on how far it was taken. I mean
> does this mean turning xxxxxObj structures into proper C++ classes, etc...?
> How would you see pulling off a conversion like that off?

I wasn't even thinking at that. That would be a huuuuge effort. Was more
thinking about just using string manipulation facilities locally in functions.
Or using a vector, a hashmap, etc... Something incremental. Then someone bold
enough could try to adapt the internal API progressively. Even my apparent
joke about renaming the files from .c to .cpp was pretty seriously considered,
and could be seen as a positive signal, even if most of it remains mostly in C.

OK, as an example of what C could save us. This recent commit by myself, which I
needed when touching a bit the SLD code
https://github.com/mapserver/mapserver/commit/9bb379794e63e654de408cc416db692424da20e4
It is mostly my reimplemtation in C of what the std::string += operator does.
msStringConcatenate() is fundamentally an inefficient way of concatenating strings.
It has probably O(n^2) performance if you call it to aggregate lots of small substrings.

> Definitely RFC worthy...

I have written long enough RFC lately :-) Deferring on that one. The material
is pretty much above.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the mapserver-dev mailing list