Archive for February, 2009

Why Steve Ballmer is More Worried about Linux than Apple

Most of you have heard by now that Steve Ballmer, Microsoft’s CEO, has said that Linux is a bigger competitor to Windows than Apple is.

However, the why is a bit lacking.

Holwerda, on OSNews, says that:

With an economy that’s not doing very well, people will opt for cheaper products. Apple cannot offer those, but Linux and piracy can.

But I don’t think that does Linux justice. It’s no so much saying “Linux is good”, it’s saying “Apple is expensive.” What else is new?

So here are a few more reasons:

  • Freedom: No, not as in the Four Freedoms (though that’s a valid point too). I’m talking about the fact that people can do anything with Linux. Brown theme, blue theme. Two panels, one panel, no-panels-but-a-right-click-menu. Small and fast. Comprehensive and thorough. No crapware. No bloatware. No spyware, no malware, no expiring freeware, no expensive software. Big icons. Little icons. No icons. Pretty effects. Pretty effects turned off. The pretty effects engine removed from the system, to save space. Live CDs. Easy reinstallation. Separate home partitions. Freedom.
  • Macs are like Chocolate: Think about chocolate for a sec. You can get the really expensive $10 (or more) kind. Or you can pick up a 75c bar at a convenience store. Yes, the first is probably a bit more delicious. But, unless you’re having a really special day, it really doesn’t make sense to buy it–the 75c version is almost as good. I think Apple is having expensive-chocolate syndrome. Yes, they’re nice, and pretty, and tasty. No, they’re probably not worth that much. This isn’t just “Linux is cheaper.” It’s “Why waste so much money? Especially in this economy? After all, it’s just a computer.”
  • The Future: I think we can all agree that Linux is on a definite upward trend, as is open source software in general. Firefox went from 0 to 20% in a few years, as people began realizing that it really is possible to have great, totally-free products. The Open Document format has become a lot more common, and forced Microsoft to release the specs of their .docx format. The software world is only getting more open, and Linux is the battleship of open software.
  • Macs really aren’t that great: I’m going to get in trouble for this one. But I issued a challenge a few weeks ago, asking “What’s the Big Deal with Macs?” I got two essays er, meaty replies. But they really didn’t make me think “OMG! I g2g get a Mac!” It was more like “Well…I guess you guys aren’t quite as crazy as I thought you were.” The main arguments in the Mac vs. Linux flame are that Macs a)Just work b)Are intuitive and c)Look pretty. In most cases Linux also just works, is fairly intuitive (which is highly subjective, by the way) and I think Ballmer has realized that people will be more interested in meat, not beauty.

Now don’t get me wrong. There are still buckets of people that have a love affair with Macs. And there’s probably less people who have a crush on Linux. But Ballmer thinks, and I wholeheartedly agree, that Linux will be a much bigger threat down the road.

Share/Save/Bookmark

Comments (2)

An Object-Oriented Primer in Python: Part 2

In the first installment, we learned a bit about objects (they hold information, and do things), and how to use pre-built objects (object.method() for a method (aka function) and object.variable for a variable). Now let’s talk about making our own classes.

The class statement:

The way you make a class in Python is with…the class statement, the name of the class, and a colon. So our Dog class is:


class Dog:

Hard, isn’t it? :) And, in true Python style, everything that’s part of that class is indented. (But you already knew that, because of the colon, right? :) )

Methods

Methods are made in a very similar manner to standard functions. There’s two main differences: They require a parameter called “self”, and there’s a few reserved methods that do special things.

Our Dog class had a method called showBreed(). It looked like this:

    def showBreed(self):
        print "It's a %s"%self.breed

So we have the def statement, the name of the method, and then “self” is the only parameter. Self is kind of a tricky concept: It refers to the object that’s calling it. So when we print self.breed, we’re printing the string called breed from whatever happens to be calling it. If it helps, you can think of it as sort of a wildcard: It can be fido.breed, it can be spot.breed, it’s a placeholder to show that it’s somebody’s breed. If you don’t grok that, read it again: This was probably my biggest stumbling block when I learned it. Now that you have that cleared up, realize that you also need to put self in as the first parameter for every method you define, but that when you actually call, the method, you pretend it isn’t there. Maybe some error messages would help:

>>> class Error:
    def cry(self):
        print "Method called"

>>> e = Error()
>>> e.cry()
Method called
>>> e.cry(self)

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    e.cry(self)
NameError: name 'self' is not defined
>>> class OtherError:
    def cry():
        print "Other method called"

>>> o = OtherError()
>>> o.cry()

Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    o.cry()
TypeError: cry() takes no arguments (1 given)

So, as you can see, calling a method with “self” raises one error, and defining a method with no “self” raises another one when it’s called–when you call it Python automatically includes the “self” (cry() takes no arguments  (1 given)).

__init__():

Now we come to one of the most important methods: __init__(): Observe:

>>> class Blog:
    def __init__(self, name):
        self.name = name

>>> RmI = Blog("Rannsaich mo Inntinn")
>>> RmI.name
'Rannsaich mo Inntinn'

__init__ (you can call it a constructor if you want) is called as soon as an object is initiated. Note how I never explicitly called it. The astute may have noticed that when I created the RmI object, it’s arguments matched __init__’s perfectly–the self is implicit, and the name is “Rannsaich mo Inntinn”. The very astute may have noticed that, actually, Blog was defined with no arguments in the beginning (you can have class Blog():, and put stuff in the parentheses, but that’s called inheritance and is a topic for another day).

You also see __init__ doing something it does a lot, doing self.xxxx = xxxx. This takes the xxxx (alright, in this case it’s name) parameter, and gives it a home as part of that object. Because if we didn’t do self.name = name, whatever value name was would get deleted as soon as __init__ was over, and there’d be no way of using it in other methods. Of course, you can use that elsewhere to, in Part 1 we manipulated self.breed directly, and you can also change self.xxxx from other methods. But __init__ is really the best for, um, initializing them.

Once you swallow all of that, go back to that Dog class, and see if you can write it. You know all of the components–try fitting them together. If you need help, post it in the comments.

—————

Here’s my Dog class, which you really shouldn’t be looking at, but…

class Dog:
    def __init__(self, breed):
        self.breed = breed
    def showBreed(self):
        print "It's a %s"%self.breed
    def changeBreed(self, breed):
        self.breed = breed
-----------

And so ends the series. There’s a lot of things I haven’t covered–the __del__ method, polymorphism (having the same method name do something different depending on what class it belongs too), inheritance (I couldn’ve had a Pet superclass, with name, breed, etc. and then Dog and Cat subclasses that inherited methods and attributes from Pet, but had some of their own (i. e. Dog.woof(), Cat.washBody()…) and a bunch of other stuff. But this is really all you need to know to do well–everything else is just very important icing. And there’s certainly enough tutorials out there for that.

Share/Save/Bookmark

Comments (7)

An Object-Oriented Primer in Python: Part 1

I’ve read several tutorials on Object-Oriented Programming (OOP), and none of them has been as clear as I thought they should be. So it took me a long time to figure out OOP, and now I feel like I should pass on the knowledge. Here it is:

Objects

One of the main difficulties in OOP is thinking about it. So start trying to wrap your mind around an object. Basically, an object is a specialized data structure than can hold information, and do things with it. In other words, it’s a thing represented by code. And you aren’t limited to just one thing, you can have as many as you want, just as you can have as many numbers, lists or dictionaries as you want.

Holding Information and Doing Things

You can give objects attributes. What’s even cooler is that you can access them really specifically:

fido = Dog("Golden Retriever")
fido.breed

Assuming you’ve made a “Dog” class, fido.breed will be a string saying “Golden Retriever.” You can also change the data (it’d be pretty pointless if you couldn’t…) :

>>> fido = Dog("Golden Retriever")
>>> fido.showBreed()
It's a Golden Retriever
>>> fido.breed = "Labrador"
>>> fido.showBreed()
It's a Labrador
>>> fido.changeBreed("Dalmatian")
>>> fido.showBreed()
It's a Dalmatian
>>> fido.breed
'Dalmatian'

Here we make a Golden Retriever named fido. We have it call a method (OOP-speak for function) to say what breed it is, and then change it’s breed variable to “Labrador.” After that, we use a different method (yes, objects can have multiple methods) to change the breed to “Dalmatian,” and have fido tell us that he is, in fact, a Dalmatian. If you feel like having to prefix everything with “fido.” is annoying, don’t worry: There’s a reason. We could just as easily have:

>>> fido = Dog("Golden Retriever")
>>> spot = Dog("Mutt")
>>> fido.showBreed()
It's a Golden Retriever
>>> spot.showBreed()
It's a Mutt

If we just used a generic ‘showBreed()’ method, Python wouldn’t know whether we were talking about fido or spot, or some other dog. The <name><dot> system is a pretty efficient way of telling Python who’s doing what, or who’s remembering what.

Look back over this section and make sure you understand it well: We made an instance of the Dog class, which held information (fido.breed) and did things (fido.showBreed()), we also made another instance of the same Dog class (spot), which held different, but similar information (Mutt instead of Golden Retriever), and did similar things (said what breed he, spot, was, as opposed to what fido was).

Obviously stuff can get a lot more complicated, but if you understand that, you’re doing fine!

~Read Part 2 to learn how to make classes~

Share/Save/Bookmark

Leave a Comment

Free Hosting from Microsoft: Another Ecstatic Darnit!

Today I learned that Microsoft, in an effort to kickstart their new Office Live program, is giving away a domain name registration, hosting, and email.

Let me say that again:

Microsoft is giving away something really nice. And it isn’t even something that has “hooks”–as far as I can tell, it’s just plain free.

They must be desperate.

I’d also like to point out one other thing: It does have a hook.

To use Microsoft Office Live, your computer must meet one of the following requirements:

  • Microsoft Internet Explorer 6 or 7, running on Microsoft Windows XP, Windows Server 2003 or Windows Vista. You can download Internet Explorer from the Windows Internet Explorer page.
  • Mozilla Firefox running on Windows XP, Windows Server 2003, Windows Vista, or Mac OS X 10.2.x and later. You can download Firefox from the Firefox download page.”

Why, Microsoft? Why? I can’t get angry for not supporting a free (as in speech and beer, not as in webhosting) browser–they let you use Firefox. I can’t get angry for requiring the use of Windows–they allow Mac OS X. So why in the name of kumquats don’t they allow Linux!? I can think of no technical reasons. It’s not even like it saved them work–they wrote more code to block Linux users. It’s plain, and it’s simple: Microsoft has a vendetta against Linux (which is not news), and they will do anything to make the life of a Linux user as difficult as possible (which is usually still easier than it would’ve been on Windows :) ).

So now I either have to reboot into XP, a waste of time, or download User Agent Switcher, that Firefox addon that lets me pretend I’m a Windows user running IE, which is a waste of time and system resources [insert crack about XP and system resources here :) ]. Or I can pull my other laptop out (which only runs XP due to hard drive restraints), find a wireless card, boot it up, gnash my teeth as it deals with five years of system bloat, and then sign up with that.

So when I do sign up, I’m not going to be thinking “Aw, isn’t Microsoft nice, giving me this domain name and webspace?” I’ll be thinking “Who thought it was a good idea to put me through this?”

Well played, Microsoft, well played.

Share/Save/Bookmark

Comments (4)

Using Dia for Diagrams

I’ve written an article for Free Software Magazine explaining how to use Dia, you can read it here.

Share/Save/Bookmark

Leave a Comment

Source for Prime Number Checking

Back in November, I posted about how C was tangibly faster than Python.

Today, I got a comment (don’t look for it, it’s on the old site) asking for the source code.

So here’s the original, in C:

#include <stdio.h>
#define VERSION “1.0″

//Runs a prime check on a given integer
//Returns 1 if prime, 0 if composite
int isPrime(int prime)
{
int count=2;

//Special cases:
if(prime==1)
{
return 0;
}
else if(prime==2)
{
return 1;
}
else
{
while(prime%count != 0 && count*count <= prime)
{
count++;
}
return (prime%count==0)?0:1;
}
}

//Print version information
void printVersion()
{
printf(”Primality checker version %s\n”, VERSION);
printf(”Compiled on %s %s\n”, __DATE__, __TIME__);
}

int main()
{
int i=1;
const int max_prime=2500;

printVersion();

for(i=1; i<max_prime; i++)
{
if(isPrime(i))
{
printf(%d is prime\n”, i);
}
else
{
printf(%d is not prime\n”, i);
}
}
return 0;
}

and here’s my Python port (and it doesn’t even have printVersion())…

def isPrime(prime):
    ”’Runs a prime check on a given integer
    Returns 1 if prime, 0 if composite”’
    count=2;
    if prime==1:
        return 0;
    elif prime==2:
        return 1;
    else:
        while prime%count != 0 and count*count <= prime:
        count += 1
        if prime % count == 0:
            return 0
        else:
            return 1
max_prime=2500
for i in range(1, max_prime + 1):
    if isPrime(i):
        print%d is prime\n” %i
    else:
        print%d is not prime\n” %i

However, I’d also like to point out that the C version is 55 lines long, and the Python one is only 21. Yes, that’s counting braces. Yes, that’s counting printVersion(), and yes, that’s counting stuff like include <stdio.h>, and int main(). But it’s still impressive.

(PS: If somebody knows of  a better way of pasting code, let me know).

Share/Save/Bookmark

Comments (6)

Ah, gedit!

People lose sleep, friends, and flesh over the Vi(m) vs. Emacs editor war.

I try not to engage in flame wars like that–they’re not very constructive–but I would like to highlight another great editor: gedit.

No, it’s not nearly as powerful as Vim, and I suppose it’s not as powerful as Emacs, but it’s very user-friendly, and is just downright awesome.

So give it a try, you may be surprised!

Share/Save/Bookmark

Leave a Comment