Well, your example shows the power of Cocoa framework. The only problem is I can not compile and run it. Following is modified version that works:
// to run: gcc -Wall -framework Foundation wcurl.m -o xwcurl && ./xwcurl
#import <Foundation/Foundation.h>
int main(int argc, char** argv)
{
NSAutoreleasePool *main_pool = [[NSAutoreleasePool alloc] init];
NSURL* aURL = [NSURL URLWithString: @"http://www.yahoo.com/"];
NSString *str = [NSString stringWithContentsOfURL:aURL];
NSLog(@"%d, %d, %d", [str length], [[str componentsSeparatedByString
" "] count], [[str componentsSeparatedByString
"\n"] count]);
[str writeToFile: @"web.html" atomically:NO];
[ main_pool release ];
return 0;
}
- I do not program in Objective-C so it may not be an optimal version
- line count is up to eleven - almost 3x of my Python code
- I fixed a few bugs to make it compile and run:
- stringWithContentsOfURL requires NSURL object so I added initialization of NSURL
- writeToFile requires two parameters
- NSLog requires %d or %u format for integers
- plus I added memory management code, #import and main()
I think it's too many details for somebody just learning to program. Python allows you to concentrate on essence of your task and not waste your time on artificial language constructs.
Majority of people that want to learn some programming will never make it. For computer science major starting with C and moving to Objective-C, C++, Lisp, etc is the right way. But it does not make any sense for "normal people" to struggle with complexity of low level languages, get frustrated and give up. If student can develop proficiency in high-level programming language he/she may learn arcane language and API as a second step.
Python was developed with goal of using it as first language, has great documentation, supported on almost all platforms and is a real programming language that may be used for broad spectrum of problems.
Plus Python is shipped as part of Mac OS X.