Slashdot Mirror


Exploring the Mac OS X Object System

Philippe writes "F-Script is an integrated set of tools that makes it possible to interactively explore and manipulate Cocoa objects as well as script them using new high-level programming techniques. This new article, Exploring Cocoa with F-Script, shows you how to use some of its most impressive features and demonstrates how it can be a useful addition to your developer toolkit."

60 comments

  1. PyObjC? by Fiznarp · · Score: 5, Informative

    I've seen Cocoa scripted with PyObjC and python Cocoa bindings.

    Apple currently employs one of the maintainers of PyObjC.

    Would someone informed care to explain if/when F-Script would be a better choice?

    1. Re:PyObjC? by Anonymous Coward · · Score: 0

      Gee.. I have seen this before. How many times is this going to be posted on Slashdot. Get original. Here's on from OSNews here. How long have you been waiting to post this?

    2. Re:PyObjC? by ceoyoyo · · Score: 0

      That was my first (and last) impression too. F-Script looks like it has a nice object browser, but why didn't they write it in Python and have all the hard work done for them?

    3. Re:PyObjC? by timmy_mc · · Score: 3, Informative

      F-script enables you to send messages to entire collections of objects at the same time. i.e. "> ArrayOfThings value" fires a value message to the array causing each object within the array responds to the message however it see's fit. When you get collections of arrays of objects takking to each other clever things can happen... http://www.fscript.org/documentation/OOPAL.pdf tim

    4. Re:PyObjC? by Anonymous Coward · · Score: 5, Informative

      F-Script can be attached to a running application. F-Script has been around since NextStep and before Python existed. Any other questions?

    5. Re:PyObjC? by dushkin · · Score: 1

      Woo! Nice! I didn't know about that.

      --
      o hai
    6. Re:PyObjC? by ceoyoyo · · Score: 1

      Python can also be attached to a running application, including one not designed to have Python attached to it.

      I didn't know F-Script has been around that long. Interesting.

    7. Re:PyObjC? by Anonymous Coward · · Score: 1, Interesting

      PyObjC is great for Python programmers who want to access Objective-C libraries. However, as a native scripting language for Objective-C/Cocoa, it is not optimal. First, you have two different object models to deal with (Python and Objective-C), which introduces some impedance mismatch and complexity. Second, the Python syntax for invoking methods does not fit well with Objective-C's keyword syntax for methods.

    8. Re:PyObjC? by lisaparratt · · Score: 2, Insightful

      Um, when one is a person who doesn't like Python, maybe? We do exist, you know.

    9. Re:PyObjC? by Bastian · · Score: 4, Informative

      I've been using F-Script for a while now; it's solid, it plays very nicely with Cocoa, and includes a lot of nice time-saving syntactic sugar. Its syntax is also simple enough that I can use it for an application scripting language that users can pick up in a few minutes. The F-Script pallette for IB is also rather convenient; it means I can throw a debugging (or scripting) console into any app of mine with almost zero effort.

      I don't really care if an Apple employee is working on one but not the other; F-Script is mature enough that it's not like I need to be afraid that the project will be orphaned before it's completed or anything like that. Nor do I care if Apple has blessed PyObjC or not. Apple also put scads of time and money into what I had always heard was a rather hacked Cocoa-Java bridge, only to essentially orphan it a year ago. And dare I mention AppleScript?

      I haven't tried PyObjC, so I can't tell you if F-Script is a better choice or not, all I know is that it's a good choice. So I'll turn the question around - what makes PyObjC a better choice?

    10. Re:PyObjC? by jcr · · Score: 3, Informative

      Its syntax is also simple enough that I can use it for an application scripting language that users can pick up in a few minutes.

      It's syntax is Smalltalk, which happens to map very well to Objective-C.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    11. Re:PyObjC? by Anonymous Coward · · Score: 1, Interesting

      Nothing beats F-Script when it comes to exploring objects interactively. PyObjC does not have the kind of graphical tools shown in this article. My favorite feature is F-Script Anywhere, a tool for injecting F-Script into running applications.

    12. Re:PyObjC? by Bastian · · Score: 4, Interesting

      Right, which is a huge advantage of F-Script over what I've seen of PyObjC. The only major difference between passing a message in F-Script and passing one in ObjC is that I use parentheses instead of square brackets. PyObjC has to go through some rather unnatural contortions in order to do the same, and it kind of made the code hurt my eyes a little bit, and I could see where it could make reading others' code a bit confusing.

      I'm also wondering, does PyObjC have "tab completion" for code the way the built-in F-Script console does? I've gotten really used to that in XCode; Python would have to be a damn sight better than F-Script for the switch to it to accelerate my coding more than the loss of Code Sense-style symbol completion would slow it down.

    13. Re:PyObjC? by Bastian · · Score: 2, Interesting

      F-Script can also be plugged into an app that wasn't designed to have it attached. From what I understand, PyInjector was created by following in the footsteps of FScriptAnywhere.

    14. Re:PyObjC? by Anonymous Coward · · Score: 0

      I can envisage a boomerang effect http://tinyurl.com/sxelz

  2. How many? by andrewman327 · · Score: 5, Interesting

    I was wondering how many Mac-specific development platforms are out there. Obviously there are loads of them for Windows, but how many just for Mac?

    As much as this will get me flamed, I code in Java when I am writing applications for Mac. I find it works well enough, but I am interested in becoming a bit more versitile.

    --
    Information wants a fueled airplane waiting at the hangar and no one gets hurt.
    1. Re:How many? by ceoyoyo · · Score: 2, Informative

      Take a look at Python and PyObjC. http://pyobjc.sourceforge.net/

    2. Re:How many? by LnxAddct · · Score: 1

      Do you mean APIs and SDKs like Quicktime, CoreAudio, .Mac, etc..., or something else? Regardless, coding Mac apps in Java is usually fine considering how well Apple ties Java into everything.
      Regards,
      Steve

    3. Re:How many? by sqlrob · · Score: 2, Informative

      Hasn't apple stated that they aren't adding any of the new APIs to java?

    4. Re:How many? by quadelirus · · Score: 5, Informative

      If you mean development frameworks then Cocoa is the way to go. Carbon is older and mostly included for backwards compatibility. Cocoa is the new hotness. As far as IDE's go, I use XCode2 and InterfaceBuilder. They are easy to use once you know where things are. I wish they had some sort of tabbed editor and I would reccomend dual monitors while developing due to the number of windows you will have open, but other than that it is a great product.

      A couple of notes:

      I, like you, come from a Java background and have recently begun to write native Mac apps. I use XCode and InterfaceBuilder and they work together really well to write Cocoa apps very quickly. I decided to learn Objective-C because for some reason I thought it would be idea to know yet another language, but Java-Cocoa should work just as well.

      I'm not sure if this is the same for Java-Cocoa, but in Objective-C/Cocoa the hardest thing for me to get used to was the graphical nature of the programming. In many languages you have API's that allow you to do things like Hello World programs and/or more complex programs like a simple browser without writing a line of code. You design the interface graphically and hit run and it works. The difference between most of those (for isntance JBuilder) and Cocoa development is that in JBuilder, even if you don't physically write the interface code, it gets coded to your class file as standard Java code. In cocoa this isn't the case. The interface is housed in a file called a NIB file. Your average programmer will probably not ever have to look directly at the contents of a NIB. Also connections between classes is created graphically. For instance, if you want to have a button do something when it is clicked you don't add an onclick listener anywhere in the code. Instead you have a special type of method in your controller class that handles actions and then in interface builder you control click on the button and drag it to the instance of your class and tell it to connect to the action. AFAIK, this MUST be done graphically. It can't be coded. Or at least, it is strongly discouraged. This graphical nature took me quite awhile to get used to.

    5. Re:How many? by Cygfrydd · · Score: 3, Funny

      Java-Cocoa... this would be... mocha?

    6. Re:How many? by aledwards20 · · Score: 3, Informative

      "AFAIK, this MUST be done graphically. It can't be coded. Or at least, it is strongly discouraged. This graphical nature took me quite awhile to get used to."
      This can be done through code. use the setAction:(SEL)aSelector and setTarget:(id)target methods. setTarget tells the button which object to talk to setAction tells the button what you want to say to the object.
      ex:
      defined in header
      IBOutlet NSButton *myButton;

      in some function in source file
      [myButton setTarget: self]; //or any other object
      [myButton setAction: @selector(toggleLines:)];

      where toggle lines looks like
      -(void) toggleLines: (id)button

    7. Re:How many? by JulesLt · · Score: 3, Informative

      Yes - due to lack of interest they have ceased development of the Java-Cocoa bridge. Of course I am sure that if there was a lot of interest, that decision would be reversed.

      Where people have interest in particular technologies you'll certainly see JNI libraries appearing, but most Java development on the Mac is cross-platform so didn't use the Cocoa bridge. I would imagine that building on top of the Eclipse RCP will be a popular means for many Java developers to get a closer native feel.

      --
      'Capitalists of the world, unite! Oh ... you have' (League Against Tedium)
    8. Re:How many? by lahi · · Score: 1

      No. Wiener Melange.

    9. Re:How many? by vistic · · Score: 1

      Apple has a good tutorial on their site for those who want to jump right in and figure it all out. I think you can do this with Java/Cocoa just by selecting Java as your project instead of ObjC.

      I actually did this in ObjC and it all worked fine, then tried to go back and make it Java... and it was kind of odd how it worked with Java I thought. It seems for this kind of programming model and IDE, that Objective C is better suited.

    10. Re:How many? by Bastian · · Score: 1

      On top of that, the biggest objective benefit of developing Cocoa apps in Java was taken away with the addition of a garbage collector to the Objective-C runtime.

      I suppose there's still the benefit of allowing people who already know Java to work with a familiar language, but of course OS X also provides Java developers with a set of APIs that should be much more familiar than Cocoa. In a sense, the Cocoa-Java bridge was always a solution in need of a problem.

    11. Re:How many? by JulesLt · · Score: 2, Informative

      The main and obvious one is Cocoa. While NextStep was available on many platforms and GnuStep continues to be, Cocoa has advanced a long way since. For all practical purposes, Objective-C is pretty much a 'Mac-only' language.

      Others that spring to mind :
      WebObjects - was cross-platform for a while, and in a weird way still is (the run-time was C++, now Java, but the only way to get a licence is with OS X server, and the development tools are now Mac specific). Front-ends can be Java or Browser clients.

      OSA - this is 'Open Scripting Architecture' - it is the framework for adding scripting languages to OS X. The main example is AppleScript, but Python and JavaScript (Late Night Software) are also available on top of OSA. Any application that is said to be 'AppleScriptable' is in fact exposed via the OSA, so this does make it a high-level development platform, useful for sticking applications together (obvious one is glueing together a BitTorrent client, video conversion software and iTunes to auto-convert files for a video ipod).

      Quartz Composer - if you have Tiger development tools, fire this up. It's an interesting way to develop graphics components, which can then be used as plug-ins in apps that support them. Having looked at Motion, you can see how much Motion is simply a friendly UI over Quartz, while Composer is a much more raw version.

      Widgets - Apple's Dashboard widgets allow a mix of technologies, but mostly Javascript. (You can have a Quartz based widget, and you can fire off OS commands from a widget too). Even has it's own IDE, separate to XCode - DashCode. Not officially out but easy to find online.

      Unix shell scripting - obviously not Mac specific, but Darwin and OS X do have unique commands - i.e. you CAN use them for Mac-specific development.

      Odd proprietary languages : FutureBASIC is still hanging in there, as a Mac only version of BASIC. (RealBASIC is cross-platform and now-OO). I've certainly seen reviews of other similar tools, like a 3D-games writing language, but they are not things I tend to keep in mind. Took me a bit of Googling to even find the name of FutureBASIC.

      If you want a direction to go in, I would suggest Obj-C and Cocoa. If you want to get better closer to the native layer than you can with Java it's definitely the way to go.
      One observation : There appear to be a growing number of apps that just use WebKit to throw up a browser window and then use HTML/JavaScript for the actual application code. Each to their own - I guess it makes sense if you mostly have web development skills.

      --
      'Capitalists of the world, unite! Oh ... you have' (League Against Tedium)
    12. Re:How many? by quadelirus · · Score: 1

      I figured there must be a way to do it but I didn't know how, thank you. When I started out in Cocoa programming all tutorials and books typically had you connecting things like that in the interface builder. Do you think programming graphically or by hand is better when dealing with Cocoa?

    13. Re:How many? by squiggleslash · · Score: 1

      Not that it matters much, but Cocoa is arguably older than Carbon. Carbon dates back to the Windows port of Quicktime in the early nineties, where it started out as a compatibility library before becoming a more general purpose Mac OS-like API for Mac OS X. Cocoa, on the other hand, is simply the name given to the most recent revisions of the OpenStep API, dating back to NEXTSTEP in the late eighties.

      Both APIs have equal access to the operating system. Apple's attempts to make Cocoa a little more language generic haven't been entirely successful, with the Java APIs deprecated. Carbon still seems to be largely C++ specific though I can see that if someone wanted to, they could make Carbon a little more available to other languages than it is now (the will is lacking, not the capability.) I guess you should make your choice on the basis of the language you want to use.

      --
      You are not alone. This is not normal. None of this is normal.
    14. Re:How many? by aledwards20 · · Score: 1

      With Cocoa, I strongly encourage using Interface Builder especially if you are learning. I typically only use Interface builder to build my UI so it retains the Aqua look and feel and make the GUI easier to maintain. You could do it all by hand if you wanted to, and there isn't any thing wrong with that. I have mixed using NIB with coding portions of the UI by hand and it works fine (personal projects). I haven't done a complete UI in code yet because you miss some of the benefits of Interface Builder and NIB files. Interface Builder creates all the objects for your GUI and serializes them in the NIB. Your app automatically reactivates the objects when its opened and connects objects to the appropriate targets and actions. This is wonderful for quickly creating apps that take full advantage of Cocoa controls and formatting because you don't have to write the code to initialize the UI and specify control behavior. Look in the object inspector to see all of what you can do without code. Coding by hand, you take on creating the GUI objects, initializing all the objects, connecting all the components, setting up the look and feel, etc. Try to create a NSButton by hand, it doesn't look like a Interface Builder NSButton at first. Also suppose the layout of the UI changes but you keep all the controls. If you code by hand you have to manually move all the components with code. In Interface Builder, just move the controls save the NIB and you are done, no change in code.

    15. Re:How many? by toph42 · · Score: 1

      Carbon is older and mostly included for backwards compatibility. Cocoa is the new hotness.

      Just to clarify, Cocoa is not newer than Carbon. It was created for Mac OS X 1.0 as a way for traditional Toolbox applications (i.e. MacOS Classic apps) to be compiled to run natively in Mac OS X. Cocoa, however, is simply a new name for the API that NeXT computers used from 1985. Don't get me wrong. Cocoa is the new hotness, just because it's the first-class API for Mac OS X, getting the most love and care from Apple's engineers. Cocoa is what you want to use for new development. Carbon is just a way to shoehorn old code into a modern environment.

    16. Re:How many? by toph42 · · Score: 1

      Just to clarify: Apple said they will not add new APIs to the Cocoa-Java Bridge. They will still support 100% Pure Java with the JRE, ongoing.

  3. Cringely? by Jerk+City+Troll · · Score: 5, Funny

    Is that you?

  4. First object to check out... by Gattman01 · · Score: 3, Funny

    ...is the trash can?

    Or is that Vista I'm thinking of?

    1. Re:First object to check out... by Mad+Marlin · · Score: 3, Funny

      Recycle bin: cuz MS is more eco-friendly.

    2. Re:First object to check out... by Gattman01 · · Score: 1

      1's grow on trees, but 0's are precious resource which need to protect.
      If people other then Microsoft don't start doing the same thing, there won't be any 0's left for our great-grandchildren.

      Won't someone please think of the children?

    3. Re:First object to check out... by FluffyWithTeeth · · Score: 1
      Heh, I actually fiddled with the settings so that my Trash is renamed, "INFERIOR!"

      Man, I'm sad...

  5. Looks nice... by Ant+P. · · Score: 1, Flamebait

    ...but is giving everything access to everything else in this way safe?

    1. Re:Looks nice... by Anonymous Coward · · Score: 1, Interesting

      That's was a pretty vague question, so I can only give a vague answer. In general Objective-C will favor power and flexibility over "security", and no classes or methods are truly private.

    2. Re:Looks nice... by Profane+MuthaFucka · · Score: 2, Funny

      It's safe in one way - you can say "F-script" on TV without getting fined by the FCC.

      --
      Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
  6. Tabbed editor by Jord · · Score: 3, Informative

    Just an FYI, you can get the same functionality as a tabbed editor in XCode by setting the editor to use only one window. Double click on a file in XCode, then on the right side of the toolbar is a button which will change the editor mode and open all of the editors in one window. Then you can use Control-1 to switch between editors.

    Not sure if you were aware of that feature.

  7. Cocoa MVS bindings by Fnord666 · · Score: 3, Informative
    AFAIK, this MUST be done graphically. It can't be coded. Or at least, it is strongly discouraged. This graphical nature took me quite awhile to get used to.

    InterfaceBuilder makes the bindings in the MVC architecture for you when you connect them graphically. Once you get the hang of which object creates the event and which object should receive it then this becomes very straightforward. That being said, you can code by hand if you wish. I don't have the reference on me, but I believe the Hillegass book
    "Cocoa(R) Programming for Mac(R) OS X (2nd Edition)" demonstrates coding an example application this way.

    --
    'The tyrant will always find pretext for his tyranny.' - Aesop's Fables
  8. Bzzt. Wrong. by wandazulu · · Score: 4, Informative

    Um...have you done any programming on the mac, AC? Carbon is the cleaned up legacy API of the pre-OSX days. The idea was that you wrote to Carbon when developing your OS9 app, and then it should pretty much run unmodified in OS X (presuming a recompile to make it OS X native lest your app fire up the classic layer).

    In that regard, Carbon is meant to run on other platforms only if you consider OS9 another platform. I think you are thinking that Objective C is somehow a bastardized version of C. It's not; Objective C is the full C language with additional object-oriented components a la C++, but not to the extreme that C++ takes it. Plus, Objective C gives you run time typing, which C++ does not provide (static, compile-time typing). This makes it very easy to get information about objects and is the basis of the key-value system that runs most of Cocoa. Objective C is inspired by Smalltalk and uses a number of its concepts whilst C++ was influenced heavily on Simula2 (I'm pretty sure). Regardless, both can call strncpy(), malloc() etc. if you want.

    If you want write truly cross-platform C, you write to the standard C API *only* and let the users get their input and output via stdin and stdout. Not very graphical, but hey, you want cross platform, right?

    1. Re:Bzzt. Wrong. by spitzak · · Score: 2, Interesting

      The original poster was talking about making portable GUI code. You cannot use Cocoa, because that basically means you are using a Mac-only toolkit (GNUStep(?) is the only attempt to fix this I know of, and it isn't anywhere close yet). You instead use the interface to some portable toolkit, all the ones that are Linux+Windows have or are working on OS/X versions. As far as I can tell they *all* use the Carbon API. You would think Cocoa could be used, at least to create a blank Cocoa window and draw the tookit's widgets inside it, but there seems to be significant overhead and complexity in using Cocoa, and excessive differences from X/Windows, so that Carbon is preferred.

      So the original poster was exactly correct, you use Carbon if you want to port your program.

    2. Re:Bzzt. Wrong. by Viol8 · · Score: 0, Troll

      >If you want write truly cross-platform C, you write to the standard C API *only* and let the >users get their input and output via stdin and stdout. Not very graphical, but hey, you want >cross platform, right?

      You're new to unix arn't you? He could use many of the X windows libraries that use a C API
      which will then run on (probably) all versions of unix. Apple include an X windows layer
      if you wish to use it instead of their wierd home-brew GUI system and Objective-C language
      which no one apart from Mac users and a few ivory tower university types bother to waste
      their time with.

    3. Re:Bzzt. Wrong. by Anonymous Coward · · Score: 0
      The parent isn't really a troll. I know I'll get flamed, but Objective-C is a weird thing, IMHO. When we were forced to to port our app to OSX because some sales guy used that as an excuse for not selling, we ported using Carbon. We examined using Objective-C and Cocoa, but the integration issues with our existing C++ codebase was ridiculous. Objective-C can't handle C++ exceptions, etc. etc. Bad things happen.

      Carbon was much better. Our port wound up using the BSD layer as much as possible for the code code, and Carbon for the UI. It works pretty well, and is mostly the same as the Windows version. I'd love to have a sales guy claim they needed a Linux version! That'd be fun, and a lot easier, except for the audio...

      2 years later, and our Mac sales are still 1% of our Windows sales... in the education market!

      Posting anonymously to keep the zealots from killing my karma!

  9. Live Testing is Where F-Script Really Shines by krisamico · · Score: 3, Interesting

    I have used F-Script to write tests for my applications for quite some time. In fact, pretty much everything I write has an F-Script console built into it when DEBUG is on. Naturally, OCUnit is nice for built-in unit test, but I really like being able to write an impromptu test into the F-Script console real quick to exercise some newly written or changed code. My clients often do not give me much time for writing enough built-in tests, so F-Script helps me pick up the slack with convenient, live testing. On the bad side, with F-Script, you are relegated to writing non-portable tests with odd, SmallTalky syntax, but for me it is an acceptable compromise for such a good, free (as in beer), on-the-fly testing tool. I don't remember having thanked Philippe for making it available. Thanks, Philippe!

    1. Re:Live Testing is Where F-Script Really Shines by Bastian · · Score: 1

      That's how I tend to do all of my testing, too. When I started combining an F-Script console with the "Fix" button, debugging became almost fun. I can just keep poking and prodding at a bug until I pin it down without having to worry nearly so much about continually dragging the program back to the conditions where the bug came out or any of that, because I can bang out an F-Script block that does that on the fly for me, and then tweak it as needed without ever having to restart the program.

  10. Re:The Future Of OS X by jcr · · Score: 2, Insightful

    Are you the same AC that was trolling this on Digg.com?

    Sure, MS needs to do something smarter than repeat the Longhorn disaster, but I really doubt that BG and Monkey-boy have the guts to admit that they can't ship a major revision to their OS anymore.

    -jcr

    --
    The only title of honor that a tyrant can grant is "Enemy of the State."
  11. misleading by m874t232 · · Score: 1

    The article seems to be more about exploring class libraries, not "the object system" (which would mean low-level analysis of how methods are invoked etc.).

    Furthermore, there is little that is OS X specific about either the class libraries or the object system: the object system comes from Smalltalk, via Stepstone, and the class libraries come from NeXT and borrow heavily from Smalltalk and also exist in GNUStep (and, yes, people are working on porting FScript to GNUStep).

  12. Impressive by Anonymous Coward · · Score: 0

    I was not aware it was possible to do things like that with Objective-C. It's neat.

  13. Other scripting environments by Anonymous Coward · · Score: 0

    There are several other scripting environments for Cocoa, including bridges for Ruby, Python, Perl and Lua. AFAIK they don't have graphical tools like those provided by F-Script for playing with Cocoa objects.

  14. Re:Do you love my penis? by Anonymous Coward · · Score: 0

    ugh, I can't believe Rob Malda would do such a thing. I guess that's what happens when you no longer matter.