52North / IlwisCore

Integrated Land and Water Information System (ILWIS) is a remote sensing and GIS software. ILWIS Core is the functional center of ilwis4..
http://52north.org/communities/ilwis/
35 stars 13 forks source link

duplicate method in kernel.h #12

Closed ridoo closed 10 years ago

ridoo commented 10 years ago

It seems that kernel.h defines duplicate template methods. Signatures just differ by a const expression:

line 126:

template<class T> const T *factory(const QString& type, const QString& subtype="") const {

line 140:

template<class T> const T *factory(const QString& type, const QString& subtype="")  {

I would go for the const version as it guarantees that no state changes occur.

ridoo commented 10 years ago

Both methods have the same body so the discussion addressing this (or a similar topic) on stackoverflow won't apply here, will it?

MartinSchouwenburg commented 10 years ago

In c++ the const behind the last bracers is part of the method signature so they are different functions. The const variant methodis different though as it returns a const pointer while the other doesnt(this isnt correct in your code paste above). They are used in different scenarios. The factories themselves are functions pointers inside the masterfactory (may change in the future, not sure yet) so the const makes sense as they are pare of the state of the masterfactory and may or may not change (depending on the variant used)

ridoo commented 10 years ago

Well, what I see problematic here is just duplicate code. What about the good practice for const 'duplicates' described in the discussion on stackoverflow?