Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Objective C really compiled ? Isn't it more like Visual Basic / .NET runtime ? Then what prevents it to be portable to other platforms?

Syntactically it's superset of C. But since messages are sent and processed at runtime this means it cannot be a pure compiled language like c but it needs a runtime like Visual Basic or .Net runtime.

Then what prevents it to be portable to other platforms by transforming this runtime to something like .NET Framework or Java JVM ?

Note: when I say VB it's of course last version 6 which compiles to Bytecode so why do you pretend that Java or .Net are different fundamentally from VB6 except for portability it's the same principle: see Similar to Java, Visual Basic is compiled into an intermediate language called "bytecode." The bytecode is translated into x86 machine language by the Visual Basic runtime module.

Read more: http://www.answers.com/topic/visual-basic#ixzz19iJd3wjA

Similar to Java, Visual Basic is compiled into an intermediate language called "bytecode." The bytecode is translated into x86 machine language by the Visual Basic runtime module.

like image 433
user310291 Avatar asked Dec 31 '10 17:12

user310291


People also ask

Is Objective-C compiled?

Objective-C uses the runtime code compilation Objective-C isn't a fast language. The main reason is that it uses the runtime code compilation, rather than the compile time. This means that when the Objective-C object calls for another object in the code, there is an extra level of indirection involved.

Is C# a compiled language?

C# is a compiled language. To run an application, normally a developer compiles C# source code into intermediate language (IL). This way, it can be executed across different target systems. During the execution, IL code is compiled further into machine code of the current target system and CPU executes it on the go.


2 Answers

You appear to be confused between the need for runtime support for language features, and the difference between a native-compiled and VM-compiled (or interpreted) language.

Most high-level languages need some sort of run-time support. Even C has a run-time library, although on many platforms you can choose not to use some or all of it. Modern operating systems provide even more runtime support, and many languages provide OS-specific extensions that integrate these - consider dynamic loading of libraries...

Furthermore, there's nothing stopping you from building a message-passing system on top of a language that doesn't support it intrinsically. Since this is extremely common (especially for programs written for event-driven platforms), integrating it into the language can be looked at as simply factoring some error-prone busywork out of the high-level code and into the language and runtime.

Finally, both Java and most .NET languages are actually compiled - they just compile down to a bytecode that no machine implements natively, requiring the use of a Virtual Machine to actually execute them. The most performant VMs compile the code again prior to executing it - this can be such an effective technique that it has been used to build fast and efficient compiler tool-chains!

Visual Basic is a red herring here - some versions are interpreted, others are compiled, and VB.NET - like other .NET languages - is compiled to bytecode and then JIT-compiled again during execution (while superficially similar, this tends to be implemented very differently from the earlier VB VMs). If nothing else, this should tell you that a language and the means by which programs written in it are executed are not as tightly coupled as is commonly-believed...

In answer to your last question: Objective-C has never not been portable, at least in the sense that C is portable (that is to say, source-code portability). Apple uses the GCC compiler, which has been ported to a dizzying array of platforms... However, once you start taking advantage of platform-specific APIs (probably one of the best reasons for using Obj-C on Apple platforms to begin with...) you're limited to platforms that implement those APIs. Binary portability is possible in theory, but I know of no implementations.

like image 58
Shog9 Avatar answered Oct 21 '22 04:10

Shog9


It does not follow at all that message passing cannot be compiled. It merely implies that the message must be resolved to a method call at runtime. Objective-C is certainly a compiled language.

The process is described here. It is true that the initial call to a method is slower than a C++ method call, but the resolution is cached so subsequent calls are faster. Such non deterministic behaviour would make Objective-C unsuited to some applications.

Objective-C is provided as a front-end for GCC, so is highly portable. However only OSX and its predecessor NextSTEP, and iOS have an OS API for which Objective-C is the preferred language (i.e. the language the OS API is written in/for). So while it can be used on any OS that supports GCC, its usefulness on such platforms is limited.

like image 44
Clifford Avatar answered Oct 21 '22 04:10

Clifford