0

Recently, I've been assigned to a project (C++) at work where there is a significant amount of string matching/parsing in an XML-ish document (similar to XML, but not quite; it's bizarre) As a result, in order to both increase readability and reduce copy/paste errors, I've placed several macros at the top of several of my source files. For reference, the macros are different in each file. For example:

#define CATAGEORY_PATH "properties/event/classifications/classification/@category"
#define CLASSIFICATION_PATH "properties/event/classifications/classification/@classification"

Is what I did considered bad form and/or is there a better way to do this? At the moment, I like this method as it is clear throughout the code what I have done, but something about #define for a string bothers me.

From the experienced coders in the crowd, what are your thoughts? Also, from the professional developers, what do you think? I apologize if the distinction offends anyone, but, in my experience, there can be a significant difference between both populations.

Thanks!

jhammond
  • 1,916
  • 2
  • 15
  • 29

1 Answers1

2

An alternative for constants is static const.

static const char category_path[] = "properties/event/classifications/classification/@category" ;

This way there is at least a little bit of type information decorated with it.

woolstar
  • 5,063
  • 20
  • 31