0

I program as a hobbyist. I mainly code using an online tool (a website) that allows me to write, run, share, and debug code online.

The website I use does have version control built in.

Quite frequently, I forget to save my code. I close the tab accidentally, and lo and behold, hours of code are gone. This is really annoying and I don't enjoy redoing what I already had done.

Since I'm not a professional developer, I can hardly imagine buying (probably expensive) tools which keep source code safe, and I can't afford spending months learning and practicing practices and processes used by professional developers.

What can I do, as a hobbyist, to avoid repeatedly losing code?

closed as off-topic by MetaFight, Jörg W Mittag, Eric King, user22815, gnat Jun 21 '16 at 0:32

  • This question does not appear to be about software engineering within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 36
    Use a real editor and save your files on your disk + use source control? – Vincent Savard Jun 16 '16 at 20:07
  • 2
    Either get into the habit of saving your code often, or switch to a tool that does it for you. This is kind of an odd question. – Eric King Jun 16 '16 at 20:13
  • 9
    No, the tools are not probably expensive. More than likely they are free. Notepad, vi, Eclipse, XCode, even some versions of Visual Studio are free. Some of these have a learning curve, some really don't. In any case, it won't be months, more like days or even hours. The tools needed to avoid this are free, and the practices needed to avoid this can be mastered in an afternoon. (learnenough.com) – Joe Ballard Jun 16 '16 at 21:33
  • 7
    I still think the only reasonable answer to this question is get into the habit of clicking the save button. No tools, no frustration, no learning of esoteric processes. Why does it have to be more complicated than that? – Eric King Jun 16 '16 at 23:34
  • 4
    @jpmc26 I think the point is, OldBunny seems satisfied with everything, except the fact that hours of work is lost because the save button isn't pressed. Solution? Press the friggin' save button. – Eric King Jun 17 '16 at 0:36
5

You could use your disappointment and upset as a chance to learn something.

Any good editor takes frequent snapshots of your study, including emacs and every IDE I've used. You should find an editor that does this and use it.

Saving code is usually required to run it so if you are developing locally this should be less of an issue. Of course you can still accidentally delete a file, which is where source control comes in.

You should also be in the habit of using source control. git will not auto-save but the more you use git the more you are used to performing frequent commits. Other source control software will also take frequent snapshots for you.

Beyond that, redoing a few hours of work should only take an hour or so, so either do it or go do something else, it's really your call.

25

The goal of Repl>it is to write and share short snippets of code. For instance, you may use it to illustrate your point when discussing a particular aspect of your favorite programming language with other programmers, or you may use it to sketch some code in a few minutes.

Repl>it is not intended to actually write and maintain codebase of any size, not even short scripts you intend to reuse to perform repetitive tasks. If you spend at least half an hour writing code, Repl>it is the wrong tool for that.

Instead:

  • Use version control. Git, SVN, whatever. Version control is the primary and mandatory tool for any team of one or more developers, including hobbyists.

  • Ensure the version control repository has (1) regular, (2) automatic (3) off-site backups. Regularity means you won't lose two months of your work. Automatic means that backups will run; no matter how strongly you believe that you'll do backups manually on regular basis, when disaster will occur, you'll discover that you haven't done them for a few months. Off-site means that you don't keep the actual data and the backups in a same geographical location. If you do, fire and burglars put both the data and the backups at risk.

  • Commit your code to version control frequently. Although there is no strict rule telling that you should commit with a well-agreed frequency, make sure you make a commit as soon as you did a logical change to your codebase: added a feature, fixed an issue, refactored something. If you're actively coding the whole day and didn't made any commits, it usually indicates that you're not doing commits frequently enough.

    Committing frequently is important if you want to reduce the consequences of messing with the current changes. Imagine you spend two hours implementing a feature, but wait until the evening to commit. Later, you fix a bug, and, mistakenly, overwrite one of the files containing the recent feature: this screws your two hours work.

    However, don't commit too frequently (committing, on regular basis, once per minute would be considered as too frequently). If the number of commits grow, it will become more difficult to keep track of what was actually done through the commit log.

If you're writing open source code, using version control is easy. For instance, GitHub hosts the code for you at no charge. If having a public repository is not a solution for you, you can host your own Git/SVN server for free or pay for private repositories (according to Richard Tingle, you can even get small private repositories for free).

What else? Well, that would be all you need. You don't have to pay a few thousand dollars for Visual Studio or spend months learning specific practices. At least, the problem of code loss should be solved with a simple version control as a tool and frequent commits as a practice.

  • 1
    You can get small private repositories for free too. E.g. bit bucket. Presumably in the hope you'll outgrow them and start paying – Richard Tingle Jun 16 '16 at 21:04
  • Visual Studio even has free versions these days, which integrate out of the box with GitHub. – Telastyn Jun 16 '16 at 22:42
  • @Telastyn Yup I use Team Foundation with Visual Studio Community, all free, pretty great! Even a plugin for IntelliJ too. – Insane Jun 16 '16 at 23:10
  • 1
    I'm the founder of repl.it and while I agree with a lot of what you said in terms of version control -- I think you underestimate how much learning and practicing happens on repl.it. We're not just narrowly focused on providing a tool for short snippets of code-- in fact we have an education platform currently in the works to better serve teachers and learners. The solution to the problem is simple from our side. We just need to save the code in localStorage so that the user can come back and find pre-populated in the editor. – Amjad Masad Jun 17 '16 at 3:56
  • 2
    @AmjadMasad: welcome to Programmers.SE, Amjad. While repl.it has other purposes, my answer was focused on the ones which, I believe, the OP would actually use. As for the LocalStorage, I think it would only mask OP's problem instead of actually solving it. I would rather imagine a system such as the one used by Google Docs which tracks all the changes made to a document, with the possibility to go back to a earlier version. However, such system (1) is very expensive, and (2) doesn't put the developer in control of the actual versions, unlike a VCS. – Arseni Mourzenko Jun 17 '16 at 9:14
6

The cost of professional tools

You severely under-estimate the availability of free tools. Software development is an industry with a wealth of completely free tools that professional developers use every day.

Free things that I use regularly in my job as a developer:

  • git (Source control, the major thing you're looking for here.)
  • KDiff3
  • SourceTree
  • Notepad++ (An excellent plain text editor on Windows)
  • Python
  • A large number of Python packages (flask, SQLAlchemy, click, pyparsing, attrs, setuptools/pip, requests, and many more)
  • PowerShell
  • bash
  • Linux (various distros, e.g. Debian, Centos)
  • Chrome with Dev tools or Firefox with Firebug
  • PostgreSQL
  • PostGIS
  • pgAdmin
  • MSYS2
  • 7-zip
  • GDAL
  • SQL Server Management Studio
  • Oracle SQL Developer
  • QGIS
  • PuTTY
  • WinSCP
  • Node.js
  • SchemaSpy (old, but still free)

Okay, you have to have Windows for some of those, which isn't free, but not for most of them. And chances are you have a Windows computer somewhere or can find a non-Windows equivalent.

A lot of software has paid and free versions, too, and very often, the free version is fully featured enough to be useful. Some examples:

  • SQL Server (Express = free)
  • PyCharm (Community = free)
  • MarkdownPad
  • Visual Studio (Community = free, mostly)
  • Slack
  • Bitbucket

I hope you can look over this list and see that you can pretty much put together and entire application stack without paying a dime, and all of them can be installed and run on your local machine. Plus, I'm only scratching the surface with the things I personally use regularly, as a professional. The only thing that's hard to find for free is hardware, but there's even a few options on that front for web hosting. (Heroku is one example.)

Not losing your work

Work locally.

To start with, you need to work locally. Start using an editor to save your code files to disk. A number of editors will even "save" working copies that can be recovered if the program crashes. (The humble Notepad++ does this, even.) Download and install the runtime for the language you use. Use it to run and test your code.

You can use a full IDE or a plain text editor. If the language doesn't make it too difficult (like C# does, for instance), I generally recommend starting out with a plain text editor. You'll learn more about the process of how code runs this way, and that will make your life simpler later on.

If this isn't enough to protect your code, then...

Use source control

Source control allows you to maintain a history of your changes. You edit your files, and then you commit them. The software keeps track of what changes occurred between any two commits. Beyond just saving your changes, it also fills the roles of moving code (to servers or other developers' machines) and of integrating different sets of changes to the same files together.

For you, I highly recommend git. It's the dominant source control tool in the software industry right now, both professionally and non-professionally. While git is most commonly used with a server, its design allows you to just keep everything in one folder on your machine. If you want to preserve your changes somewhere other than your machine, look into git services that offer free repositories.

git can be a little hard to approach, so if you find it too difficult, you can consider SVN. It's much easier to learn, but it requires a server to run. You can run one locally, but it will probably be simpler to find a service that offers free repositories.

Free repositories are typically limited in some way, but given that you've been making do with repl.it, I'm sure you can find a service with limitations you can live with.

Something to consider is that hobbyists and professionals alike use source control. It's expected today for anything beyond the smallest of throwaway programs/scripts. So this is a necessary skill to have if you want to be involved in the development world at large (either socially or professionally).

  • If the downvoter would be kind enough to leave some feedback, I'd be glad to consider it. – jpmc26 Jun 17 '16 at 0:46
  • 5
    Visual Studio Community is almost identical to the Pro edition and free for individuals and small companies. (Though it has the downside of requiring a Microsoft account) – CodesInChaos Jun 17 '16 at 9:40
  • @CodesInChaos Maybe it's better now than it used to be. When I tried it a couple years ago, it was all that craziness where it was split into the "web" and "desktop" and "phone app" versions, and they couldn't even build projects of other types. I'm pretty sure a Community version wasn't a thing back then. – jpmc26 Jun 17 '16 at 22:19
  • Those were the express editions, which were indeed rather crippled. The Community edition was introduced with VS 2015 and has very few technical restrictions compared to Pro (no TFS support). Legally it's restricted to individuals, small companies and open source projects. (See 1. INSTALLATION AND USE RIGHTS.) – CodesInChaos Jun 18 '16 at 9:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.