<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cappuccino Blog &#187; Objective-J</title>
	<atom:link href="http://cappuccino.org/discuss/category/objective-j/feed/" rel="self" type="application/rss+xml" />
	<link>http://cappuccino.org/discuss</link>
	<description>Home of Cappuccino and Objective-J</description>
	<lastBuildDate>Wed, 25 Apr 2012 05:40:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Cappuccino 0.9.5</title>
		<link>http://cappuccino.org/discuss/2011/11/16/cappuccino-0-9-5/</link>
		<comments>http://cappuccino.org/discuss/2011/11/16/cappuccino-0-9-5/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 21:03:14 +0000</pubDate>
		<dc:creator>Alexander Ljungberg</dc:creator>
				<category><![CDATA[Cappuccino]]></category>
		<category><![CDATA[Objective-J]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Update]]></category>

		<guid isPermaLink="false">http://cappuccino.org/discuss/?p=1210</guid>
		<description><![CDATA[Today we are extremely excited to announce Cappuccino 0.9.5, featuring over 90 new features and improvements in addition to numerous bug fixes. Here are some of the new features we think you&#8217;ll really like. Modern scrollbars Cappuccino now features new scrollbars which fade away automatically when not in use, giving more space for the content [...]]]></description>
			<content:encoded><![CDATA[<p>Today we are extremely excited to announce Cappuccino 0.9.5, featuring over 90 new features and improvements in addition to numerous bug fixes. Here are some of the new features we think you&#8217;ll really like.</p>
<h3>Modern scrollbars</h3>
<p>Cappuccino now features new scrollbars which fade away automatically when not in use, giving more space for the content of your scroll views. If the user&#8217;s browser does not support or use overlay scrollbars, Cappuccino automatically detects it and falls back to old style scrollbars.</p>
<div style="text-align: center;">
<p><a href="http://cappuccino.org/learn/documentation/interface_c_p_scroll_view.html#aa47001712e1531cf3430d9923cc720cf"><img class="aligncenter size-full wp-image-1227" title="scrollview-overlay" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/scrollview-overlay1.png" alt="" width="379" height="201" /></a></p>
<p><a href="http://cappuccino.org/learn/documentation/interface_c_p_scroll_view.html#aa47001712e1531cf3430d9923cc720cf"><img class="aligncenter size-full wp-image-1226" title="scrollview-legacy" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/scrollview-legacy.png" alt="" width="379" height="201" /></a></p>
</div>
<h3>Documentation Overhaul</h3>
<p>The Cappuccino documentation has not only been extended but also visually refreshed. Many more classes and methods are now in the documentation and it&#8217;s an easier read.</p>
<div style="text-align: center;"><a href="http://cappuccino.org/learn/documentation/"><img class="aligncenter size-full wp-image-1223" title="doc small" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/doc-small.png" alt="Cappuccino 0.9.5 documentation screenshot." width="400" height="302" /></a></div>
<h3>Popover Widget</h3>
<p>A popover control is a small window that appears to &#8216;come out&#8217; of a part of your user interface, and which remains attached to it until the user dismisses it. It&#8217;s an easy way to ask for extra information when that &#8216;create&#8217; button is clicked, or to show a list of individually selectable downloads when the &#8216;downloads&#8217; button is clicked.</p>
<div style="text-align: center;"><a href="http://cappuccino.org/learn/documentation/interface_c_p_popover.html"><img class="aligncenter size-full wp-image-1219" title="popovers" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/popovers.png" alt="A CPPopover control." width="457" height="227" /></a><br />
<span style="font-size: 10px;">CPPopover originating from a button.</span></div>
<h3>Level Indicator Widget</h3>
<p>A level indicator shows a discrete graduation from &#8216;empty&#8217; to &#8216;full&#8217;, useful for certain gauges like space usage. Level indicators can also be editable and can be placed inline in table cells.</p>
<div style="text-align: center;"><a href="http://cappuccino.org/learn/documentation/interface_c_p_level_indicator.html"><img class="aligncenter size-full wp-image-1234" title="CPLevelIndicator" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/CPLevelIndicator.png" alt="A series of four level indicators showing various colour coded levels." width="412" height="122" /></a><br />
<span style="font-size: 10px;">Level indicators, some in a &#8216;warning&#8217; state.</span></div>
<h3>Predicate Editor</h3>
<p>Predicates are powerful tools for encoding &#8216;search patterns&#8217;, and combined with the power of Cappuccino&#8217;s Array Controller class they make it incredibly easy to create user searchable tables or other views. The new predicate editor allows users to create their own saved searches with almost no work for the developer.</p>
<div style="text-align: center;"><a href="http://cappuccino.org/learn/documentation/interface_c_p_predicate_editor.html"><img class="aligncenter size-full wp-image-1241" title="PredicateEditor" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/PredicateEditor.png" alt="A user editable search combining various criteria." width="410" height="189" /></a></div>
<h3>Tooltips</h3>
<p>A much requested feature has been tooltips. We didn&#8217;t want to release something that wasn&#8217;t as powerful and flexible as everything else in Cappuccino and we don&#8217;t think we will disappoint. Cappuccino tooltips can be attached to any control, position themselves intelligently and support multiline tips.</p>
<div style="text-align: center;"><a href="http://cappuccino.org/discuss/wp-content/uploads/2011/11/Tooltips.png"><img class="aligncenter size-full wp-image-1231" title="Tooltips" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/Tooltips.png" alt="A yellow tooltip next to a Click Me button with multiple lines of text." width="307" height="121" /></a></div>
<h3>Stronger Interface Builder Integration</h3>
<p>If you want to easily create and edit your user interfaces using a visual editor, you have the best tool in the market available for use with Cappuccino: Interface Builder. Every aspect of the nib2cib experience has improved, with better support for fonts, smarter realignment of widgets to match Cappuccino sizes and support for more controls than ever before. Best of all, the new XcodeCapp application automatically creates an Xcode project out of your Cappuccino project and lets you place UI components with ease.</p>
<div style="text-align: center;"><a href="http://cappuccino.org/discuss/wp-content/uploads/2011/11/xcc2.png"><img class="size-full wp-image-1212" title="xcc2" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/xcc2.png" alt="XcodeCapp's menu." width="300" height="185" /></a></div>
<h3>New Installer</h3>
<p>The new bootstrap installer is much simpler to use and installs all the packages you will need by default.</p>
<div style="text-align: center;"><a href="http://cappuccino.org/discuss/wp-content/uploads/2011/11/installer-1.png"><img class="aligncenter size-full wp-image-1238" title="installer-1" src="http://cappuccino.org/discuss/wp-content/uploads/2011/11/installer-1.png" alt="Cappuccino's bootstrap.sh running in a terminal window." width="524" height="307" /></a><br />
<span style="font-size: 10px;">You know you want to.</span></div>
<h3>Notable Improvements</h3>
<p>There are too many improvements to list them all here but here are some highlights:</p>
<ul>
<li><strong>CPNumberFormatter</strong> with CPNumberFormatterDecimalStyle.</li>
<li>More powerful <strong>objjc CLI</strong>.</li>
<li><strong>CPButton</strong> continuous mode.</li>
<li>Keyboard navigation, improved submenu handling and auto validation in <strong>CPMenu</strong>s.</li>
<li>Support for <strong>pattern fills</strong> when drawing using CG.</li>
<li>Many new <strong>bindings</strong> features and optimisations, including CPNullPlaceholderBindingOption, CPContinuouslyUpdatesValueBindingOption and better object controllers.</li>
<li><strong>CPUserDefaultsController</strong> which can be used to easily bind controls to user default keys in Interface Builder or elsewhere.</li>
<li><strong>CPColorWithImages</strong> convenience function to quickly create a `CPColor` from single, 3-part or 9-part images.</li>
<li>Support for <strong>autosaving</strong> and collapsing views towards the right in <strong>CPSplitViews</strong>.</li>
</ul>
<p>For the full list of changes, see the <a href="https://gist.github.com/1370087">Cappuccino 0.9.5 change log</a>.</p>
<h3>The Team</h3>
<p>We&#8217;re also happy to announce we&#8217;ve added <a href="http://www.annema.me/" target="_blank">Klaas Pieter Annema</a>, <a href="https://github.com/aparajita">Aparajita Fishman</a> and <a href="http://antoinemercadal.fr" target="_blank">Antoine Mercadal</a> to the core team. Their contributions to Cappuccino have been invaluable.</p>
<p><em>- The Cappuccino Core Developer Team</em></p>
<p><a href="/download">Download Cappuccino</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cappuccino.org/discuss/2011/11/16/cappuccino-0-9-5/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>CappCon 2011: Success!</title>
		<link>http://cappuccino.org/discuss/2011/06/15/cappcon-2011-success/</link>
		<comments>http://cappuccino.org/discuss/2011/06/15/cappcon-2011-success/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 05:30:47 +0000</pubDate>
		<dc:creator>me1000</dc:creator>
				<category><![CDATA[Cappuccino]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Community Highlights]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Objective-J]]></category>
		<category><![CDATA[Sofa]]></category>

		<guid isPermaLink="false">http://cappuccino.org/discuss/?p=1152</guid>
		<description><![CDATA[The first ever Cappuccino conference was a massive success. CappCon 2011 had a diverse set of attendees from six different continents and included both speakers and sponsors from Pixar, Google, Sofa, Push Pop Press, Shopify, and many others. The overall theme of the conference was &#8220;Design, Develop, Distribute&#8221;; everything you need in order to build [...]]]></description>
			<content:encoded><![CDATA[<p>The first ever Cappuccino conference was a massive success. <a title="CappCon 2011" href="http://cappcon.org" target="_blank">CappCon 2011</a> had a diverse set of attendees from six different continents and included both speakers and sponsors from Pixar, Google, Sofa, Push Pop Press, Shopify, and many others. The overall theme of the conference was &#8220;Design, Develop, Distribute&#8221;; everything you need in order to build a successful app. The talks explored this theme and covered a huge breadth of knowledge, while each one explored its topic in satisfying detail. In addition, all seven members of the core team were in the same room at the same time to answer questions from the community.</p>
<p>Two of our favorite reactions were &#8220;this is the <strong>best conference I&#8217;ve ever been to</strong>&#8221; and &#8220;CappCon was <strong>better than WWDC</strong>.&#8221;</p>
<h2>Announcements</h2>
<p>Perhaps the most exciting part of the event was the amount of projects revealed and released! If you didn&#8217;t follow the event on Twitter, here is a quick overview of announcements made:</p>
<ul>
<li><a title="Language.js" href="http://languagejs.com/" target="_blank">Language.js</a>: Objective-J author Francisco Tolmasky has open sourced his new parser generator. Language.js gives you first class error reporting as well as unprecedented speed. This new parser generator will be the basis for Objective-J 2.0, which will open many unheard-of opportunities for the language. <a title="Language.js on GitHub" href="http://languagejs.com/" target="_blank">Language.js on GitHub</a></li>
<li><a title="CoreText on GitHub" href="http://github.com/280north/cappuccino/tree/coretext" target="_blank">CoreText and CPTextView</a>: Cappuccino core team member Nick Small showed off his new implementation of CoreText and CPTextView. These amazing new controls for rich text represent the first time ever we will have desktop-class rich text on the web, which also offers feature parity with Cocoa&#8217;s NSTextView. CPTextView will be available soon, but CoreText is open source now, in its own <a title="CoreText on GitHub" href="http://github.com/280north/cappuccino/tree/coretext" target="_blank">branch in Cappuccino mainline</a>.</li>
<li>Aristo 2.0: Sofa has worked hard to provide a new version of the already best-in-class Aristo theme that we have already started to implement in Cappuccino. Aristo 2.0 accomplishes some new goals, mainly to &#8220;under-promise and over-deliver,&#8221; something we&#8217;ll talk more about in the coming weeks. <a title="Preview of Aristo 2.0" href="http://www.cl.ly/7XnD" target="_blank">Preview of Aristo 2.0</a></li>
<li>Frappuccino and RunKit: Austin Sarner and Mark Davis will be open sourcing their physics-based animation toolkit, and alternative UI framework.</li>
</ul>
<h2>The Future</h2>
<p>Of course there were many more announcements and talks, and the videos and slides for every talk will be available in the coming weeks. The atmosphere at CappCon was infectious; people were thrilled to attend, learn, talk, and interact.</p>
<p>Most importantly, everyone present was a part of the future of Cappuccino. The takeaway from the event is that Cappuccino is stronger than ever, and with some incredible things in the pipeline, it&#8217;s poised to get even better.</p>
<p>Thanks to everyone who could attend, and we hope to see everyone again next year!</p>
]]></content:encoded>
			<wfw:commentRss>http://cappuccino.org/discuss/2011/06/15/cappcon-2011-success/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Cappuccino 0.9</title>
		<link>http://cappuccino.org/discuss/2011/02/23/cappuccino-0-9/</link>
		<comments>http://cappuccino.org/discuss/2011/02/23/cappuccino-0-9/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 20:04:55 +0000</pubDate>
		<dc:creator>me1000</dc:creator>
				<category><![CDATA[Cappuccino]]></category>
		<category><![CDATA[Objective-J]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Update]]></category>

		<guid isPermaLink="false">http://cappuccino.org/discuss/?p=993</guid>
		<description><![CDATA[We&#8217;re really excited to announce the next major release of Cappuccino, Version 0.9. This massive release includes several killer new components, exciting new features for existing components, and of course a number of bug fixes. Here&#8217;s a brief overview of some of the compelling things you&#8217;ll find in Cappuccino 0.9: Bindings One of the most [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re really excited to announce the next major release of Cappuccino, Version 0.9. This massive release includes several killer new components, exciting new features for existing components, and of course a number of bug fixes. Here&#8217;s a brief overview of some of the compelling things you&#8217;ll find in Cappuccino 0.9:</p>
<h3>Bindings</h3>
<p>One of the most exciting features of this release is full Key Value Bindings support. Team members <a href="http://github.com/klaaspieter">Klaas Pieter</a>, <a href="http://github.com/aljungberg">Alexander</a>, <a href="http://github.com/boucher">Ross</a>, and of course <a href="https://github.com/280north/cappuccino/contributors">many members of the community</a> have put a tremendous amount of work into getting bindings ready for this release. With support for most major components, CPObjectController, CPArrayController, and undo/redo, bindings are already a killer feature. But we&#8217;ve gone one step beyond that and included support for bindings in nib2cib! So not only can you build your Cappuccino interface in Interface Builder, but you can now configure interface bindings in it as well.</p>
<h3>CPTableView and CPOutlineView</h3>
<p>We were incredibly excited to introduce table views—one of the most important and versatile components in any widget set—in our 0.8 release. In 0.9, we&#8217;ve matured the table view to production quality and added its supplemental component, the outline view. CPOutlineView lets you build tables that provide hierarchical data and it inherits from CPTableView, so it already benefits from all the additional work that has gone into the table view.</p>
<p>&nbsp;</p>
<div style="text-align: center;"><img class="size-full wp-image-1060 aligncenter" title="CPOutlineView" src="http://cappuccino.org/discuss/wp-content/uploads/2011/02/Screen-shot-2011-02-23-at-12.00.06-PM1.png" alt="CPOutlineView" width="559" height="166" /> <span style="font-size: 10px;">CPOutlineView</span></div>
<p>Table views now support bindings, group rows, inline editing, column reordering and resizing, and a whole slew of other features. Perhaps the most requested feature that is now supported: variable row heights.</p>
<p>&nbsp;</p>
<div style="text-align: center;">
<p style="text-align: center;"><img class="size-full wp-image-1104 aligncenter" title="CPTableView Variable Row Heights in CappuTweetie" src="http://cappuccino.org/discuss/wp-content/uploads/2011/02/variable-row-heights1.png" alt="CPTableView Variable Row Heights in CappuTweetie" width="414" height="153" /><br />
<span style="font-size: 10px;">CPTableView Variable Row Heights in an upcoming Cappuccino demo app</span></p>
</div>
<p>One of the most important aspects of our table view is performance; we have been very careful not to sacrifice speed for any of these new features. CPTableView will still scroll like butter, even with hundreds of thousands of rows.</p>
<h3>New Components</h3>
<p>This release also introduces several new features to Cappuccino. You&#8217;ll find more controls from Cocoa and some new additions specific to Cappuccino. While there are too many to mention them all here, here are some notable additions:</p>
<ul>
<li><strong>CPAlert</strong>: Totally rewritten for ease of use and featuring a new UI  designed by <a href="http://madebysofa.com/">Sofa</a>.</li>
<li><strong>CPBrowser</strong>: We&#8217;re shipping a great implementation of CPBrowser with this release of Cappuccino. CPBrowser provides columnar layout for displaying hierarchical data. This is very similar to the column view in Mac OS X&#8217;s Finder.</li>
<li><strong>CPCursor</strong>: A simple API for changing the user&#8217;s cursor. The class supports a number of cursors from the start or allows you to load your own images.</li>
<li><strong>CPPredicate</strong>: The CPPredicate school of classes gives you a very powerful way to filter through your data. A future release may include robust controls for users to visually edit predicates.</li>
<li><strong>CPStepper</strong>: A control that allows users to incrementally step through values.</li>
<li><strong>CPTokenField</strong>: A powerful text field subclass with support for autocomplete, CPTokenField allows you to build unique token managers, like the address fields in Mac OS X&#8217;s Mail.app.</li>
<li><strong>NativeHost</strong><em>:</em> We announced <a href="http://cappuccino.org/discuss/2010/05/13/nativehost-run-your-cappuccino-applications-on-the-desktop/">NativeHost</a> a few months ago, but this is the first time we&#8217;ve included it with a release of Cappuccino. NativeHost lets you build your Cappuccino application for desktop platforms and distribute it like any other desktop app. Support for Mac OS X is currently included, with Windows and Linux support coming soon.</li>
</ul>
<div style="text-align: center;">
<p><a href="http://cappuccino.org/discuss/wp-content/uploads/2011/02/CPAlert.png"></a><img class="aligncenter size-full wp-image-1097" title="CPAlert" src="http://cappuccino.org/discuss/wp-content/uploads/2011/02/CPAlert1.png" alt="" width="409" height="199" /><br />
<span style="font-size: 10px;">CPAlert</span></p>
</div>
<h3>The Future</h3>
<p>We&#8217;re extremely proud of this release and all the time and work that has gone into it. We couldn&#8217;t have made it to this point this without all our contributors (67 and counting!), and a huge thank you goes out to everyone involved. The core team has grown considerably as well, now composed of 7 team members. We also want to thank everyone who has battle hardened this release through rigorous testing and feedback.</p>
<p>But what&#8217;s next? We have a ton of updates in the pipeline, and the master branch is already far ahead of 0.9. Cappuccino has been open source for over 2 years now, and it has been an amazing ride. The framework has vastly matured and a lot of people would have already slapped the 1.0 sticker on it. However, we&#8217;ve had a concrete goal of quality and completion in mind from the beginning, and can finally see the light at the end of the tunnel. Stay tuned in the upcoming weeks as we discuss our final roadmap toward Cappuccino 1.0!</p>
<p><strong>-Randy</strong></p>
<p>You can find a full list of changes <a href="http://cappuccino.org/files/v0.9.0-changelog.txt" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cappuccino.org/discuss/2011/02/23/cappuccino-0-9/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Solving the JavaScript Memory Management Problem</title>
		<link>http://cappuccino.org/discuss/2010/04/01/solving-the-javascript-memory-management-problem/</link>
		<comments>http://cappuccino.org/discuss/2010/04/01/solving-the-javascript-memory-management-problem/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 00:01:58 +0000</pubDate>
		<dc:creator>ross</dc:creator>
				<category><![CDATA[Cappuccino]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Objective-J]]></category>

		<guid isPermaLink="false">http://cappuccino.org/discuss/?p=606</guid>
		<description><![CDATA[JavaScript has some real problems. Anyone who has programmed for the web can attest to that. And anyone familiar with what we&#8217;re doing with Cappuccino will recognize that we&#8217;re not afraid to tackle those problems head on. When we created Objective-J we set out to create a set of true enhancements to the JavaScript language [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript has some real problems. Anyone who has programmed for the web can attest to that. And anyone familiar with what we&#8217;re doing with Cappuccino will recognize that we&#8217;re not afraid to tackle those problems head on. When we created Objective-J we set out to create a set of true enhancements to the JavaScript language that would add powerful new dynamic features to the language, like advanced automatic dependency resolution, truly dynamic message passing, and familiar classical inheritance. By all accounts it has been a tremendous success.</p>
<p>Lately, though, we&#8217;re beginning to realize that we didn&#8217;t quite go far enough. Memory issues have long plagued JavaScript developers. Because the garbage collector is opaque to the developer, and nothing like &#8220;finalize&#8221; is provided by the language, programmers often find themselves in situations where they are forced to hold on to an object reference for too long (or forever) creating a memory leak.</p>
<p>Just as we&#8217;ve done before, when we tackled this problem we decided to look at what has worked in the past. Finding inspiration in the elegant simplicity of C, we knew we&#8217;d found the right solution. And so, we&#8217;re pleased to announce the immediate availability of a manual memory management system in Cappuccino.</p>
<p>A lot of Cocoa developers disparaged garbage collection when it came to Objective-C, and we&#8217;ve come to realize they were absolutely right! Why rely on machines to solve problems for us when we can do it by hand. So, we&#8217;ve taken the Cocoa reference counting system and implemented it in JavaScript. We&#8217;ve replaced the existing no-op -retain, -release, and -autorelease methods with fully working implementations. When an object&#8217;s release count reaches 0, the object&#8217;s dealloc method will be called, and the memory will be able to be reclaimed. Now you have a clear way to clean up unwanted references when an object is no longer being used. Just make sure you do your reference counting correctly!</p>
<p>To do this right, we&#8217;ve created a global object table. These objects aren&#8217;t going anywhere on their own! If you don&#8217;t release an object, it will stick around forever, ensuring you&#8217;ll always have it when you need it. This global table acts as a lookup table for any object, allowing us to finally implement pointers in JavaScript. Since $ has become the coolest way to do completely non-standard lookups in an almost indecipherable way, we thought we&#8217;d jump on the bandwagon. Pass any pointer to $ and you&#8217;ll get the associated object! How do you get a pointer you ask? $$ of course! For example:</p>
<pre><code>
var o = [CPobject new]; // +new returns with a retain count of 1!
var p = $$(o); // returns a pointer to o

o === $(p); // we dereference the pointer and get the right object!</code></pre>
<p>Zombies come standard, too! Just set OBJJ_ZOMBIE_DETECTION to true and objj_msgSend will throw an exception if you ever message an object that&#8217;s been dealloc&#8217;d. </p>
<p>We&#8217;ve even take the time to properly -autorelease all objects returned from class methods in Foundation, but we&#8217;ve made absolutely no effort to properly retain those objects in Cappuccino code that uses them yet. So we need your help. Every line must be scrutinized (but we shouldn&#8217;t to automate this process, as it would surely be too error prone). Rather than focus on developing new features or fixing bugs in the issue tracker, we hope that all Cappuccino contributors will spend their time writing memory management code so that we can fully realize this web development revolution!</p>
<p>We&#8217;ll be including these exciting new features in a future release, so you should get started adding manual memory management code to every single line of Cappuccino you&#8217;ve ever written! In the meantime, check out the <a href="http://github.com/280north/cappuccino/commit/6678bba94f7778b245d8219292b3a6ac85d31678">working code on Github</a>.</p>
<p><em>Please note this is an April Fools joke!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://cappuccino.org/discuss/2010/04/01/solving-the-javascript-memory-management-problem/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Announcing Atlas</title>
		<link>http://cappuccino.org/discuss/2009/02/28/announcing-atlas/</link>
		<comments>http://cappuccino.org/discuss/2009/02/28/announcing-atlas/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 03:55:48 +0000</pubDate>
		<dc:creator>tlrobinson</dc:creator>
				<category><![CDATA[280 North]]></category>
		<category><![CDATA[Cappuccino]]></category>
		<category><![CDATA[Objective-J]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[280north]]></category>
		<category><![CDATA[atlas]]></category>

		<guid isPermaLink="false">http://cappuccino.org/discuss/?p=301</guid>
		<description><![CDATA[Over at 280 North, we announced our next product, called Atlas, at the Future of Web Apps conference in Miami this week. Atlas is a visual development tool for creating web applications using the Cappuccino framework. The best way to explain Atlas is to show it: Think Vitamin has an article discussing Atlas in more [...]]]></description>
			<content:encoded><![CDATA[<p>Over at <a href="http://280north.com">280 North</a>, we announced our next product, called Atlas, at the <a href="http://events.carsonified.com/fowa">Future of Web Apps</a> conference in Miami this week.</p>
<p>Atlas is a visual development tool for creating web applications using the <a href="http://cappuccino.org">Cappuccino</a> framework. The best way to explain Atlas is to show it:</p>
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="545" height="361" id="viddler_1db9bf4d"><param name="wmode" value="transparent" /><param name="movie" value="http://www.viddler.com/simple/1db9bf4d/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><embed src="http://www.viddler.com/simple/1db9bf4d/" width="545" height="361" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" name="viddler_1db9bf4d" wmode="transparent"></embed></object></p>
<p><a href="http://thinkvitamin.com/features/atlas-under-the-hood/">Think Vitamin has an article</a> discussing Atlas in more detail.</p>
<p>We&#8217;re really excited about the ways Atlas could change the process of developing web applications. Atlas will allow developers to worry less about boilerplate user interface and glue code, just as the Cappuccino framework gives developers many common features expected by users, letting them focus on the ones specific to their applications.</p>
<p>Furthermore, Atlas allows non-programmers, such as many graphic designers, to join in on the process of actually building an application, rather than just providing mockups that must then be replicated in code by a developer.</p>
<p>Atlas will be available this summer. Sign up for updates on <a href="http://280atlas.com">280atlas.com</a> and we&#8217;ll let you know of the progress on Atlas.</p>
]]></content:encoded>
			<wfw:commentRss>http://cappuccino.org/discuss/2009/02/28/announcing-atlas/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>On Leaky Abstractions and Objective-J</title>
		<link>http://cappuccino.org/discuss/2008/12/08/on-leaky-abstractions-and-objective-j/</link>
		<comments>http://cappuccino.org/discuss/2008/12/08/on-leaky-abstractions-and-objective-j/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 18:29:47 +0000</pubDate>
		<dc:creator>tolmasky</dc:creator>
				<category><![CDATA[Cappuccino]]></category>
		<category><![CDATA[Objective-J]]></category>

		<guid isPermaLink="false">http://cappuccino.org/discuss/?p=159</guid>
		<description><![CDATA[In a recent post by John Resig, and in many of the comments, there seems to be the mistaken belief that Objective-J was designed to allow existing Objective-C programmers to write code that runs on the web. It&#8217;s been compared to GWT, where developers program almost exclusively in Java and are allowed to “circumvent” JavaScript. [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://ejohn.org/blog/javascript-language-abstractions/">recent post</a> by John Resig, and in many of the comments, there seems to be the mistaken belief that Objective-J was designed to allow existing Objective-C programmers to write code that runs on the web. It&#8217;s been compared to GWT, where developers program almost exclusively in Java and are allowed to “circumvent” JavaScript. This however is not the case with Objective-J at all. For starters, Objective-J is simply a language addition to JavaScript, and exists separately from the actual Cappuccino framework (which I&#8217;ll discuss a little later). It does not directly have anything to do with the DOM or AJAX, etc. The purpose behind Objective-J was to facilitate the development of Cappuccino, and when we originally set out to do that we simply wanted to add a few key missing features to the existing JavaScript “standard”. In other words, Objective-J is our take on JavaScript 2.0.</p>
<p>Now, this is usually the point at which someone chimes in that JavaScript is <strong>perfect</strong>, and that I just don&#8217;t understand it (you know, despite the fact that I&#8217;ve been using it for upwards of 10 years and have worked on its implementation in a major shipping browser). However, I think most people in the community can agree that there are some pretty big holes remaining in JavaScript. JavaScript is being used in increasingly larger projects, and in these projects some of its weaknesses are beginning to show. This is precisely why we have things like the (now dead) ECMAScript 4 proposal, Harmony, and Adobe&#8217;s ActionScript. And the truth is, had JavaScript 2.0 come around and been widely implemented and supported, we would have built Cappuccino without Objective-J. But the problem is that JavaScript 2.0 didn&#8217;t come around. I started working on what would eventually become Objective-J and Cappuccino <strong>three years ago</strong>, and in that time there have been no significant improvements or changes to the JavaScript language. Yes, certain browsers have taken it upon themselves to add a few nice features here and there, but for people writing real applications that need to run on most browsers, its simply not practical to rely on them. For the most part, we&#8217;re writing the same JavaScript today (language-wise at least) that we were 5 years ago. And that doesn&#8217;t seem like its going to change anytime soon.</p>
<h3><strong>Everybody is writing &#8220;abstractions&#8221; around JavaScript<br />
</strong></h3>
<p>And I don&#8217;t just mean projects like Pyjamas and GWT. I mean <strong>EVERYBODY</strong>, including Prototype, Dojo, and jQuery.  Yes, you read correctly, all the major JavaScript frameworks are essentially doing the same thing we are to some degree or another &#8212; we&#8217;re really not that original. The sole difference between their approach and ours is that when they add new language features to JavaScript, they&#8217;re not taking the extra step of introducing <em>new syntax</em>. Don&#8217;t believe me? Take a quick look at an example right out of the Prototype tutorials:</p>
<link rel="stylesheet" type="text/css" media="screen" href="/includes/tutorial.css"/>
<pre>
<div class="codeblock" style="margin-bottom: 0px; border: 0px;"><span class="comments">// when subclassing, specify the class you want to inherit from</span>
<span class="keyword">var</span> Pirate = Class.create(Person,
{
     <span class="comments">// redefine the speak method</span>
    <span class="selector">say</span>: <span class="keyword">function</span>($super, message)
    {
          <span class="keyword">return</span> $super(message) + ', yarr!';
    }
});</div>
</pre>
<p>What we&#8217;re seeing here is the introduction of classical inheritance to the JavaScript language. This has always traditionally been a language feature, but due to its absence in JavaScript, the folks at Prototype have chosen to make it a library feature. The important thing to realize here is that it requires as much work to learn about the Class function as it would to learn about a new class keyword. And the same is true of Dojo:</p>
<pre>
<div class="codeblock" style="margin-bottom: 0px; border: 0px;">dojo.declare("Employee", Person,
{
    <span class="selector">constructor</span>: <span class="keyword">function</span>(name, age, currentResidence, position)
    {
          <span class="comments">// remember, Person constructor is called automatically</span>
          <span class="keyword">this</span>.password="";
          <span class="keyword">this</span>.position=position;
    },
    <span class="selector">login</span>: <span class="keyword">function</span>()
    {
          <span class="keyword">if</span> (<span class="keyword">this</span>.password)
               alert('you have successfully logged in');
          <span class="keyword">else</span>
               alert('please ask the administrator for your password');
    }
});</div>
</pre>
<p>Once again, dojo.declare might as well be a new keyword since its shoehorning classical inheritance right into JavaScript. The jQuery UI widgets do something very similar to this with the &#8220;widget&#8221; factory method:</p>
<pre>
<div class="codeblock" style="margin-bottom: 0px; border: 0px;">
$.widget("ui.sortable", $.extend({}, $.ui.mouse,
{
    <span class="selector">_init</span>: <span class="keyword">function</span>()
    {
           <span class="keyword">var</span> o = this.options;
           <span class="keyword">this</span>.containerCache = {};
           <span class="keyword">this</span>.element.addClass("ui-sortable");
<span class="comments">//...</span></div>
</pre>
<p>At the end of the day, it doesn&#8217;t really matter if you&#8217;re a JavaScript expert, all these libraries have quite the learning curve and if its your first time with any of them, you&#8217;re going to have be referring to documentation a lot.  And that&#8217;s <strong>not a bad thing</strong>. My point is simply that in JavaScript, more so than anywhere else, libraries need to first define what is essentially a new mini-language before they can begin to do anything useful.  This is a bit unfortunate, because it ends up tying language additions to library features, despite there being no necessary connection between the two. This makes it particularly hard to use the different libraries together in an efficient way. Sure, you can use all three in the same project, but there are some clear walls between them since each one decides to do classes a little bit differently.  Not to mention the fact that you now have pretty redundant code your site. This is what happens when a language is clearly missing features. Individual frameworks in the .NET, Objective-C, Java, and so forth world don&#8217;t suffer from core incompatibility in the way they choose to do something as fundamental as defining class hierarchies. This is part of the reason we built Objective-J as its own standalone entity.  If all you want is some of the cool language features that Objective-J adds (without any of the design patterns in Cappuccino) then you can <em>just</em> use Objective-J, there is no &#8220;all or nothing&#8221; contract.</p>
<h3>OK, so how is Objective-J different?</h3>
<p>As we&#8217;ve now seen, there is a general tendency to add language features to JavaScript. Now, in <em>my personal opinion</em>, I prefer language features as fundamental as these to be part of the syntax, not part of a library. Let&#8217;s look at what Objective-J inheritance looks like:</p>
<pre>
<div class="codeblock" style="margin-bottom: 0px; border: 0px;"><span class="keyword">@import</span> "Animal.j"

<span class="keyword">@implementation</span> Snake : Animal
{
    Number miceEaten;
}

- (String)<span class="selector">speak</span>
{
    <span class="keyword">return</span> "hisss!";
}

<span class="keyword">@end</span></div>
</pre>
<p>To me this code reads a little more naturally, and at the very least it&#8217;s no harder to pick up than the numerous library functions required in the other libraries. This approach also has the added benefit of making it absolutely trivial to write new syntax modules so that my text editor of choice can actually know what is going on in my code. You&#8217;ll also notice that creating a new syntax gives us great flexibility and allows us to add a few nifty features that wouldn&#8217;t otherwise be possible, such as optional static typing and code importing. But again, this isn&#8217;t as &#8220;out there&#8221; as some people would have you believe. It has even more benefits as we&#8217;ll soon find out, but before we do, let me answer the question that I&#8217;m sure many of you are asking right now:</p>
<h3>Why Objective-C style syntax?</h3>
<p>Again, we didn&#8217;t start off saying &#8220;lets port Objective-C&#8221;!  In fact, our first versions of Objective-J looked very similar to Java or C++:</p>
<pre>
<div class="codeblock" style="margin-bottom: 0px; border: 0px;"><span class="keyword">class</span> Snake <span class="keyword">extends</span> Animal
{
    Instance.<span class="selector">speak</span> = <span class="keyword">function</span>()
    {
          <span class="keyword">return</span> "hisss!";
    }
}</div>
</pre>
<p>However, this approach had some serious issues. To better understand them, we have to take a look at what the principal design goals of Objective-J actually were:</p>
<ol>
<li>First off, it <strong>had</strong> to be a strict superset of JavaScript &#8211; meaning all existing JavaScript had to work. Believe it or not, we <em>do like</em> JavaScript, and we didn&#8217;t want to break it or create a trade-off of features.  Not to mention we wanted the existing plethora of libraries to still work.</li>
<li>Secondly of course, we wanted to add a number of &#8220;key&#8221; features.  Some things as crucial as being able to <strong>import code</strong> and built in support for classical inheritance.  We also wanted some features inspired by languages like Ruby, such as method_missing.</li>
<li>And lastly, we wanted to keep the ease of use of JavaScript, which meant not adding an extra &#8220;compilation&#8221; step, but instead allowing developers to still pound out some code and hit refresh and see it run.</li>
</ol>
<p>The problem with adding language features in a way that would be more &#8220;familiar&#8221; to most developers, like the Java approach above, is that it would break backwards compatibility with existing JavaScript. This is because a lot of the keywords we wanted to use are actually reserved words in JavaScript, despite not being currently used. There is good reason for this though, because at some point they may actually <em>mean </em>something, and we wanted to make sure Objective-J kept working when JavaScript (finally) got a real update. Of course, we could have just chosen different keywords, like &#8220;Class&#8221; instead of &#8220;class&#8221; for instance. This however also breaks backwards compatibility because someone may have used the Class identifier in their code already.</p>
<p>The other problem with this approach is that it made it next to impossible to add harder features like optional static typing or dynamic dispatch of methods (thus allowing for method_missing) without having a full blown compiler. There&#8217;s no way to &#8220;intercept&#8221; a method call in JavaScript.  So once again, we were stuck.</p>
<p>Luckily for us however, a group of people ran into these same issues about 25 years ago when trying to improve the C language. These were the folks at Stepstone who developed Objective-C. Just like in our case, Objective-C had to be a strict superset of C (unlike C++ which does NOT always play nice with C). Also lucky for us is that JavaScript syntax is very close to C syntax, so their language additions translated very naturally to JavaScript. And perhaps now it is obvious why our keywords start with the &#8220;@&#8221; symbol, because in this manner there is no possibility of ever clashing with future JavaScript keywords or predefined user variables and functions. In other words, we can now add to the language as much as we want without the fear of breaking compatibility with existing JavaScript.</p>
<p>Similarly, the new method passing syntax allows us to have firmer control of how messages are sent:</p>
<pre>
<div class="codeblock" style="margin-bottom: 0px; border: 0px;">object.<span class="selector">jsMethod</span>();
[object <span class="selector">objjMessage</span>];</div>
</pre>
<p>This is the famous bracket syntax. What you may not realize is that this makes it perfectly clear when you are using Objective-J style message dispath, allowing us to &#8220;hook in&#8221; and add things like method_missing, etc. There are a whole bunch of other cool things that this enables which are outside the scope of this post, but I encourage you to check out the other <a href="http://cappuccino.org/learn/tutorials">tutorials</a> on our site to learn about them. All this, <strong>without</strong> breaking any existing libraries and without requiring the user to compile before every run. Pretty impressive for a langauge that is supposedly &#8220;completely different&#8221; from JavaScript.</p>
<h3>The Part About Leaky Abstractions</h3>
<p>On top of Objective-J, we&#8217;ve built the Cappuccino framework, which is designed to help developers write desktop class applications on the web. One of the many things Cappuccino does is &#8220;abstract away&#8221; the DOM, and I&#8217;ll get into why we do this in a moment.  But before I do, I think I should take a second to address this whole &#8220;leaky abstractions&#8221; business, because there seems to be a fair bit of confusion regarding this as well. If you haven&#8217;t already read it, or even if you have, I recommend you take a look at <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">Joel Spolsky&#8217;s original article on the subject</a>.</p>
<p>When people refer to this article, it is usually to criticize some &#8220;abstraction&#8221; because it will &#8220;inevitably&#8221; be leaky, and then oh boy you better watch out! But this was not Spolsky&#8217;s thesis. He didn&#8217;t end the article with &#8220;and thus avoid abstractions at all costs&#8221;. He was not somehow suggesting that we stop abstracting altogether. Quite the contrary, its clear that although these &#8220;leaks&#8221; are an unfortunate and unavoidable consequence, abstractions are still incredibly worthwhile: hence the conundrum. In every single example given in the article, it was never implied that the abstraction was somehow bad or invalid because of its leak: Just because certain SQL queries are slow doesn&#8217;t mean you should manually read in tab delimmeted files and scan them yourself. Just because TCP can fail if you unplug your computer doesn&#8217;t mean you should do IP transfers yourself.  It just turns out that, big surprise, nothing is perfect. Joel put it best himself:</p>
<blockquote><p>Indeed, the abstractions we&#8217;ve created over the years <strong>do</strong> allow us to deal with new orders of complexity in software development that we didn&#8217;t have to deal with ten or fifteen years ago, like GUI programming and network programming.</p></blockquote>
<p>And the truth of the matter is that the problem of leaks is overstated. I find it particularly hilarious when JavaScript programmers bring this up, since JavaScript, being a garbage collected <em>dynamic</em> <em><strong>interpreted</strong></em> language, is quite possibly one of the biggest abstractions of all. And yet, most of us can see that the benefits of JavaScript far outweigh the &#8220;leaks&#8221;. I think few JavaScript programmers have had to learn &#8220;the whole stack&#8221; once they&#8217;ve encountered one of JavaScript&#8217;s many leaks, whether it be performance issues (from being interpreted) or perhaps large memory consumption (from being improperly garbage collected in some browsers). No one has had to go and open up WebKit&#8217;s source code to figure out these problems. Most of the time you simply Google your concern and learn the workaround. Not that big a deal.</p>
<p>Leaks are just something we all have to learn to deal with in every facet of programming, because programming <strong>is</strong> abstraction. Abstraction is basically all programmers ever do, from pushing electrons across a wire, to turning C into assembly, to interpreting JavaScript in your browser, every step in computer science has been an exercise in abstraction. There is nothing inherently wrong with abstraction. I can understand if someone disagrees with a particular abstraction for well defined reasons, but simply waving your hands and referring me to the law of leaky abstractions is not a valid argument.</p>
<p>To suggest that we shouldn&#8217;t abstract because of Joel Spolsky&#8217;s Law that all abstractions are inherently leaky is to suggest that we shouldn&#8217;t debug because of Murphy&#8217;s Law that all code will remain inhrerently buggy.</p>
<h3>Back to Cappuccino and the DOM</h3>
<p>Cappuccino doesn&#8217;t just abstract away the DOM, it abstracts away HTML, CSS, VML, the JavaScript DOM API, etc. Why? Because as you can see there are just too many technologies with overlapping responsibilities. It&#8217;s never really clear whether you should create a button in HTML or in JavaScript code, and whether you should style it in a CSS files or apply styles manually in JavaScript, or whether you should just use Canvas to draw everything. Not to mention that on top of having to sort through all these technologies, you have the additional challenge of having to accomodate for every slightly different flavor that exists in every browser. Sometimes its relatively simple, but othertimes it can be quite complex, as is the case with Canvas and VML. The other problem is that these technologies were simply not originally designed to handle the tasks they are now performing.  HTML was designed for laying out documents, not creating applications.</p>
<p>We look at these technologies completely differently.  To us, HTML, CSS, Canvas, the DOM, etc all represent the &#8220;rendering engine&#8221; of the web, in the same way that graphics cards are the rendering engines for your computer. It&#8217;s too difficult to learn the intricacies of every graphics card on the market, so developers instead use technologies that hide these details like OpenGL. In the same way, Cappuccino defines a common way to &#8220;draw&#8221; for the web. Internally, it figures out whether its more efficient to make a div, or draw to a canvas, or use VML. This is a fantastic time saver today, because it allows Cappuccino to worry about things like performance and allows you to just get a button on the screen. But its going to be even better as time goes on. This is not only because the underlying code will get better, but because web applications today look like this:</p>
<blockquote><p><center><img class="alignnone size-full wp-image-204" title="webapps1" src="http://cappuccino.org/discuss/wp-content/uploads/2008/12/webapps1.png" alt="" width="400" height="137" /></center></p></blockquote>
<p>But tomorrow, when enough browsers finally support SVG, they may look like this:</p>
<blockquote><p><center><img class="alignnone size-full wp-image-206" title="webapps2" src="http://cappuccino.org/discuss/wp-content/uploads/2008/12/webapps2.png" alt="" width="400" height="137" /></center></p></blockquote>
<p>Or, for all we know, like this:</p>
<blockquote><p><center><img class="alignnone size-full wp-image-207" title="webapps4" src="http://cappuccino.org/discuss/wp-content/uploads/2008/12/webapps4.png" alt="" width="400" height="137" /></center></p></blockquote>
<p>The important thing is that when this happens, and it <em>will</em> eventually happen, people who invested heavily in todays technologies will have to spend a great deal of effort updating, but we will just swap out the guts of Cappuccino and your code will inherit the benefits of SVG or whatever new technology is out there.</p>
<h3>Conclusion</h3>
<p>To me what we&#8217;ve done with Objective-J and Cappuccino seems inevitable.  Even the most conservative major JavaScript libraries can&#8217;t get away without adding features to the language, and we&#8217;ve simply taken the next logical step with Objective-J. Similarly, Cappuccino is a tool that allows you to stop thinking about web pages and browser incompatibilities, and instead focus on the complex problems presented by the challenge of creating full-on applications on the web. As we&#8217;ve said <a href="http://cappuccino.org/discuss/2008/10/21/web-pages/">countless</a> <a href="http://cappuccino.org/learn/">times</a>, Cappuccino isn&#8217;t for everything. All of this abstraction isn&#8217;t necessary if you&#8217;re simply trying to add dynamic elements to a site like bankofamerica or digg. Cappuccino is for building rich applications in the browser, a small minority in the web world today. We believe that this is where things are headed, and we designed Cappuccino specifically to get <em>us</em> there.</p>
<p>- Francisco</p>
]]></content:encoded>
			<wfw:commentRss>http://cappuccino.org/discuss/2008/12/08/on-leaky-abstractions-and-objective-j/feed/</wfw:commentRss>
		<slash:comments>66</slash:comments>
		</item>
		<item>
		<title>Synthesizing Accessor Methods</title>
		<link>http://cappuccino.org/discuss/2008/10/26/synthesizing-accessor-methods/</link>
		<comments>http://cappuccino.org/discuss/2008/10/26/synthesizing-accessor-methods/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 07:58:45 +0000</pubDate>
		<dc:creator>ross</dc:creator>
				<category><![CDATA[Objective-J]]></category>
		<category><![CDATA[@accessors]]></category>
		<category><![CDATA[Accessor Synthesizing]]></category>

		<guid isPermaLink="false">http://cappuccino.org/discuss/?p=114</guid>
		<description><![CDATA[Yesterday, Francisco and Tom checked in a new feature to the Cappuccino git repository, called accessor synthesizing. This is a new language feature for Objective-J, and its designed to reduce the amount of boilerplate code developers have to write in a custom class. Normally, when you write a custom class in Objective-J, you also write [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, Francisco and Tom checked in a new feature to the Cappuccino git repository, called accessor synthesizing. This is a new language feature for Objective-J, and its designed to reduce the amount of boilerplate code developers have to write in a custom class. Normally, when you write a custom class in Objective-J, you also write a pair of getter and setter methods for each instance variable (ivar) that you want to expose. This usually means writing repetitive code that hardly ever changes each time you write it. With accessor synthesizing, developers will only have to write getter and setter methods when something truly interesting needs to happen in those methods.</p>
<p>Accessor synthesizing adds a new keyword to the Objective-J language, <strong>@accessors</strong>. When declaring your list of ivars in the <strong>@implementation</strong> block of your class, adding this one keyword will tell the Objective-J preprocessor to implement accessors for you. Let&#8217;s see an example of a simple class written using the old method, and then the same class using <strong>@accessors</strong>.</p>
<p>This Person class has two ivars, firstname and lastname. Before <strong>@accessors</strong>, the class looks like this:</p>
<pre class="enscript" ><!--BEGIN enscript-->
@<B><span style="color:#A020F0">implementation</span></B> <B><span style="color:#0000FF">Person</span></B> : <B><span style="color:#0000FF">CPObject</span></B>
{
    CPString firstName;
    CPString lastName;
}

- (<B><span style="color:#228B22">void</span></B>)<B><span style="color:#0000FF">setFirstName</span></B>:(<B><span style="color:#228B22">CPString</span></B>)<span style="color:#B8860B">aString</span>
{
    firstName = aString;
}

- (<B><span style="color:#228B22">CPString</span></B>)<B><span style="color:#0000FF">firstName</span></B>
{
    <B><span style="color:#A020F0">return</span></B> firstName;
}

- (<B><span style="color:#228B22">void</span></B>)<B><span style="color:#0000FF">setLastName</span></B>:(<B><span style="color:#228B22">CPString</span></B>)<span style="color:#B8860B">aString</span>
{
    lastName = aString;
}

- (<B><span style="color:#228B22">CPString</span></B>)<B><span style="color:#0000FF">lastName</span></B>
{
    <B><span style="color:#A020F0">return</span></B> lastName;
}

@<B><span style="color:#A020F0">end</span></B><!--END enscript--></pre>
<p>Using the new <strong>@accessors</strong> keyword, we can eliminate four methods:</p>
<pre class="enscript" ><!--BEGIN enscript-->
@<B><span style="color:#A020F0">implementation</span></B> <B><span style="color:#0000FF">Person</span></B> : <B><span style="color:#0000FF">CPObject</span></B>
{
    CPString firstName @<B><span style="color:#A020F0">accessors</span></B>;
    CPString lastName @<B><span style="color:#A020F0">accessors</span></B>;
}
@<B><span style="color:#A020F0">end</span></B><!--END enscript--></pre>
<p>This second version is much more succinct than the first, and less tedious to program. We think this will be helpful for developers, and will increase productivity and code readability.</p>
<p>It&#8217;s important to note that this doesn&#8217;t change the way you use a class. For our Person class, in both cases, the code for getting the first and last names of a person (in the myPerson variable) would look something like this:</p>
<pre class="enscript" ><!--BEGIN enscript-->
var fullName = [myPerson firstName] + <B><span style="color:#BC8F8F">&quot; &quot;</span></B> + [myPerson lastName];<!--END enscript--></pre>
<p>Similarly, setting an ivar looks like this:</p>
<pre class="enscript" ><!--BEGIN enscript-->
[myPerson setFirstName:<B><span style="color:#BC8F8F">&quot;Winston&quot;</span></B>];
[myPerson setLastName:<B><span style="color:#BC8F8F">&quot;Smith&quot;</span></B>];<!--END enscript--></pre>
<p>Like any key-value-coding compliant class, the name of the instance variable becomes the &#8220;property&#8221; or &#8220;key&#8221;, and that key name is used in the setter and getter methods. If your key is <em>firstName</em>, the getter for that key will be <em>firstName</em>, and the setter will be <em>setFirstName:</em>. The same pattern applies to any other key.</p>
<h3>Configuration</h3>
<p>There are a few configuration options when using the new <strong>@accessors</strong> technique. Perhaps most importantly, is the ability to change the name of the property. For example, if you declared an instance variable like this:</p>
<pre class="enscript" ><!--BEGIN enscript-->
CPString _location @<B><span style="color:#A020F0">accessors</span></B>;<!--END enscript--></pre>
<p>Objective-J would generate two accessor methods called <em>_location</em> and <em>_setLocation:</em>. These are the expected accessor methods for a key called &#8220;_location&#8221;. In order to generate more friendly versions without the leading underscore, you can modify your declaration like this:</p>
<pre class="enscript" ><!--BEGIN enscript-->
CPString _location @<B><span style="color:#A020F0">accessors</span></B>(<B><span style="color:#0000FF">property</span></B>=location);<!--END enscript--></pre>
<p>The addition of the property=location tells Objective-J to use &#8220;location&#8221; as the new property name, instead of &#8220;_location&#8221;, which will generate <em>location</em> and <em>setLocation:</em> methods without the underscore. In addition, you can also specify the specific name of both the getter and the setter method, like this:</p>
<pre class="enscript" ><!--BEGIN enscript-->
<B><span style="color:#A020F0">BOOL</span></B> _hidden @<B><span style="color:#A020F0">accessors</span></B>(<B><span style="color:#0000FF">getter</span></B>=isHidden, setter=setIsHidden);<!--END enscript--></pre>
<p>This code specified a boolean instance variable called _hidden; the getter method will be called <em>isHidden</em> and the setter method will be called <em>setIsHidden:</em>. One thing to keep in mind when specifying your own getter and setter method names is key-value-coding. Although we don&#8217;t yet have much documentation on the subject (you can read Apple&#8217;s documentation <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/KeyValueCoding.html">here</a>), key-value-coding enables several important features in Cappuccino, so it&#8217;s important to maintain key-value-coding compliance. Normally, the rules are that for a given key, say &#8220;foo&#8221;, the getter is called <em>foo</em>, and the setter is called <em>setFoo:</em>. There&#8217;s an additional rule for boolean values, which says that you can use <em>isFoo</em>, and <em>setIsFoo:</em>, in addition to the usual method names. In our case, thats why our custom getter and setter names are still key-value-coding compliant.</p>
<p>There are two additional configuration options, <strong>readonly</strong>, and <strong>copy</strong>. By default, <strong>@accessors</strong> will generate both a getter and a setter. If you only want to expose a getter method to the world, you can add the <strong>readonly</strong> value in the arguments. The other option, <strong>copy</strong>, has to do with how the setter works. Normally, when you pass an object to a setter, it&#8217;s assigned directly. The generated setter looks like this:</p>
<pre class="enscript" ><!--BEGIN enscript-->
- (<B><span style="color:#228B22">void</span></B>)<B><span style="color:#0000FF">setFoo</span></B>:(<B><span style="color:#228B22">id</span></B>)<span style="color:#B8860B">aFoo</span>
{
    foo = aFoo;
}<!--END enscript--></pre>
<p>When you specify <strong>copy</strong>, the argument is first sent the message copy, and the return value of that message is assigned to the instance variable:</p>
<pre class="enscript" ><!--BEGIN enscript-->
- (<B><span style="color:#228B22">void</span></B>)<B><span style="color:#0000FF">setFoo</span></B>:(<B><span style="color:#228B22">id</span></B>)<span style="color:#B8860B">aFoo</span>
{
    <B><span style="color:#A020F0">if</span></B> (foo !== aFoo)
        foo = [aFoo copy];
}<!--END enscript--></pre>
<p>This is useful if you want to ensure that an object you&#8217;re passing isn&#8217;t modified out from under you. Of course, it only applies to ivars that are both read and write, and cannot be combined with readonly. To summarize, you can use both of these options like this:</p>
<pre class="enscript" ><!--BEGIN enscript-->
@<B><span style="color:#A020F0">implementation</span></B> <B><span style="color:#0000FF">FooBar</span></B> : <B><span style="color:#0000FF">CPObject</span></B>
{
    <B><span style="color:#A020F0">id</span></B> foo @<B><span style="color:#A020F0">accessors</span></B>(<B><span style="color:#0000FF">readonly</span></B>);
    <B><span style="color:#A020F0">id</span></B> bar @<B><span style="color:#A020F0">accessors</span></B>(<B><span style="color:#0000FF">copy</span></B>);
}<!--END enscript--></pre>
<h3>History</h3>
<p>Apple introduced properties in Objective-C 2.0, which added a new way to declare instance variables for your classes. The two key features were the ability to use what has become known as &#8220;the dot syntax&#8221; for accessing instance variables, and the second was the ability to have the compiler automatically generate accessor methods. Reducing code, especially code that doesn&#8217;t change every time you write it, is certainly a worthwhile goal, so we thought it would be a good idea to bring this new idea to Objective-J. There are a lot of things about the Objective-C 2.0 implementation of properties that don&#8217;t make sense for Objective-J, so we decided not to port them directly and instead developed a syntax that we believe makes the most sense.</p>
<p>The main goal we want to achieve is eliminating the need to write your own accessor methods. We don&#8217;t, however, support the &#8220;dot syntax&#8221; aspect of Objective-C 2.0. This makes the dual @property and @synthesize syntax of Objective-C 2.0 redundant. Furthermore, rather than just choose one or the other, we decided to use a new keyword, <strong>@accessors</strong>. This will lesson the confusion for existing Cocoa developers trying to learn Objective-J. It will also make sure we don&#8217;t have an incompatible syntax going forward, as we explore new ways to work with existing Objective-C code.</p>
<h3>Conclusion</h3>
<p>Accessor synthesizing will reduce the amount of boilerplate code that needs to be written, and make the language just a little bit easier to develop in. Overall, we think it&#8217;s a worthwhile addition to the language. If you have an opinion, we&#8217;d love to hear it, so sound off in the comments. Although this new syntax isn&#8217;t yet written in stone, we won&#8217;t expect to change it after version 0.6 of Cappuccino ships. Checkout the latest version of the git repository to start using this new feature.</p>
<p>We&#8217;re also considering other language features that might make it easier to program in Objective-J. If you&#8217;ve got an idea, or you&#8217;re interested in being part of the discussion, you should sign up for the <a href="/discuss/list.php">mailing list</a>, where we&#8217;ll be discussing some of the new proposals.</p>
]]></content:encoded>
			<wfw:commentRss>http://cappuccino.org/discuss/2008/10/26/synthesizing-accessor-methods/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

