Convalesco

Growing stronger every day!

Archive for November 20th, 2006

MacOSX Developers Approach

with 2 comments

Scott Stevenson wrote an interesting article about the approach of most MacOSX developers. As I mentioned before, this is one of the key reasons I choose this platform and programming language. The hack value that most OSX applications have these days is above everything else. I’m flirting with the idea of a FreeBSD desktop with beryl support for fancy graphics. I’ve seen many YouTube video’s. It’s nice but the interface still misses the fresh feeling that Aqua gives. Not to mention of course other problems that Linux has in the desktop field (bad implementation, buggy applications, not unique interface, etc), I have no previous experience with FreeBSD but I think that the Desktop environment is unique for GNU/Linux and BSD’s.
However Stevenson deals with the entire topic in a very interesting way. The conversation that follows through comments is also very interesting.

Written by Panagiotis Atmatzidis

November 20th, 2006 at 5:58 pm

Posted in Uncategorized

Creating a Calculator Class

with 5 comments

Creating a calculator class in Objective C is not an easy task! Oh, c’mon sure it ;-) . I’ve been reading about operators lately. Arithmetic operators, bit operators, assignment operators etc. The fact that many of these things were known helps me gap the lack of time to proceed with reading as I wanted too. Here is my last code:

#import 
#import 

@interface Calculator: Object
{
	double accumulator;
}

// accumulator methods

-(void) setAccumulator: (double) value;
-(void) clear;
-(double) accumulator;

// arithmetic methods

-(void) add: (double) value;
-(void) subtract: (double) value;
-(void) multiply: (double) value;
-(void) divide: (double) value;

@end

@implementation Calculator

-(void) setAccumulator: (double) value
{
	accumulator = value;
}

-(void) clear
{
	accumulator = 0;
}

-(double) accumulator
{
	return accumulator;
}

-(void) add: (double) value
{
	accumulator += value;
}

-(void) subtract: (double) value
{
	accumulator -= value;
}

-(void) multiply: (double) value
{
	accumulator *= value;
}

-(void) divide: (double) value
{
       accumulator /= value;
}

@end

int main (int argc, char *argv[])
{
	Calculator *calc;

	calc = [[Calculator alloc] init];

	[calc clear];
	[calc setAccumulator: 100.00];
	[calc add: 200.00];
	[calc divide: 15.00];
	[calc subtract: 10.00];
	[calc multiply: 5.00];

	printf("The result is %g\n", [calc accumulator]);
	[calc free];

	return 0;
}

Okay, pretty simple you’ll say! But it’s not! Actually for the first time some things came natural! The allocation and initialisation of memory, I didn’t even think about the right syntax after the first line [calc clear]; which helped write the program quickly. However I made some mistakes the first I wrote the program. The first one was not paying attention that the accumulator was of type “double” and not “void” which caused some warning but not fatal errors

Written by Panagiotis Atmatzidis

November 20th, 2006 at 5:46 pm