News for hackers. Stuff that matters.
Re:A better introduction to Objective-C by natesm on Tuesday September 27, 2011 @02:02AM (#3042078)
This is an excellent tutorial, especially compared to the other one. The only thing I took issue with was this:

    if ( [self hasPrefix:@"http://"] )
        return YES;
    else
        return NO;
The other thing that puzzled me a little was the K&R interfaces and Allman everything else, but I guess it's a consistent style. I do use K&R exclusively for blocks, so I suppose I am just as guilty.
Re:A better introduction to Objective-C by miles_matthias on Tuesday September 27, 2011 @10:23AM (#3043363)
Why do you have a problem with that when they said, "Keep in mind this is not a good implementation of URL detection. We're just trying to get the concept of categories across:..."
Re:A better introduction to Objective-C by Zev on Tuesday September 27, 2011 @02:36AM (#3042142)
What was your issue with that? It not being written as below?

  return [self hasPrefix:@"http://"];
If so, I disagree. The way it was written in the tutorial is easier to read when going into a new language — and teaches you that Objective-C uses YES and NO, rather than true and false.
Re:A better introduction to Objective-C by zoul on Tuesday September 27, 2011 @02:47AM (#3042162)
I think people should not use awkward code in tutorials and then say it was for the sake of illustrating a point. Otherwise the readers can pick up bad idioms just as in a natural language. In this case I doubt the author wanted to showcase YES/NO. And if that really was the intention, you can easily add one sentence after the code example, explaining the potentially strange BOOL type and its values.
Re:A better introduction to Objective-C by to3m on Tuesday September 27, 2011 @07:48AM (#3042846)
Anybody who can pick up Objective-C from a single HTML page is unlikely to be such a beginner that they are flummoxed, confused or unduly influenced by this code.
Re:A better introduction to Objective-C by Zev on Tuesday September 27, 2011 @02:50AM (#3042172)
The code is very easy read. And, when you're getting started, being easy to read is very important. Besides, it is still semantically correct. (Also FWIW, I didn't find it very awkward, personally.)

I might even be convinced to go a step further and say that early on, it is far more important to actually get started and avoid hitting roadblocks, then it is to write nice and pretty code. You can figure that out later on, once you're comfortable with everything.

Re:A better introduction to Objective-C by billjings on Tuesday September 27, 2011 @07:26AM (#3042794)
I think his point is that the code is written differently than it would be written in practice solely to make a pedagogical point. Tutorial code should exemplify well-written practical code in addition to whatever concept is being demonstrated.

This particular construct is debatable - I personally think it can read better to explicitly break out a boolean statement like that in some cases, especially in a simple method like in this example. I certainly wouldn't take a hostage over that opinion, though.

Re:A better introduction to Objective-C by bmelton on Tuesday September 27, 2011 @07:58AM (#3042862)
Don't confuse awkward with clever. The code that illustrates the IF conditional is far more readable than the self-returning YES or NO, where you don't even know that YES and NO are the return values.

Arguably, an ObjC programmer should know that booleans are YES and NO and not true or false, but so what? Code that can't be maintained isn't good code. Code that is developed within a team should be readable before it should be clever. if it is clever, or if it needs to be clever, then it should be commented to the degree that it is more easily understood.

I personally would rather write readable code than more comments.

Re:A better introduction to Objective-C by nolanw on Tuesday September 27, 2011 @11:54AM (#3043818)
> Arguably, an ObjC programmer should know that booleans are YES and NO and not true or false

It's just C. 0 is false, anything else is true.

Re:A better introduction to Objective-C by spicyj on Tuesday September 27, 2011 @11:34AM (#3043683)
Actually, YES == TRUE == 1 and NO == FALSE == 0.
Re:A better introduction to Objective-C by natesm on Tuesday September 27, 2011 @10:53AM (#3043493)
I think that it teaches that conditionals (or boolean constants) are "special". When I first learned to program I did similar things, and I think it held the "everything clicks" moment back.