I already read some post about the why use embedded script language but I want to ask when to use it.
I have implemented an Objective-C / Javascript binding framework which allow me to write Javascript to use any Objective-C classes and methods. I found it very useful for debugging purpose because I can check / modify the internal state of my app at runtime. But I also found I still prefer to write ObjC code instead of JS code when building my app for some reasons:
- Code completion. If I want to call some
UIKit
method froom JS, I often have to check the document for its name compare to just type first few letters and let Xcode complete it for me in ObjC. - All the benefit of static typed language. ObjC is static typed and dynamic typed language so compiler can do lots type checking for me when possible.
- Performance?
- C binding to JS not ready yet (this required to parse header and generate code to expose C function, enum, struct, etc)
- More natural to write ObjC when dealing with ObjC methods. (e.g. in JS write code like
view.setEdit_animated(true, true)
compare to ObjC[view setEdit:YES animated:YES]
But I feel I should write more JS code so I can take the benefit scripting language (e.g. replace methods with bug fixes at runtime)
I am not sure which part of my app should be written in JS and which part should be written in ObjC. Any advice?
Also any design pattern can be used for embedded script language?