Live data from Hacker News

In defence of Objective-C

splinter.com.au

21–30 of 122 posts

Re: In defence of Objective-C

#21

As someone who likes Objective-C a lot, I have to say this is a pretty bad defense of it. No offense, clearly we are both fans of the language, I just don't think this will convince anyone on the other side. In fact, I find very little defense of it at all in this post. It seems his fundamental argument is "its a matter of taste", which while true, in no way conveys the many "whys" of the choices made in this languag…

They could have added garbage collection if they wanted to add as much ram to the iphone as the Android phones have but I guess they already made their choice long before one could develop code for the iphone.

Re: In defence of Objective-C

#22

I wonder if I'm the only person that thinks that Xcode is the problem, not ObjC. Having experience with C I feel just fine writing code in Objective-C, but only the thought of trying to use Xcode instead of Emacs is painful. I'd love to know what Eclipse/VS/NetBeans users think about it, maybe it's easier if you're already used to working inside a huge IDE.

No, you're not the only one.

Most of the problems I've hit with iOS development are Xcode-isms.

I've recently been sent on a merry hunt to get the built-in git integration from imploding, and the project groups vs folders ambiguity has caused mistakes of the "what actual file is this name pointing too again?" variety (and this in turn leads back to the git integration issues when a file is not where you think it is).

It would also be nice if Objective-C++ was a first class citizen with regards to refactoring tools (I understand this might be hard to implement however).

Rarely has it been a problem with the actual language itself.

Re: In defence of Objective-C

#23

There is one thing in Objective-C that still gets my goat, even after 8 years of working with it: it's the lack of syntax for container-types: [NSMutableDictionary dictionaryWithConstructorIDontWantToType:...] is just a huge pain in the ass. Other problems with the syntax have been solved by introducing sugar at the right place. Why not id hash=@{ @"key" : @"value }; and id array=@[ @"value1", @"value2", @"value3"];

Please understand that to do anything in Objective C you must pass a message to an object.So when we write. MyArray *array = [[MyArray alloc] initWithObjects:@"string1",@"string2",...]; Lets understand this in two steps: Step 1) You first allocate an object of type NSArray by passing a message "alloc" to the NSArray Class object.Yes every class in objective C is really a class object in the Objective C runtime.Now th…

The poster seems to be complaining that there is not similar syntax to many scripting languages, where you can do [@"string1", @"string2"], not about two-phase message allocation; he wasn't complaining for "dictionaryWithConstructorIDontWantToType:", he was complaining against it.

In this specific case, you actually can usually use "arrayWithObjects:" (yes, the syntax that the poster didn't like), and it is frankly preferred. If you are doing alloc/init, and (as in your example) storing to a local variable, you should also send an autorelease in the same statement, so as to guarantee exception safety of allocation for subsequent code; "arrayWithObjects:" takes care of all three steps for you.

Re: In defence of Objective-C

#24

There is one thing in Objective-C that still gets my goat, even after 8 years of working with it: it's the lack of syntax for container-types: [NSMutableDictionary dictionaryWithConstructorIDontWantToType:...] is just a huge pain in the ass. Other problems with the syntax have been solved by introducing sugar at the right place. Why not id hash=@{ @"key" : @"value }; and id array=@[ @"value1", @"value2", @"value3"];

So, languages that have primitives like this typically are designed to be used by people who don't know much about algorithms, or simply don't want to be hassled with it, either now, or ever: they want to write code, they want it to "work", and they want to move on to something else; in essence, we are talking "scripting languages".

Languages that some look at as "real programming languages", in comparison, tend to not have syntax like this, and the reason why is that you often, either now, or at some point later, are going to care whether the data structure you just allocated is a red-black tree, a hash map, a patricia trie, or even an AVL tree (which I include mostly to make a point: there actually are situations where it is preferred to a red-black tree).

When this suddenly matters, you are in the situation where what you want to be able to do is to make a very small modification to areas of your code where you need to select a different algorithm, in order to get the different result; you don't want to be forced to rewrite half your code to use a different syntax just because it was slow (I mean, if you wanted to do that, you'd have written it in Ruby and then recoded it in C).

Therefore, you find that it is normally the case in languages like Java, C++, and Objective-C, that there are no "built-in container types", as you will never find a container type that is actually correct to use in an even fractional majority of the cases; in fact, most of the time, there isn't even a single obvious choice in these languages for what class to use: you find default implementations of multiple algorithms.

Objective-C, here, is no different from this concept: NSDictionary is just an interface, and can be implemented by numerous backends. Apple has a rather good implementation backing the default version, and even attempts to switch between algorithms as the data structure grows, but your code is always just a few identifiers away from choosing a different subclass in that collection hierarchy.

Re: In defence of Objective-C

#25
I love it too for its readable and descriptive method names. It is also surprisingly flexible considering its age. (I guess what I am saying is that Apple kept it up-to-date pretty well.)

Re: In defence of Objective-C

#26
I didn't find this very convincing at all. For starters, the code presentation reinforces the verbosity and difficulty working with it. Don't most languages support named parameters and in an easier to understand way? I'm not qualified to discuss memory management but that point also left me confused.

Re: In defence of Objective-C

#27
post #24

There is one thing in Objective-C that still gets my goat, even after 8 years of working with it: it's the lack of syntax for container-types: [NSMutableDictionary dictionaryWithConstructorIDontWantToType:...] is just a huge pain in the ass. Other problems with the syntax have been solved by introducing sugar at the right place. Why not id hash=@{ @"key" : @"value }; and id array=@[ @"value1", @"value2", @"value3"];

So, languages that have primitives like this typically are designed to be used by people who don't know much about algorithms, or simply don't want to be hassled with it, either now, or ever: they want to write code, they want it to "work", and they want to move on to something else; in essence, we are talking "scripting languages". Languages that some look at as "real programming languages", in comparison, tend to n…

Ah, I get it. Convenient container-syntax is only found in toy scripting languages for stupid people like -uh- Haskell? :)

Re: In defence of Objective-C

#28

There is one thing in Objective-C that still gets my goat, even after 8 years of working with it: it's the lack of syntax for container-types: [NSMutableDictionary dictionaryWithConstructorIDontWantToType:...] is just a huge pain in the ass. Other problems with the syntax have been solved by introducing sugar at the right place. Why not id hash=@{ @"key" : @"value }; and id array=@[ @"value1", @"value2", @"value3"];

This is why I do most of my editing with objective-C in xcode, while I do most of my editing with python in vim.

Tab completion of methods is very nice to have, and makes using xcode as fast as using vim for me. (now, if I could have vim keybindings with xcode tab-complete, then I'd rocket through my editing...)

Re: In defence of Objective-C

#29
post #24

Earlier quoted context omitted.

So, languages that have primitives like this typically are designed to be used by people who don't know much about algorithms, or simply don't want to be hassled with it, either now, or ever: they want to write code, they want it to "work", and they want to move on to something else; in essence, we are talking "scripting languages". Languages that some look at as "real programming languages", in comparison, tend to n…

Ah, I get it. Convenient container-syntax is only found in toy scripting languages for stupid people like -uh- Haskell? :)

Languages with macros and (often) monads allow developers to redefine the syntax and types to accomplish these goals. The point I am making here is that there is a reason why language designers make this tradeoff: it isn't at all obvious that languages should have a built-in container syntax, and when you find languages that don't you can (and should) notice a pattern.

(C++11 is actually an interesting thing to analyze regarding this tradeoff, by the way: the new "common initializer" syntax is designed to provide as much of the benefits as possible of a simplified built-in data type syntax without taking on the semantic burden of having it; however, it also does not provide syntax that ends up being entirely devoid of the type of the container.)

Re: In defence of Objective-C

#30
post #19

As someone who likes Objective-C a lot, I have to say this is a pretty bad defense of it. No offense, clearly we are both fans of the language, I just don't think this will convince anyone on the other side. In fact, I find very little defense of it at all in this post. It seems his fundamental argument is "its a matter of taste", which while true, in no way conveys the many "whys" of the choices made in this languag…

On #4: personally, I believe it is a mistake to attempt to abstract memory management from developers unless you can abstract all resource management (as there is no fundamental difference between memory mappings, file handles, database connections, or minimum-wage bicycle messengers), and in the attempt to fully abstract memory management (as in, with garbage collection) it usually becomes impossible to abstract arb…

Why don't you expand upon this and your other comments into a full-blown defense of objective C?

for the record: My preference for Smalltalk-style messaging over Simula-style objects is largely historical (having been exposed to the former first)

Post reply on HN