Comment
Syntax is a purely subjective thing, some people don't like the Obj-C syntax. Personally I think that it is head and tails above the likes of C#, Java, Ruby etc which try to make things concise but end up just making code less readable.Hmmm... This sounds more like a criticism of Perl. Have you spent much time with Java or C#? One of Java's overarching design goals is readability over all else. Everything is clearly spelled out, with abbreviations being strongly discouraged (far more than in Objective C.) I think you would be hard pressed to find counterexamples. The only exception perhaps being boxing/unboxing.
Float value = 1.0f;
Single value = 1.0F;
NSNumber* value = [[NSNumber alloc] initWithFloat:1.0];
public MyClass() {
firsName="Joe";
lastName="Smith";
}
- (id) init {
if ( self = [super init] ) {
[self setFirstName:@"Joe"];
[self setLastName:@"Smith"];
}
return self;
}
Now, as for why Apple doesn't use Java or C# beyond Obj-C's dynamic nature, partly because many of the APIs in Cocoa are older than C# or Java and that there's no major benefit to rewriting all that code
Not only the Cocoa code, but that there's a huge amount of Core Foundation code underlying the OS, to which an app is linked. The code base must be HUGeE, and a rewrite would put forward motion on hold. Apple has instead moved forward.
I cringe every time I instantiate an object: MyClass *object = [[MyClass alloc] init]; Eck!
Cringe. C'mon... just do it (lol). Actually, now that I deeply understand what is going on in that two part call, it is my friend. Not all of my object instantaitions are so plain vanilla. Actually, nowadays very few are. Sometimes I invoke class factory methods to get autreleased objects, oftentimes the -init call is -initWithParamaters, and sometimes when it is plain vanilla, the two part construction reminds me about my need for memory management. I, by the way, am no fan of garbage collection, but rather am a disciplined retain-releasor. I can envision all too many ways that by not paying attention, it is all too easy to create reference loops among objects that prevent garbage collection from working. Sure, reference "cycles" (in a directed graph sense) are as easily possible in manual memory management, but for me the needed attention to memory management keeps me en-guard.
Martin said:The two part initialisation...
More correctly, the two parts are allocation and initialization, quite distinct. I know you know that :-)
This capability exists in many JVM and CLR languages including BeanShell (basically optionally typed Java), which was developed by Pat and to which I contributed. If you need this in a Java or .NET environment you simply use a language that supports it, and the tools (Eclipse and VisualStudio) provide excellent support for these languages side by side with Java and C#. Additionally, there are many excellent AOP libraries that provide the ability to intercept and route method calls.
For the aforementioned reasons, I respectfully disagree. I'm happy to learn a new language. My issues are specifically with Objective C. Today I reviewed the language specification, and it just looks...well...old, and not particularly elegant or expressive by modern standards. I cringe every time I instantiate an object: MyClass *object = [[MyClass alloc] init]; Eck!
I can understand this, especially given Apple's general philosophy. I just wish they would start anew or at least use a more recent starting point. Apple could join the JCP and contribute to Java's evolution. Its not hard. We did it. Also note that C# is an ECMA standard. Apple could also do something new, as they did with AppleScript.
Martin Pilkington: You have all the introspection tools to test before hand, but if you don't then there are methods like forwarding and dynamic method creation that allow you to handle unimplemented methods before finally resorting to an exception.This capability exists in many JVM and CLR languages including BeanShell (basically optionally typed Java), which was developed by Pat and to which I contributed. If you need this in a Java or .NET environment you simply use a language that supports it, and the tools (Eclipse and VisualStudio) provide excellent support for these languages side by side with Java and C#. Additionally, there are many excellent AOP libraries that provide the ability to intercept and route method calls.
Martin Pilkington: As for the methods, they aren't named parameters but interspersed parameters, something that in believe only Obj-C and Smalltalk do. I wrote an article on them and why they are different to named parameters.I stand corrected. Your post makes the distinction clear.
Martin Pilkington: Now, as for why Apple doesn't use Java or C# beyond Obj-C's dynamic nature, partly because many of the APIs in Cocoa are older than C# or Java...I'm sure this is the reason. Its whats already there, and people are accustom to it.
Martin Pilkington: ...and that there's no major benefit to rewriting all that code in them beyond meaning people don't have to learn a new language.For the aforementioned reasons, I respectfully disagree. I'm happy to learn a new language. My issues are specifically with Objective C. Today I reviewed the language specification, and it just looks...well...old, and not particularly elegant or expressive by modern standards. I cringe every time I instantiate an object: MyClass *object = [[MyClass alloc] init]; Eck!
Martin Pilkington: It also means Apple has control over where the language goes. Try telling MS to use a language someone else has the keys to.I can understand this, especially given Apple's general philosophy. I just wish they would start anew or at least use a more recent starting point. Apple could join the JCP and contribute to Java's evolution. Its not hard. We did it. Also note that C# is an ECMA standard. Apple could also do something new, as they did with AppleScript.
Stuart Malin: Can you then send myButton a message and tell it, at runtime, to change the method it invokes? Can you send the button a message and tell it which object it should send its message to?Yes. It would be trivial for me to enable any of these capabilities in the SDL/Swing framework because there are multiple points at which I can intercept the calls. Both the Java and .NET platforms have the ability to do introspection and dynamically generate bytecode (IL in .NET parlance) at runtime. I've worked on frameworks, compilers and interpreters (mostly for DSLs) on both platforms, and have rarely found my self saying, "I want to enable capability X, but its impossible on this platform."
button ID="myButton" do="myCoolMethod"< ...which would invoke a Java method in the controller called myCoolMethod().
© 2024 Created by Daniel Leuck. Powered by
You need to be a member of TechHui to add comments!
Join TechHui