3

I have a (possibly bad) habit of coding everything into a monolithic header file when trying out ideas, placing all implementation code with the class definitions. As the code expands, it becomes difficult to navigate the file. Therefore, I refactor the code into separate files and split the implementation details (cpp files) from the interface (hpp files).

The laborious copy / pasting involved seems like a job for a machine. Are there any simple tools available for this task?

learnvst
  • 15,455
  • 16
  • 74
  • 121
  • "implementation details (hpp files) from the interface (cpp files)." Other way around, right? – johnsyweb Feb 16 '13 at 11:55
  • An inch of prevention's worth a pound of cure which results in some amount of inch-pounds per file. I'd agree with "possibly bad". – ChiefTwoPencils Feb 16 '13 at 12:00
  • 2
    @Johnsyweb In a parallel universe, source files are used to declare interfaces used in an interface-implementing interface file ;). More seriously, edited his question. – Synxis Feb 16 '13 at 12:01
  • Easiest way would be to drop your probably definitely bad habit. – juanchopanza Feb 16 '13 at 12:01
  • His habit is not always bad. Consider the case where he test his code with ideone or codepad, for example on his phone or on a non-dev machine... (But I agree it is not that good in general). – Synxis Feb 16 '13 at 12:03
  • Sounds more like he's using testing as a substitute for designing, but I've been wrong in the past. – ChiefTwoPencils Feb 16 '13 at 12:05

2 Answers2

5

You can try Lazy C++, as stated in this question.

You can also use a standard IDE, and move each function from header to source (for Visual Studio you can use Visual Assist, I think Eclipse can do it straight), generally it's like right click > refactor > move to source or something like that.

Community
  • 1
  • 1
Synxis
  • 9,236
  • 2
  • 42
  • 64
0

This kind of thing is quite common. My approach is to only cut and paste once: make a copy of the original file, then chop stuff from the header and chop other stuff from the source file.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165