Link: Lawrence Lessig on Copyright

May 2nd, 2009 Comments off

Lawrence Lessig presentation
Here’s a great presentation by Lawrence Lessig about the changes we desperately need to have in copyright law. It’s beautifully done as a presentation (I’m guessing in Apple’s Keynote) and, though 45 minutes long, worth watching every minute of. It’s extremely entertaining and frequently very funny.

By the way, this video is not on YouTube because Warner Brothers issued a DCMA “take down” notice – though there doesn’t seem much doubt that this was unwarranted under standard fair use provisions of the existing copyright law.

The irony is that I would never have stumbled upon this if Ray Beckerman hadn’t linked to a site linking to it; and that site only linked to it because of the takedown notice. Go figure.

Categories: Links Tags:

Are You Paranoid Enough?

May 1st, 2009 Comments off

(Image from iStockPhoto)
When it comes to preserving your valuable data, it pays to be paranoid.

Assume the worst, think of all the possible ways things could go wrong. Be paranoid. The question is not whether you are paranoid, but whether you are paranoid enough.

These days, everyone has valuable data, and it’s taking up more and more room. Documents, spreadsheets and databases; emails, photographs and even video. Game players have many save files capturing their progress in various games. In my case and that of most programmers I also have many files and folders comprising highly valuable program source code. We’re all working hard generating digital files of one form or another, almost every day.

So, think about how you would feel if you lost that data. Bad? It could be worse than bad.

About ten years ago the young programmers in my office were having fun replaying an audio file garnered off the Internet, from some computer company’s help-line. It was a call from some guy who had been writing a book on his computer, maybe a novel. Something went wrong with the machine and he sent it in for repair. The computer company had (for whatever reason) wiped the hard disk. The young guys in my office thought it was hugely amusing to hear this guy raging in despair about the loss of all of his data, almost literally foaming at the mouth. Personally, I found it very painful to listen to. I could feel his pain.

Losing data, particularly creative work you have labored over, is tragic. This is why I am paranoid about backups.

Here are my paranoid rules:

  • If there’s only one copy of something, it might as well not exist at all, you’re going to lose it. Make an immediate copy of any irreplaceable item (such as photographs of a wedding, which can’t be replaced at all).
     
  • If you only have two copies of something, each copy must be kept in a different physical location. The house or office could burn down (or, as happened to my daughter and her husband, the backup drive can be stolen along with the laptop it was backing up).
     
  • Two copies is not enough. Your hard drive could crash AND the backup copy could be lost or prove corrupt. I’ve had it happen.
     
  • How do you know your backup files aren’t corrupt? Check them regularly.
     
  • Are you backing up everything you might want? I regularly (say once very 18 months) reformat my desktop computer. That’s when I remember all the things I should have backed up but could easily forget to: fonts, passwords, email archives, application settings.
     
  • What about backups of material not on your desktop computer? Like on-line blogs, forum posts, etc. A colleague of mine forgot to renew his domain name and hosting package and lost a valuable travel blog and photographs.
     
  • Think about how much time you would be prepared to put in to re-create your work if it was lost. In other words, how much work could you bear to lose? A day’s worth? A week’s worth? Backup more often than that.
     
  • There’s no such thing as too many copies if the data is really valuable.

So here’s my backup strategy. Personally, I don’t yet think it’s paranoid enough.

  • For program source code, I use a version control system (Subversion) to save progressive versions, each time I do significant work on any programming project. The commit happens via a VPN, to a server in a different physical location to my desktop – in fact, to an office some 20 km away. This generally happens once or twice a day on a current project. As Jeff Attwood says, source control is the absolute bedrock of software engineering.
     
  • I have an external network drive (a 500GB LaCie Ethernet Mini). I use Acronis to schedule weekly backups of ‘My Documents’ and source code folders, on an incremental basis (this means I can backtrack, à la Mac Time Machine, to previous versions of things).
     
  • I copy the Acronis backup files from the LaCie to one of two identical external USB drives (Western Digital MyBooks). Only one of these is kept at my house. On an approximately weekly basis, I take the current MyBook drive with me to another physical location, and swap it with the identical drive already there. Even in my house, the MyBook drive doesn’t live on my desk, but somewhere else in the house where a thief won’t find it.
     
  • When I’m feeling particularly vulnerable, I burn DVD-ROMs of really critical files and keep them somewhere else.

You might quite reasonably ask why I don’t use ‘cloud storage’ to backup files to a location on the Internet, like Amazon’s S3. The answer is that in Australia our broadband upload speeds are still so feeble that it would take weeks to backup any significant volume of data this way.

So am I paranoid enough? I guess I’ll only find out when things go wrong.

“Even paranoids have enemies”
— Golda Meir to Henry Kissinger

Lazy People Make Progress

April 22nd, 2009 Comments off

Progress isn’t made by early risers. It’s made by lazy men trying to find easier ways to do something.

-Robert Heinlein

This came up today on the ‘Quote of the Day’ box on my iGoogle page.

It strikes me as being very true, and very applicable to many software developers. It’s not that we don’t work very hard; but it’s that that we’re so lazy that we will often work very hard to save ourselves the effort of having to work on stuff we hate doing.

Someone, like me, who is a compulsive programmer, would much rather spend an hour writing code to automate a boring task than spend half an hour actually doing the task manually. Even if we’re only ever going to have to perform the task once!

There’s some great stuff about compulsive programmers in Computer Power and Human Reason by Joseph Weizenbaum, written way back in 1976, but full of very useful insights into today’s world even so.

It’s Optional

April 19th, 2009 Comments off

What’s the best way to store and retrieve optional settings or preferences for users for your C# application? For simple stuff, there’s no easier way than creating settings in Visual Studio:

Settings dialog

Note that you can use settings for both simple values like bool and string, and for more complex values like colors.

These settings get persisted in a file called [your program name].exe.config.

And you can refer to them in code like this:

    private void GetBackgroundColor()
   {
         this.BackColor = Properties.Settings.Default.BackgroundColor;
    }
 
    private void SetBackgroundColor(Color backcolor)
    {
          Properties.Settings.Default.BackgroundColor = backcolor;
          Properties.Settings.Default.Save();
    }

Well, that’s all very well, simple, and very useful. But it gets messy if you want to set up a lot of options and particularly if you need options using your own enums, in various categories or for different states or objects in your application – the Settings dialog is just a very simple, line by line set of options with no structure.

My own preference* is to create one or more Options classes, and to use the nifty Xml Serialization stuff which I talked about previously on this blog to load and save the class.

Here’s a considerably cut-down version of my Options class from my software Chapter Master:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public class Options
{
	public enum ImageGrabOptions
	{
	    None,
	    CropFromTop,
	    CropFromLeft,
	    CropFromRight,
	    CropFromBottom,
	    CropFromCentre,
	    Pad
	}
 
	public enum SaveOptions
	{
	    None,
	    RenameOriginal,
	    PromptForNew
	}
 
	[System.Xml.Serialization.XmlElement()]
	public ImageGrabOptions ImageGrab = ImageGrabOptions.CropFromTop;
 
	[System.Xml.Serialization.XmlElement()]
	public SaveOptions SaveOption = SaveOptions.PromptForNew;
 
	[System.Xml.Serialization.XmlElement()]
	public int PadColorAsInt = Color.White.ToArgb();
 
	[System.Xml.Serialization.XmlIgnore]
	public Color PadColor
	{
	    get {
	        return Color.FromArgb(PadColorAsInt);
	        }
 
	    set {
	        PadColorAsInt = value.ToArgb();
	    }
	}
 
	public Options()
	{
	}
 
	public bool Save(string filename)
	{
	    return Seralize.ToXmlFile(filename, this);
	}
 
	public static Options Load(string filename)
	{
	    return opts = (Options) Seralize.FromXmlFile(filename, typeof(Options));
	}
}

Where Serialize is a class containing just the Xml serialization routines I wrote based on this Code Project article.

Note the way that the Color is serialized in lines 27-40, the same sort of workaround as is needed for TimeSpan values.

I like this approach because among other things, it allows different sets of preferences to saved and loaded as required.

Accessing these option values is very simple (this code is a fudge written just to demonstrate my general approach):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private readonly string MySettingsFolder = 
      System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
      + @"\ProgramName";
 
private OptionClass MyOptions;
 
private void GetOptions()
{
     MyOptions = Options.Load(MySettingsFolder  + @"\Default Options.xml");
}
 
//....and thus code like:
 
picCover.BackColor = MyOptions.PadColor;
if (MyOptions.ImageGrab.CropFromBottom)
{
     //........
}
 
private bool SaveSpecialOptions()
{
    return MyOptions.Save(MySettingsFolder  + @"\Special Options.xml");
}

* I’m happy to have others tell me why there are better ways. As always, I certainly don’t claim to be any kind of expert. This is just the way I like to do it. If you think it’s dumb, tell me so.

Categories: Programming Tags: , , ,
Performance Optimization WordPress Plugins by W3 EDGE