Graveyard

Tuesday, May 5, 2009

Windows 7 RC

Sorry for another rant, but I must. I've been using Windows 7, Microsoft's successor to the failure that was Vista, since build 7000 (which was one of the first public betas). Yesterday Release Candidate version was released, available to TechNet/MSDN subscribers ( and everybody else). Keys for this version are freely available everywhere, both for 32 an 64 bit versions.

So what are my experiences? In short, it is a real relief after the terribly slow buggy Vista. Elaborating:

  • Amazingly responsive (on par with XP) - how this was achieved is still a mystery to me, MS claims new testing/tracing technologies helped identify bottlenecks
  • Low memory footprint (something like 200MB for the OS with Aero, down from almost 500Mb in Vista)
  • Usable, usability improvements in almost all system components - control panel, task bar, command line, system software, media libraries are actually usable now, and so on
  • Many improvements in the OS core and new functions like VHD (virtualization built-in which is a must in modern OS)
  • UI feels "nice" - almost like Macintosh but without proprietary interfaces and software absence problems of Apple (try Win-Left/Right combo)
  • All software which worked on XP/Vista works here, I did not need compatibility mode for anything yet
  • Driver coverage: everything was supported on the three computers that I installed it on, so it's been 100% for me with no manufacturer disks (YMMV)
  • The fact that Microsoft gives you over one year of free evaluation is pretty nice, too (expiration for this RC is June 2010)


Would I immediately upgrade from Vista? Without doubt, even if this new OS would've crashed with BSOD every other day :) From XP? Yes, if only for the new taskbar. Some tips on Windows 7 installation:

  • Upgrading from previous builds: unpack downloaded ISO and edit sources/cversion.ini file in notepad - where it says "MinClient=7077.0" lower the version to any number below your currently installed build.

  • Installing on Asus EEE PC: just did a test install and with some services/control panel tweaks it runs pretty well on Asus's netbook. To install you would need a bootable USB flash, 4GB in size (you need exactly 4GB, which now costs something like 15$). Copy all the files from inside Windows 7 ISO (7zip can unpack ISOs) to the bootable USB flash, tweak EEE bios to boot from removable devices first, and then during EEE startup press ESC to bring up the boot selector menu, done.

  • There are many services and scheduled tasks which send usage stats of this RC to MS. You can either opt-out during installation, or, to be double sure (although ingrate), disable all services and scheduled tasks related to customer experience.

  • Silly tip, but as the 'Run' start menu item has been removed by default, you will have to use Win-R combo (you are probably using it already).



Everything else is pretty obvious, this is Windows afterall, so enjoy. Windows 7 looks like it very well might be MS's answer to the superiority of apples and penguins on desktops and netbooks which was becoming increasingly obvious with dated XP still being the only really used MS OS. We'll have to see how well businesses adopt this new system.

Labels: , , , ,

Sunday, February 10, 2008

RoR: Overriding Comparison Operators in Your Model

Ruby allows you to override everything. Ruby allows you to override everything using two lines of code. You just got to love ruby! This small entry is about overriding comparison operators (or, to be correct, it is about bulk-defining comparison operators for user class).

Common use case from Ruby on Rails is to define a simple model which is associating a Fixnum with some additional properties (like string name): examples are sport leagues (number), or bank account (balance), and so on. Whenever the primary objective of your model (say, League) is to store the number, you would want to override the comparison operators so that instead of that ugly code:

league.number > other_league.number
...
leagues.sort! {|a,b| a.number <=> b.number}


you would write this beautiful ruby:

league > other_league
...
leagues.sort!


But overriding each comparison operator would quickly make your model look like some java code or worse. Ruby "meta-programming" to the rescue:

Class League < ActiveRecord::Base
%w(<=> == < > <= >=).each do |operator|
define_method operator do |other|
case other.class.to_s
when "League"
self.number.send(operator,other.number)
when "Fixnum"
self.number.send(operator,other)
else
raise ArgumentError, "Illegal argument"
end
end
end
end


This not only would allow you to compare League with some other League in every possible perverted way you please, but also to compare apples and oranges, i.e. League and a Fixnum, and get an ArgumentError when comparing it to anything else.

You may find it useful to compare with a String, too, if a string attribute is sensible identifier for your model. We use send here to evaluate comparison operator for our number attribute, but you can send to String attributes just as easily (and to anything else which already has it's own comparison operators defined).

But, surely, while this code above defines 6 methods for you while keeping it DRY, there is a better way - using Comparable mixin. It would define 6 comparison methods (plus between?(min,max) method) all based on the <=> operator, and the code will look much clearer:

class League < ActiveRecord::Base
include Comparable

def <=>(other)
case other.class.to_s
when "League"
self.number <=> other.number
when "Fixnum"
self.number <=> other
else
raise ArgumentError, "Illegal argument"
end
end
end


Have fun!

Labels: , , , ,