Code Monkey home page Code Monkey logo

Comments (3)

jgalan avatar jgalan commented on August 15, 2024

I see, then we will need to introduce a python script at the validation pipeline, similar to validateProcesses.py, or inside validateProcesses.py that certifies that no any statement appear at the process header.

from framework.

jgalan avatar jgalan commented on August 15, 2024

Another option would be to avoid using using namespace std; at the headers? And then write directly std::any when willing to use the c++17 standard one.

There are not many classes to modify in that case:

galan-gifna:source javi$ grep -rnw . -e "using namespace std" | grep .h:
./framework/tools/inc/TRestReflector.h:28:using namespace std;
./framework/tools/inc/TRestSystemOfUnits.h:20:using namespace std;
./framework/tools/inc/TRestDataBase.h:10:using namespace std;
./framework/tools/inc/TRestStringHelper.h:24:using namespace std;
./framework/tools/inc/TRestTools.h:31:using namespace std;
./framework/tools/inc/TRestPhysics.h:27:using namespace std;
./framework/tools/inc/TRestStringOutput.h:24:using namespace std;
./framework/core/inc/TRestTask.h:22:using namespace std;
./libraries/detector/inc/TRestDetectorGeometry.h:35:using namespace std;
./libraries/detector/inc/TRestDetector.h:35:using namespace std;
./libraries/geant4/inc/TRestGeant4ParticleCollectionDecay0.h:15:using namespace std;
./packages/restG4/include/SteppingAction.hh:15:using namespace std;
./packages/restG4/include/EventAction.hh:37:using namespace std;
./packages/restG4/include/RunAction.hh:44:using namespace std;
./packages/restG4/include/PrimaryGeneratorAction.hh:48:using namespace std;
./packages/restG4/include/PhysicsList.hh:44:using namespace std;

Perhaps then we can just have a validateCode.py that checks if using namespace std; is found at the headers files.

from framework.

Vindaar avatar Vindaar commented on August 15, 2024

👍 for the change, because up to now I thought the usage of any was indeed referring to C++'s std any.

Aside from that I would personally rather use something inherently safer than something like what we have here now, e.g. std::variant (obv. not available since we do not target C++17 I suppose):
https://en.cppreference.com/w/cpp/utility/variant

The problem I see with the current approach is that it's inherently unsafe, unless one uses the GetValue helper. But in practice that doesn't seem to be used, e.g. here:
https://github.com/rest-for-physics/framework/blob/master/source/framework/core/inc/TRestAnalysisTree.h#L118

If the user calls GetObservableValue<int>(…) but the stored value is actually a float this produces garbage and there's no runtime checks for this. Personally I would remove the ability for direct access to the pointer in TRestReflector and force the usage of GetValue. There can be a more verbose and possiblye "dangerous" way, i.e. an unsafe_ptr proc for the case where one really wants to avoid the if check. But imo that shouldn't be necessary, because code that is performance critical should never use such objects anyway.

Naming wise I would choose something like RestValue.

from framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.