<?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>Improbabilidade Infinita &#187; mac</title>
	<atom:link href="http://cgweb.com.br/blog/category/mac/feed/" rel="self" type="application/rss+xml" />
	<link>http://cgweb.com.br/blog</link>
	<description>Pois a vida é uma caixinha de surpresas.</description>
	<lastBuildDate>Fri, 19 Nov 2010 13:39:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>5 hours of Titanium</title>
		<link>http://cgweb.com.br/blog/2009/11/5-hours-of-titanium/</link>
		<comments>http://cgweb.com.br/blog/2009/11/5-hours-of-titanium/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 22:01:34 +0000</pubDate>
		<dc:creator>filipe</dc:creator>
				<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://cgweb.com.br/blog/?p=24</guid>
		<description><![CDATA[I always wanted to develop Mac apps, but as I never had the time to learn Objective-C, I started searching for other available options that used easier to learn programming languages or those ones I already use. After testing a some of them, like MacRuby, a few months ago I came across an excellent software [...]]]></description>
			<content:encoded><![CDATA[<p>I always wanted to develop Mac apps, but as I never had the time to learn Objective-C, I started searching for other available options that used easier to learn programming languages or those ones I already use.</p>
<p>After testing a some of them, like MacRuby, a few months ago I came across an excellent software called <a href="http://www.appcelerator.com/products/titanium-desktop/">Titanium</a>, which enables you to build desktop AND mobile applications using your good old HTML + Javascript.</p>
<p>Truth be told, by then I didn&#8217;t quite get how it worked, mostly fault of their messy and not so extensive documentation and my lack of time to magically discover everything. In fact, I installed it just because it was necessary to run bowline.</p>
<p>Two days ago I was browsing my Applications folder and happened to see it was still installed, so I though about giving it a second chance.</p>
<p>And I&#8217;m glad I did.</p>
<p>In about 5 hours, I created my first (at least my first useful) <a href="http://api.appcelerator.net/p/pages/app_page?token=V4j8YJx6">Mac app</a>.<br />
<a href="http://cgweb.com.br/blog/wp-content/uploads/2009/11/cotacoes.jpg"><img class="alignnone size-medium wp-image-25" title="cotacoes" src="http://cgweb.com.br/blog/wp-content/uploads/2009/11/cotacoes-192x300.jpg" alt="cotacoes" width="192" height="300" /></a><a href="http://cgweb.com.br/blog/wp-content/uploads/2009/11/cotacoes2.jpg"><img class="alignnone size-medium wp-image-26" title="cotacoes2" src="http://cgweb.com.br/blog/wp-content/uploads/2009/11/cotacoes2-192x300.jpg" alt="cotacoes2" width="192" height="300" /></a></p>
<p>One might say that spending 5 hours developing a simple, 2-window app is a hell of a noobie job. Yes, it may be.</p>
<p>But the fact is that I spent 5 hours developing while learning how it worked AND trying to make it look nice. So, 5 hours from scratch to complete.</p>
<p>Damn it, the first time I tried doing a Hello World on Objective-C, I spent 5 minutes building the interface on XCode and at least 2 hours (not that long, I&#8217;m just trying to prove my point) looking at the API just to find out how to connect to a database and another while to populate a grid list.</p>
<p>And the best thing is that you can use Ruby, Python and PHP code.</p>
<p>No, I&#8217;m sorry. The best thing is that you can package it as a Mac, Windows or Linux application.</p>
<p>It&#8217;s almost perfect.</p>
<h3>About the app</h3>
<p>Whenever I&#8217;m learning a new programming language, I like to create a complete app that monitors stock prices (like a price ticker). It stores your favorite stocks and retrieves up-to-date prices.</p>
<p>So, first of all, I need a database to store which stocks I need to monitor, and I need to load a web page or webservice (usually I use Yahoo) that returns me the information I need.</p>
<p>I like this method for learning purposes because it&#8217;s a simple app that enables me to dive deeper into the language/programming environment than most examples people use.</p>
<p>On the first window it lists my favorite stocks, and it has a button to update their prices. I plan on automatizing it soon. The other screen lists all available stocks, a checkbutton to mark it as monitored and a search field.</p>
<p>Simple as that.</p>
<p>Everything is build using HTML, Javascript and CSS. In fact, it&#8217;s just a web page rendered by WebKit engine.</p>
<p>In this app, I used a small Ruby code to use open-uri and ping libraries, so I could check internet connection and open Yahoo Finance&#8217;s download quote feature.</p>
<p>The design was inspired (ok, almost copy/paste inspired) by <a href="http://www.atebits.com/tweetie-mac/">Tweetie</a>. I hope they don&#8217;t mind.</p>
<h3>What I think Titanium needs improving</h3>
<p>As a new user, I really missed a good documentation. At <a href="http://www.codestrong.com/titanium/api/titanium/">Titanium API</a> you find, just that, the API. There isn&#8217;t much more than that.</p>
<p>For example, I couldn&#8217;t find anywhere where the database is stored. At first I though it was inside your application resources, but it isn&#8217;t. After a good while looking for it, I found the it&#8217;s at ~/Library/Application Support/Titanium/appdata/your.app.context/your.app.context_0/</p>
<p>Another simple thing that took me a while to figure out is that, when you install your application, it creates an empty database. As it was when you package it. So, every time your application runs, you have to find out if the database is created or not, and run an database installation script. In my case:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> db <span style="color: #339933;">=</span> Titanium.<span style="color: #660066;">Database</span>.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Databases'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;select count(1) from papeis;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Create tables and inserts rows</span>
    <span style="color: #006600; font-style: italic;">// Yeah, inside the catch block. It's awful, I know.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ok, not a big deal, but some warning about that wouldn&#8217;t hurt.<br />
Another thing is that I couldn&#8217;t find a way to run background process. Every time I click on the update stock button, the application freezes a few seconds as it opens Yahoo page. I tried using <a href="http://www.codestrong.com/titanium/api/titanium/Worker/createWorker/">Titanium.Worker.createWorker</a>, <a href="http://www.codestrong.com/titanium/api/titanium/Process/createProcess/">Titanium.Process.createProcess</a> and even tried using a lot of setTimeout calls, but none worked.</p>
<p>I&#8217;m still skeptical about it&#8217;s performance. My app runs smoothly here, but can&#8217;t tell how it works with bigger apps.</p>
<p>Still, I&#8217;m very, very satisfied.</p>
]]></content:encoded>
			<wfw:commentRss>http://cgweb.com.br/blog/2009/11/5-hours-of-titanium/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

