OxyCo

November 30, 2006

Learning how to read Binary

Filed under: Objective C — atma @ 8:55 pm

Some days ago I was reading at the handbook about the left shift operator “Wikipedia link didn’t help a lot, so I asked on IRC. The result was excellent! Now, although I’m not used to use binary by any means or understand on the fly the binary numbers - which means make on the fly translation from binary to decimal - but a guy show me a way to calculate binary numbers, the clue was:

Let’s say that we have this binary number: 1001. We have a binary number (base 2) composed by 4 elements/characters. Now to find a decimal we must apply the following formula: a*3^2 + b*2^2 + c*1^2 + d*0^1. Where a,b,c,d we must substitute the binary numbers from left to right, make sure you count the last character of the binary number as 0. So the result is: 1*2^3 + 0*2^2 + 0*2^1 + 1*2^0 = 8 + 0 + 0 + 1 = 9.

Isn’t that simple? Now back to our first issue, the left shift operator - link here - shifts the first operand the specified number of bits to the left. Now I don’t understand where the hell is going to turn useful such an operator in Object Oriented programming, but I hope to find out someday.
I’m happy enough to understand binary, you know.. I never really understood the famous Geek quote: There are 10 kind’s of people those who understand binary and those who don’t I hope to be able to laugh someday with that, I’ve read it a thousand times.

November 24, 2006

Inconsolata fonts for OSX

Filed under: OSX, TextMate — atma @ 4:47 pm

After reading cosmix’s post about a font called Inconsolata I managed to install the font under MACOSX very easily, through fontbook - MacOSX application for managing fonts - and for the first time I realised the difference between different fonts. My TextMate looks more beautiful than ever! This font is amazing. Although it does not support Greek I think I’ll made it my default font under TextMate.
I am Greek as you probably realised/know so not having Greek support is not acceptable. However Raph Levien managed to find out the post and promised some support if the interest is strong enough for Greek chars. Apparently there are some issues under Windows and I didn’t tried out under GNU/Linux and/or *BSD. I’ll try it out under FreeBSD when I have to time to install it on my x86 Desktop. Try the otf file now!

November 20, 2006

MacOSX Developers Approach

Filed under: Thoughts — atma @ 5:58 pm

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.

Creating a Calculator Class

Filed under: Objective C — atma @ 5:46 pm

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

November 13, 2006

Run out of time!

Filed under: Uncategorized — atma @ 11:20 am

Oh it’s weird! Since the last post I didn’t had the time to open the Objective C manual!!! Isn’t that weird? Even now I’m writing this post from my working Office! Many things to do the last week. I hope to have some time to work with TextMate and Objective C a bit more. I’m on the 4th chapter and Objective C seems fairly easy, maybe I should wait a bit more before making this kind of statement heh!

November 5, 2006

Creating Bundles with TextMate

Filed under: TextMate — atma @ 2:13 pm

As a starter I write small programs that I’d like to see executed at once. The book has two suggestions for those who are using MacOSX:

a) Use xCode ( which is a software that I’ll need to learn somewhere in the remote future )

b) Use Gcc through command line. ( which is what I had in mind since day 1 actually )

However I felt uncomfortable having a terminal open along with TextMate just to compile programs. So I start looking for a shortcut that will do the job for me, nothing complicated: Just compile the current .m file, run it and show eventual errors otherwise the output.
I searched the manual and I found the apple-command+B shortcut which tries to compile the .m file with xCode unsuccessfully. The problem is that xCode looks for xCode-projects inside the working directory, so it does not recognize on the fly the specific file.
After that I looked at macromates for other info, because I was sure that something similar already exists. Nothing though, the Build command was bounded to xCode for .m files.
At this point I joined the IRC textmate support channel on Freenode. A found a Greek guy under the nickname cskiadas which helped me create my first bundle!
It was easier than expected! TextMate surprised me in a very positive way already! So what I did was:

Bundles -> Bundle Editor -> Edit Commands | New Commands

Following cskiadas advice I did not put the new bundle under Objective-C Bundles, I put it under my own Bundle category created by TextMate. The first thing we need to do is satisfy the Scope Selector which in my case was source.objc. Then following the GUI was easy to create a key shortcut I decide for apple-command+B which is the default shortcut for Build. I decide to watch the output in tooltip mode which is much more convenient and fancy than Document mode, which open’s another document and paste’s the output. Mr. cskiadas told me that tooltip may have issues with large text. Kept that in mind, but after all.. changing that option takes 3 seconds. Now the hard part was to put together the code that compiles & run’s the file. Mr. cskiadas helped with a short example and key feature to go peaceful with .m files.. here is the code:

	# just to remind you of some useful environment variables
	# see Help / Environment Variables for the full list
	#echo File: "$TM_FILEPATH"
	#echo Word: "$TM_CURRENT_WORD"
	#echo Selection: "$TM_SELECTED_TEXT"

	#!/usr/bin/sh  - atma 05/11/2006
	BASE=${TM_FILEPATH%.m}
	gcc "$TM_FILEPATH" -o "$BASE" -l objc

	# Simple bash check out and compile

	if [[ -e $BASE ]]
	  then
	     echo “Executing $BASE”
	     echo “”
	     exec $BASE
	else
	     echo “”
	     echo “File does not exist”
	fi

The BASE=${TM_FILEPATH%.m} variable saved me from having hard time. The %m option means “without the .m extension”. The $TM_FILEPATH variable stands for full path filename as you can imagine. The rest is simple shell code which I put together with a little goggling ( I didn’t remember the -e variable for bash’s test ) just to make it more elegant.

Now when I type apple-command+B I get the compile & run results on the fly, inside a tooltip!

tooltip

November 3, 2006

TextMate blogging & the Objective C book intro

Filed under: Objective C, TextMate — atma @ 3:44 pm

Following the this video I did not managed to post through TextMate the famous MacOSX all-in-one editor. Although the blog functionality seems quite elegant doesn’t work as it should.
First all when fetching post’s through wordpress.com it fetches my Dashboard articles and not my previous posts. I don’t know why, maybe WordPress API is not working as it should? I’m quite positive that Allan’s blog should be a WordPress blog although from the video I didn’t understand if it’s WordPress or webpress, the spelling was not clear enough plus the fact I don’t speak native English, so I can’t be sure. He uses Markdown instead of HTML though. When I post I get error cannot post to this blog or category - (401). So if anyone reading this (Hello?) has managed to use TextMate with wordpress.com please let me know. Anyway..
I purchased from Amazon the following book: Programming in Objective-C by Stephen Kochan.
The first impression is good. The book seems to be what I needed in first place and has some positive feedback at Amazon’s website.

Jeez, writing in simple html for blog post’s in TextMate is much more easy then using other editors! Actually most of my posts were written in TextEdit which I like very much for it’s power and simplicity, but it’s not an HTML editor to make an acceptable comparison!

I noticed that most of the mac programs like the one’s already mentioned, QuickSilver, VoodooPad, etc. are made in a very smart, elegant, simple yet powerful way. It’s not just the operating system, it’s the entire community that has a genius mindset :-)
uhh!!
I need to get some sleep and read a bit about instances and methods!!!

Cheerz!

EDIT: Update! I’m editing through TextMate!

My mistake was putting the this line:

oxyCo http://atma@wordpress.com/xmlrpc.php

instead of this:

oxyCo http://atma@atma.wordpress.com/xmlrpc.php

Now seems to work perfectly! :-)

EDIT2: I just purchased TextMate. Hope it’s worth the 39$!!

November 2, 2006

Hello Objective C!

Filed under: Objective C — atma @ 7:22 pm

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];

Blog at WordPress.com.