Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sebpayne

macrumors member
Original poster
Nov 28, 2005
48
0
I'm new to programming (apart from CSS and HTML) and using the tutorials on the internet, I am thinking of developing my skills by:

1. Learn AppleScript
2. Learn Cocoa

I tried a Cocoa tutorial on Apple Developer Connection but it failed (don't know why) but the AppleScript one worked and I guess it would be good to have knowledge of both languages. If you were totally new to programming, where is a good place to start?

REALbasic looked good but I can't afford £280 for a license for it so I'm going to stick to free tools.

Thanks

Seb
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
It depends on your goals. If you want to become a good programmer in general learn the theory! If you want to become a Mac programmer learn C the Objective-C/Cocoa. AppleScript is pretty much unique in terms of syntax so will not really help you much in terms of moving to other languages/platforms so I'd view it as optional.
 

Josh

macrumors 68000
Mar 4, 2004
1,640
1
State College, PA
I'd say start with C or C++.

Learning an easier language like C will help you learn C++, Java, etc a lot more quickly.

The syntax is different in different languages, but the general concept is there. Once you learn one, picking others up is a lot easier.
 

Jordan72

macrumors member
Nov 23, 2005
88
0
Applescript is for programming how programs can be used together to produce results. I.e., lets say you wanted to always know when news about a particular subject was being broadcasted on the web. You could make a program in AppleScript to cause Safari to launch and use several searach engines for your subject. The links found then would be coppied to a text document created by AppleWorks. After Safari had performed the daily search, it could shut down. If links are found, you could cause it to set an event for your iCal, which brings up a message saying you have links. This could all be done through using AppleScript programming. AppleScript's practical benefit is pretty much limited these kind of tasks: Automating existing applicatons for a customized use.

Cocoa is used to build applications like Safari, Applworks and iCal. You wouldn't use Applescript to make Chess or some software a local company hired you to make (except, maybe a small project). You would most likely use Cocoa.

Once you know what kind of software you intend to learn to build, you'll know where to start. If you choose to learn Cocoa, it's better to start with Objective-C, because that is what Cocoa is written with. There is really only one beginners book: Programming in Objective-C by Kochan. It also teaches you the C you need to get going.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Jordan is mostly correct about AppleScript but there is AppleScript Studio which allows for building Applications with AppleScript. It uses a bridge into Cocoa iirc. It does have the downside of being called ASS. It's amazing that you don't see more programs advertising : "Built With ASS" :D
 

atari1356

macrumors 68000
Feb 27, 2004
1,582
32
If your goal is to be able to create Mac applications, I'd first learn some C programming basics.

Then read "Programming in Objective-C" by Stephen Kochan. It's a good introduction to Objective-C, and covers a bit of the Cocoa frameworks as well.

After that, you can read one (or more) of the books covering Cocoa.

(I've been learning off and on for a few years now... it's not easy, and can be intimidating. One thing I think that might help is to have some goals in mind - come up with an idea for a small application that you want to create, and work on it as you learn new things. It helps you stay motivated if you feel like you're accomplishing something as you go along.)
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
I have found that for myself, keeping myself exposed to different languages is a good idea. It might present you with different ways of thinking about problems, plus seeing a number of languages makes it easier to learn a new one when the time comes. And the time will come. Of course you will probably concentrate on a single language, but keep dabbling in others along the way.
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
if you want to program for OS X, C variants are the way to go.

For Cocoa, you will need Obj-C, for Carbon you need C++ or C.

Applescript is an easy way to handle Application specific sub-routines, but the limitation for Applescript and Applescript studio application is that you must constrain yourself to use things that other applications use. You never have the chance to create something entirely for yourself.

My opinion is to start with C++ because with this, you will never have to learn C (since C++ is a superset of C), and later, you will have an easy time moving to Cocoa by learning Obj-C.
 

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
My 2¢:
Learn C then C++ - learn about Polymorphism (SP?), Inheritance, and the like. This is a must in all OOP (Object-oriented programming) languages. And I'll throw an example cause I like to :D . Once you've learned C or C++ depending on what you want to develop, learn that API - for example for gaming I've been learning SDL and have made a Tetris program via a tutorial. I've known C and C++ for about 4 years, but never made a game with it not until yesterday. Now I'm enhancing on the game. Here's the link to that btw http://www.aaroncox.net/tutorials/ and SDL tutorials are kind of rare on the internet right now. Alright, here is some simple code that deals with classes (what basically defines OOP).
PHP:
#include <iostream.h> //include standard C++ libraries

class MyClass //create a class called MyClass
{
private: //make anything listed below private members
int c1Value, c2Value; //declared two integer values
char *nmValue; //declare a character pointer (good for strings)

public:
//now I'm going to create a constructor for MyClass
MyClass(int a1, int a2, char* a3) : c1Value(a1), c2Value(a2), nmValue(a3)
{
}
//now a destructor
~MyClass()
{
}

int returnMultiply() //return int value via function called returnMultiply
{
 return c1Value*c2Value; //returns c1Value*c2Value
}

};

int main() //main start of a program
{
 MyClass* xclass; //create a pointer to MyClass called xclass
 xclass = new MyClass(10, 15, "My New Window"); //allocate new memory for xclass via new MyClass(variable, variable, variable)
 std::cout << xclass->returnMultiply() << endl; //print out into a command or terminal window the value of class->returnMultiply();
 return 0; //exit program normally
}

Now I know most of this you won't understand right away. Learning Javascript may help with learning these key features. Umm... yeah, not sure what else to say but good luck. - Oh all this program does right now is return the output: 150
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
Soulstorm said:
My opinion is to start with C++ because with this, you will never have to learn C (since C++ is a superset of C), and later, you will have an easy time moving to Cocoa by learning Obj-C.

C++ is not a strict superset of C, you know. There is C code that won't compile with a c++ compiler.

The difference between learning C and C++ first is whether or not you want to start off learning OOP. I know many people who "know" C++ but don't even begin to understand OOP.
 

iEdd

macrumors 68000
Aug 8, 2005
1,956
4
I am a beginner and I have had quite a bit of experience with the language NQC (Not quite C), which has similar syntax functions of the true C language. NQC is mainly used for powerfully programming LEGO® MINDSTORMS™. After a few years of doing nothing, I started learning Java from just after christmas, then went back and looked at NQC again and their are many, many similarities. NQC is much easier though :p As many have recommended, a beginner who wants to learn a *real* language, should start with C or Java, then move onto C++, objective C or C# if they do windows stuff. Or so I was told.
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
sebpayne said:
I'm new to programming (apart from CSS and HTML) and using the tutorials on the internet, I am thinking of developing my skills by:

1. Learn AppleScript
2. Learn Cocoa

Just learn Java. Its a popular language that is relatively easy for novices and its used all over the place. Buy a book or better yet take a class.
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
darkwing said:
C++ is not a strict superset of C, you know. There is C code that won't compile with a c++ compiler.

The difference between learning C and C++ first is whether or not you want to start off learning OOP. I know many people who "know" C++ but don't even begin to understand OOP.
I know that. But at first it was created as such, didn't it? Anyway, the point is indeed wether you want to learn Object Oriented Programming or not. Personnaly, I think that OOP is the one way to go. C has limitations in structures, that I don't like. I found OOP disturbing at first, but later, I couldn't imagine myself not using it.

The only thing that I still find difficult is pointers and references. Although I understand their usefullness, I have trouble using them with objects... On the other hand, I still haven't been involved with C++ for 5 months yet.
 

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
Soulstorm said:
I know that. But at first it was created as such, didn't it? Anyway, the point is indeed wether you want to learn Object Oriented Programming or not. Personnaly, I think that OOP is the one way to go. C has limitations in structures, that I don't like. I found OOP disturbing at first, but later, I couldn't imagine myself not using it.

The only thing that I still find difficult is pointers and references. Although I understand their usefullness, I have trouble using them with objects... On the other hand, I still haven't been involved with C++ for 5 months yet.
CC, it is strict and has limitations, the one major thing I don't like about it, is you have to define all of your variables before any real code, at least with some compilers if I defined int way down the line, it would give me errors and that. With C++ you can define any type of data anywhere. So let's say I had a program like this:
Code:
#include <stdio.h> //c header

bool render();
int GetErrorCode();

int g_Error = 0;

int main()
{
 printf("This is a statement\n");
 if(!render())
 {
   int x = GetErrorCode();
   return x;
 }
 return 0;
}

bool render()
{
  return true;
}

int GetErrorCode()
{
  g_Error = 100;
  return g_Error;
}
That would generate errors cause int x has to be defined at the top level of main.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
I am waiting for them to provide inline variable declarations to Objective-C (or to the gcc compiler anyway), so I can do stuff like:
Code:
for (int i = 0; i < 10; i++) { ... }
Even Java can do this! It's a small thing, perhaps, but useful and I want it. :)
 

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
HiRez said:
I am waiting for them to provide inline variable declarations to Objective-C (or to the gcc compiler anyway), so I can do stuff like:
Code:
for (int i = 0; i < 10; i++) { ... }
Even Java can do this! It's a small thing, perhaps, but useful and I want it. :)
Objective-C you can't do inline!? I don't know Obj-C, but thats sad if it can't. When I made my OpenGL class (SFC_GL.h) when I used a PC, I called the functions as inline _return_type_ function_name(...)
{
//define here
}

cause I heard it makes your programs faster.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
slooksterPSV said:
Objective-C you can't do inline!? I don't know Obj-C, but thats sad if it can't. When I made my OpenGL class (SFC_GL.h) when I used a PC, I called the functions as inline _return_type_ function_name(...)
That's function inlining, which is a compiler optimization, and I believe you can specify inline functions in Xcode's C/Objective-C, but that's a completely different thing than I was talking about. I'm talking about declaring variables inside program statements. So instead of
Code:
int i = 0;
for (i = 0; i < 10, i++) { ... }
which you have to do now, you could just write
Code:
for (int i = 0; i < 10, i++) { ... }
 
add -std=c99 to your compiler flags.

That said, I don't know the position of Objective-C wrt to C99 (1999 'Standard' for the C language) maybe someone who knows can reply.

For the OP
Please ask yourself why you want to learn to program, then you will get better advice. Learning because you want to learn more about computers in one thing (go for any C type language), but learning if you have a specific programme you want to write is another (I suggest Python with no other information, knowing what you want to program is important here).

If you fall into the latter group and learn the wrong language, you will be in for a very frustrating experience.
 

Coheebuzz

macrumors 6502a
Oct 10, 2005
511
148
Nicosia, Cyprus
I am in the same position as sebpayne, am just starting to get my feet wet with low level languages and my first attempts have failed!
My only experience with programming has been/is with HyperTalk, Lingo and ActionScript. A few months ago i decided to try RealBasic and i really really liked it, very easy to learn and you can start producing *multiplatform* apps in no time! However i quickly struck its limitations so now am certain that Objective-C is the way to go because there are already build-in classes into OSX that i can use to build what i have in mind.

Also, does it really help to begin with C or C++ and then move towards Objective C? I don't want to become a programming guru, am a g designer and i just want to know enough so that i can work out solutions by myself. I mean what can Carbon do better than Cocoa in everyday examples? Sure carbon is more mature than Cocoa in terms of available classes but new stuff are added all the time.

I keep hearing good things about Kochan's book so i just bought it, i should have it by Friday! I hope his tuts are better than Apple's!
 

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
HiRez said:
That's function inlining, which is a compiler optimization, and I believe you can specify inline functions in Xcode's C/Objective-C, but that's a completely different thing than I was talking about. I'm talking about declaring variables inside program statements. So instead of
Code:
int i = 0;
for (i = 0; i < 10, i++) { ... }
which you have to do now, you could just write
Code:
for (int i = 0; i < 10, i++) { ... }
Oh that's just as bad, if not worse. No that's worse. I like being able to do that cause then if I want to call the same variable for a different for loop its in a different score. Good thing you can optimize with inline in Obj-C. *hugs C and C++ and SDL*. What about putting something like this:
Code:
void ab() //I don't know Obj-C so I'll do it in C/C++ Standard
{
cout << "Hello world" << endl;
int x = 1; //this specifically, can you declare variables any where?
cout << x << endl;
int y = 2; //this too
cout << x * y * y * y << endl;
}
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Coheebuzz said:
My only experience with programming has been/is with HyperTalk, Lingo and ActionScript. A few months ago i decided to try RealBasic and i really really liked it, very easy to learn and you can start producing *multiplatform* apps in no time! However i quickly struck its limitations so now am certain that Objective-C is the way to go because there are already build-in classes into OSX that i can use to build what i have in mind.
Realbasic is nice and easy but I quickly got tired of it's limitations. Primarily it's lack of scalability and it's bugs and the fact that you end up paying every year for the damn thing.
Also, does it really help to begin with C or C++ and then move towards Objective C? I don't want to become a programming guru, am a g designer and i just want to know enough so that i can work out solutions by myself. I mean what can Carbon do better than Cocoa in everyday examples? Sure carbon is more mature than Cocoa in terms of available classes but new stuff are added all the time.
I'd advise using objective-c/cocoa when you can and carbon when you can't. It's a lot easier to write an app in obj-c/cocoa than it is in carbon. There are some things that you can't do yet in cocoa (IIRC spotlight, core image, authorization for example) but you can include carbon code in a cocoa app. You'll find that there are lots of folks out there writing Cocoa wrappers around the nasty bits of the carbon API (because Apple hasn't got round to it).

If you plan on doing objective-C then don't bother with learning C++. It's a lot harder and most of it you won't need. Learning C would be a good idea but you don't need to be a real C guru for Cocoa. A basic understanding will probably do. So long as you understand variables, loops, conditionals etc you should be fine.

I'm not sure how you'd learn this but I think it's more important to quickly grasp how to design apps using objects than to be a real **** hot C programmer. Also make sure you read and understand the retain - release mechanism. If you get it wrong, objects vanish when you least expect (because you should have retained them) or you leak memory (because you didn't release something you should've).

Finally, In cocoa it seems that there's tons of methods to learn and loads of classes but there are patterns to the naming of them and the documentation is pretty good. When you first start out you do tend to spend a LOT of time looking at the documentation for every line of code looking for the right method! That stage should pass with a few hundred lines of code under your belt ;)
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
slooksterPSV said:
Code:
void ab() //I don't know Obj-C so I'll do it in C/C++ Standard
{
cout << "Hello world" << endl;
int x = 1; //this specifically, can you declare variables any where?
cout << x << endl;
int y = 2; //this too
cout << x * y * y * y << endl;
}
Yes you can declare variables just when you need them...this isn't pascal;) You just can't declare a variable in a 'for ( blah; blah; blah)'
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
AlmostThere said:
add -std=c99 to your compiler flags.

That said, I don't know the position of Objective-C wrt to C99 (1999 'Standard' for the C language) maybe someone who knows can reply.

Objective-C is fine with C99, there's even a checkbox in Xcode for it. I think it's madness that it's not on by default :/

slooksterPSV: so wait... you inlined ALL your methods? Do you know what that actually does?

caveman_uk: Spotlight has Cocoa API, and there are methods for converting NSImages to CIImages and back. You're right about authorization services though... such a pain :/
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.