Author Topic: How to stop ALL types of file overwriting?  (Read 6218 times)

Offline Mountaingod

  • Multiple posting newcomer
  • *
  • Posts: 11
How to stop ALL types of file overwriting?
« on: April 09, 2009, 02:59:09 am »
Hi, I'm kind of new to programming, more new to C++, and I started using Code::Blocks yesterday (much easier & less cluttered than VS2007).

I turned all the autosaving features I could find off, but still managed to overwrite some code just now at some point. Nothing I'm writing atm is too crucial but I don't like the idea of any .cpp files etc. being written over unless I expressly tell it to.

What I did was:
Saved a bunch of code
Cleared the lot and replaced it with some simpler code I just wanted to test for a second
Compiled & ran that code
Shut down Code::Blocks & restarted to open the 'saved' version of the .cpp file

- but it seems to have saved the small piece of temporary code, over the top of all the stuff that was there before! If I quit CB without saving, it asks me whether I want to (first for the Workspace & then specific files), but this time it didn't.

Am I right in thinking the compiling & running of a file causes it to be silently autosaved first? Can I turn this off?

Thanks.
« Last Edit: April 09, 2009, 03:03:47 am by Mountaingod »

mrTeoc

  • Guest
Re: How to stop ALL types of file overwriting?
« Reply #1 on: April 09, 2009, 03:39:41 am »
Hello there,

I'm also fairly new to programming myself (I'm not a total newbie, but still...) and started learning C++ a couple of weeks ago :)

As far as I know, you can't do anything simple to disable saving whenever you want to compile your file. The compiler is an external program, and it has to know the location of a .cpp file before it can compile. It's not something that happens in the editor, so the compiler needs to have a saved .cpp file at hand. I suppose automatically saving to a temporary file before a build is a possible solution, but I don't think you can do that and it's not a good approach anyway; it might make sense for single files, but not for projects that use a lot of files which depend on one another.

Whenever you are testing, either save to a temporary file yourself, or comment/uncomment code so that you won't lose anything. Code::blocks has many nice features, such as shortcuts for automatically commenting/uncommenting multiple selected lines of code.
« Last Edit: April 09, 2009, 03:47:00 am by mrTeoc »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: How to stop ALL types of file overwriting?
« Reply #2 on: April 09, 2009, 11:02:42 am »
If you compile a source, it will be saved, for the reasons pointed out by mrTeoc. There is no way to turn that off, it's expected behaviour. Usually that is not a problem, though.

If you need back revisions of your files, install a revision control system, such as Subversion.

Disabling the autosave plugin will make no difference, since that plugin does not overwrite your files by default (unless you tell it to). Instead it regularly saves your work to a different file.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Mountaingod

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: How to stop ALL types of file overwriting?
« Reply #3 on: April 09, 2009, 11:56:45 am »
OK, that's what I thought. It's no problem, I'll just have to remember it in the future. I might turn autosaving back on in that case, given it would ironically have saved the stuff I lost!

Thanks

Offline PaulS

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: How to stop ALL types of file overwriting?
« Reply #4 on: April 09, 2009, 02:46:14 pm »
The last Borland C++ IDE that I used managed to compile without overwriting the user's files.  I don't know if they passed working copies to the compiler or saved & then restored the users files.  I liked the idea that my code wasn't changed unless I did an explicit save. 

I can live with either but it is an idea you might consider for the future.

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: How to stop ALL types of file overwriting?
« Reply #5 on: April 09, 2009, 06:50:06 pm »
The last Borland C++ IDE that I used managed to compile without overwriting the user's files.

The Borland IDE was dedicated to use only the Borland compiler, so compiling from a copy in memory was not a big issue for them.  The C::B IDE is capable of using almost any compiler; since not all compilers can compile from memory, the file has to be written out somewhere for the (unknown) compiler to find it.

Ringo

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: How to stop ALL types of file overwriting?
« Reply #6 on: April 09, 2009, 07:36:39 pm »
Well, we could of course save everything to a temporary directory and compile from there, but it would make everything a lot more complex. For example, compiler errors would have to be mapped from tempfile names to real names. The actual benefit of not saving files is rather small compared to the added complexity and error-proneness.
Usually one would want one's work to be persistent, and saving to disk is the usual way to gain persistence.

Also do note that copying everything to a temp directory may easily take 20-30 seconds for some projects.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline PaulS

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: How to stop ALL types of file overwriting?
« Reply #7 on: April 09, 2009, 08:29:41 pm »
Certainly true on the time overhead for large projects.  I wasn't think of that.  Mine a mostly less than a dozen smallish files.  I have adapted to CodeBlocks ways and just make a manual copy when I don't think that a commit is appropriate.  Still, it was nice.