provides software and services that enable enterprises
Live Chat 1-888-673-6564

Open Source Software Technical Articles

  • Home
  • Search
  • Source Code Scanning Tools
  • Products and Support
  • Services
  • Cloud Services
  • Open Source Training
  • Enterprise OSS Blog
  • Wazi Technical Blog
  • About Wazi
  • Attributions and Licensing
  • Supply Chain Compliance
  • How to Contribute
  • Contributors
  • Resources Library
  • Partners
  • Customers
  • Community
  • Company
  • Careers
  • News and Events
  • Contact Us

Subscribe to Wazi by Email

Your email:

click-here-to-chat-with-an-online-representative


Enterprise Developer Support 24 x 7 for Apache, CentOS, Tomcat, PostSQL and more. Get a Support Quote by clicking here!


Latest Posts

  • Build your own custom modules for Drupal 7
  • CentOS system administration using text-based user interfaces
  • Quickly create custom software packages with FPM
  • More easy RSS for your websites via Google and Yahoo! APIs
  • Get RSS for your website using jQuery and PHP
  • JSF tip: How to create bookmarkable pages
  • MySQL Workbench simplifies MySQL management tasks
  • Use Perl to enhance ModSecurity
  • The secret to great reporting with Drupal 7
  • A more colorful LibreOffice unveiled

Connect with Us!

Current Articles | RSS Feed RSS Feed

Tea: A Disney Original Programming Language

Posted by Rares Aioanei on Mon, Apr 16, 2012
  
Email This Email Article  
Tweet  
  

Would you expect to write code in a language proposed by the Walt Disney Internet Group? Yep, Disney created its own language and IDE, plus several other utilities, to use in the creation and maintenance of its website, as well as others under its corporate umbrella, such as ESPN and ABC News. The Tea language owes a lot to Java, and so do the rest of the tools – for example, Beandoc converts JavaDoc comments to JavaBean comments. If you know Java, Tea will be right up your alley. If you are familiar only with languages like C++ or C#, it may take a little more getting used to.



Along with Java, the Tcl and Scheme languages have had an influence on Tea. Tea combines features that are hard to find elsewhere in a single language: support for functional programming, closures (taken from Scheme, of course), full object-oriented programming support, library autoloading facilities, and lots of core classes and functions for common functionality like networking, I/O, string processing, and XML. Support for popular DBMSes like PostgreSQL, MySQL, Oracle, Sybase, Informix or Microsoft SQL Server is included.



However, open source purists should be aware that the official Tea interpreter, unlike the other Tea tools, is proprietary, ergo so is the bytecode that results from its use. That means that you can get Tea and use it for personal projects, but for commercial use you have to ask for permission. There are alternatives, though: One is a Perl project called destea that released Language::Tea in CPAN, which generates Java code based on your Tea code. You can also try an open source compiler called TeaClipse, which unfortunately looks a bit neglected at the moment.



To get the Tea interpreter, if you choose to go that route, you can go to the project's download site and follow the usual install-from-source routine. You need a JRE installed, as well as the GNU regexp library. Optional features you may want include XML parsing, for which you need SAX, or a JDBC driver if you need database connectivity. Another very interesting project to look out for is Tea Trove, which seems better maintained than the old SourceForge project and under a more friendly license (Apache 2.0) than what we've found on PDMFC's site. I used it for this article, but that doesn't mean you can't use the other alternatives, should you wish to, because I'm interested in the language more than the tools used for it.


19a98812-f823-48dc-841e-bf029c63c6d7

To get your first sip of Tea, let's start with a simple "Hello, world!" example, though it may look a bit different than what you're used to if you're familiar with Java, Tcl, or Scheme:




<% template HelloWorld(ContentObject obj) %>
Hello <% obj.message %>!


All code regions are delimited by <% and %>, and text outside those regions is printed as-is. That means another way to write this, if we wanted to use only one pair of delimiters, would be




<% template HelloWorld(ContentObject obj)
"Hello " obj.message
%>


Tea's lexical structure is almost entirely based on Java's. Here's an example that would look familiar to developers that embed ASP or JSP code in HTML, and that illustrates how text and Tea code regions get mixed:




<% template MyTemplate(PageInfo page) %>
<html><head><title><% page.title %></title></head>
<body>
<h1><% page.heading %></h1>
<table>
<% foreach (item in page.list) { %>
<tr><td><% item.name %></td><td><% item.desc %></td></tr>
<% } %>
</table>
</body>
</html>


Tea has just a few keywords. Its operators and separators will be familiar to those familiar with C or Java. For a complete reference, check the wiki on Github.



Practical Approaches



For a more practical demonstration of Tea's utility, let's start by declaring a template:




Template ::= TemplateDeclaration [StatementList]
TemplateDeclaration ::= template Identifier ( [FormalParameterList] ) [SubstitutionParameter]


Parameters must be delimited by commas, and each formal parameter requires a class name and a unique identifier. Object type names must be fully qualified except for those defined in the java.lang and java.util packages. The type declaration may define an array (or an array of arrays) just as in Java, using [ and ] symbols.



Templates have some resemblance to functions, in that they can return a value, and they can invoke other templates. Let's take SimpPage.tea as a first example of a template, then see how CompPage.tea calls it:




//SimpPage.tea
<% template SimplePage(String title, String color) { ... }
'<html><head><title>' title '</title></head>'
if (color == null) {
'<body>'
}
else {
'<body bgcolor="' & color & '">'
}
...
'</body></html>'
%>

//CompPage.tea
<% template NewsPage(org.news.NewsStory story)
// Pass a title and a substitution block to SimplePage
call SimplePage(story.title, "#ffffff") {
'<h1>' story.headline '</h1>'
foreach (paragraph in story.body) {
'<p>' paragraph.body
}
}
%>


Tea creates loops using the keywords foreach, break, and continue, and you can, as usual in other languages, combine them with if blocks if you so need. Blocks are delimited by braces, C-style. If you're not clear about the foreach keyword, imagine you need to increment each member of a list by two. So for each of those members, you just add two:




foreach (item in my.list) {
item+=2
}

//The functionality of 'for' is created like so:
foreach (count in 1..10) {
"Count is " & count
}

//Same, but in reverse
foreach (count in 1..10 reverse) {
"Count is " & count
}


Assignments are made easy for the developer, so they don't have to worry too much about type compatibilities. Here are some examples:




Hello = "Hello, this is a string"
value = 20
newval = value + 10
newval = value + 10 as Integer

//Any text that is not inside a code block is treated as pure text, so
"Hello, world!"
//and
print("Hello, world!")
//are equivalent


IDE support



There used to be a Kettle IDE suggested on the project's old SourceForge page, but the PDF documenting it, as all the site it seems, stopped receiving updates somewhere around 2001. I downloaded Kettle and tried to start with the .jar file. It seems it's made to work with Java 1.3, so I didn't stand a chance with the implementation that I have installed. I went looking for IDE alternatives, but Eclipse doesn't seem to directly support Tea, nor does NetBeans. In conclusion, folks, no Tea IDE for you, unless I really missed something, which is not impossible, since looking for such a common term on search engines is likely to give you more misses than interesting results.



Despite the lack of a working IDE, Tea has a pretty active community behind the language. It's interesting, easy to learn, and practical if you need a web programming language that lets you get started right away.

Follow @openlogic
Follow @CloudSwing

This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.Follow @openlogic
Follow @OSCloudServices

This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.
Tags: MySQL, Technical, PostgreSQL, Tutorial, Programming, teatrove-kettle, teatrove-beandoc, sax, teatrove-tea, Java

Comments

that superb points you have discussed about Original Programming Language, its really helpful for the new developers.
Posted @ Friday, March 15, 2013 2:03 AM by bahrain web development
Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics

Loading...
Error sending email
Email sent successfully

Email article
Email To : 
Your name : 
Message : (maximum 200 characters)
Home | Search | Source Code Scanning Tools | Products and Support | Services | Cloud Services | Open Source Training | Enterprise OSS Blog | Wazi Technical Blog | Resources Library | Partners | Customers | Community | Company | Careers | News and Events | Contact Us
Products
OpenLogic Exchange (OLEX)
License Compliance Module
OSS Discovery
OSS Deep Discovery
OpenUpdate
Services
Open Source Support
CentOS Support
Scanning & Compliance
Open Source Training
Professional Services
Solutions
Support & Indemnification
Open Source Governance
Open Source Scanning
Open Source Provisioning
Consulting & Training
Contact Us
1-888-673-6564


© 2013 OpenLogic, Inc. All rights reserved.
Site Map  |  Privacy Policy