Posts Tagged ‘Programming’

A few words about ruby 1.9

Posted in Programming on December 15th, 2009 by atma – 2 Comments

Recently, I start messing up with Ruby 1.9 . I bought the most advertised book about Ruby 1.9 online, called “Programming Ruby 1.9 – The pragmatic programmers guide“, and I start digging a bit.

The book itself is well written in my humble opinion and absurdly well documented. But in no way this is a book for starters. This is a book for switchers, with an advanced background. Even the way the book is written is kinda backwards. That said, I did not regret buying it, although my programming experience is poor. It has excellent pointers, from what I’ve seen, it goes deep in the language idioms, deals with the latest Ruby version which is 1.9 and points out the important innovations it brings to Ruby’s 1.8 disregard. It has very good examples as already said, it’s probably the best reference you can get out there.

For starters like myself and many others, the suggested books are “why’s poignant guide to ruby” which deals is a free book under creative commons. I like to print my books, even in photocopies. For a more professional approach there’s a very good reading “Learn to Program” for 11.04 £ at amazon written by Chris Pine. Both of these books are really good written and do not require any previous experience.

There are a few positive things that stroke with ruby, compared to Objective-C. First, it’s straight forward. I was able to write small helpful programs in less than 6 hours of reading. Note that I’m a new-be programmer, although some concepts were pretty familiar such as loops, iterations, etc. Ruby’s approach is tremendously easier using methods like “each”.

Don’t forget to join the Ruby-Talk Mailing List, for help and announcements on latest Ruby gems updates, new features, new gems, etc. It’s a very good place, I found no trolls (so far), no bad language, the netiquette is followed by the vast majority of the list, so should you join, try being polite.

Scott Stevenson interview with Aaron Hillegass

Posted in Internet & technology on May 29th, 2008 by atma – Be the first to comment

Aaron Hillegass is one of the most famous book authors in the Mac community. The interview can be found here.

Programming issues. Writing a tax calculator.

Posted in Programming on August 15th, 2007 by atma – Be the first to comment

My Objective C reading doesn’t go as I would like to, but in a way proceeds. Today I forgot the ObjC manual in the military chamber, while going home, so I couldn’t read much. I decide to solve a simple self assigned exercise. Nothing complicated, it could be done in less than 4 seconds using Python or even C.
Anyway the good thing about this book is that, as Stephen Kochan explains, I’ll start programming using the specific object oriented programming mindset, avoiding some issues that more experienced programmers have when they try to learn objective C and object oriented programming. First, I’ll show you my code:

The header file

// ivacalc.h header
 
#import
#import
 
@interface TAX: Object
{
	double price;
}
 
-(void) setPrice: (int) p;
-(double) price;
 
 
@end

The main program (implementation/main function)

// Calculating the tax of a give price v1.1
// main program
// ivacalc.m
 
#import
#import
#import "ivacalc.h"
 
@implementation TAX;
 
-(void) print
{
	printf("The price is %.2f and the tax is %.2f.\nThe sum is %.2f\n", price, price * 0.19, price + (price*0.19));
}
 
-(double) price
{
	return price;
}
 
-(void) setPrice: (int) p
{
	price = p;
}
 
@end
 
int main(int argc, char *argv[])
{
	int j;
 
	TAX *myTax = [[TAX alloc] init]; // allocating and initializing a TAX-fellow class!
 
	printf("Price: ");
	scanf("%i", &j);
	printf("\n");
 
	[myTax setPrice: j];
	[myTax print];
 
	[myTax free];
 
	return 0;
}

As you can see the program above is quite simple. It does not much. The hard part was defining correctly the interface and implementation sections and the inner goal is to get more familiar with methods and classes. However the first issue I’ve encountered was the data encapsulation. Which raises the question: What would have happened if I had put the scanf code inside the setPrice method? I could change the method, in order to make the method perform all the test + scanf execution internally. I tried to do it, I wrote the code but I` didn’t manage to get the print method accept a variable that is calculated from a method within the same class of the implementation section. I’m quite that this is possible though.
The problem is, which programming style is correct? When must I write a function or perform a specific operation inside the method and not on the main() function, as a C-style program, and then must I put the more possible options inside the method? Is there a universal answer or there are many, depending on the program?
I’ll continue writing code tomorrow! Bye

Creating a Calculator Class

Posted in Internet & technology on November 20th, 2006 by atma – 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 <objc/Object.h>
#import <stdio.h>
 
@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

Hello Objective C!

Posted in Internet & technology on November 2nd, 2006 by atma – Be the first to comment

Hello Objective C!

This is my new blog, entirely dedicated in Objective C. I am a starter, never had experience with programming languages, although I was/am able to write small scripts in bash and / or python. Nothing fancy but enough to keep my GNU/Linux tuned!
So a Mac lover with a Linux background in the world of Objective C and object oriented programming! Today I wrote my first program:

Hello world

Surprise ha? :-)

The reason I choose Objective C and not C, Python, Ruby or something else is the cocoa framework which is the best environment I’ve ever seen. I bought 2 books, the first is an extensive guide into Objective C for starters – non programmers – and the second one is an introduction to cocoa framework! I hope that books will speed up the learning process. Due to my work I don’t very much free time but I’ll try to finish the book in a reasonable time.

Cya

[myObject Free];


Convalesco is using WP-Gravatar