ArticleslgStudy

science

Tritium (programming language)

Tritium (programming language) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Tritium (programming language) rather than just read about it. In short: Tritium is a simple scripting language for efficiently transforming structured data like HTML, XML, and JSON. It is similar in purpose to XSLT but has a syntax influenced by jQuery, Sass, and CSS versus XSLT's XML based syntax.

Key takeaways

  • Tritium (programming language) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Tritium (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Tritium (programming language) from memory before moving on to harder problems.

Reference excerpt

Tritium is a simple scripting language for efficiently transforming structured data like HTML, XML, and JSON. It is similar in purpose to XSLT but has a syntax influenced by jQuery, Sass, and CSS versus XSLT's XML based syntax.

History Tritium was designed by Hampton Catlin, the creator of languages Sass and Haml and is currently bundled with the Moovweb mobile platform. As with Sass (created to address deficiencies in CSS) and Haml (created to address deficiencies in coding HTML templates), Catlin designed Tritium to address issues he saw with XSLT while preserving the core benefits of a transformation language. Much of this was based on his prior experience porting Wikipedia's desktop website to the mobile web. Open Tritium is the open source implementation of the Tritium language. It was presented at O'Reilly Open Source Convention 2014 and the compiler is implemented in Go.

Concept Tritium takes as input HTML, XML, or JSON documents and outputs HTML, XML, or JSON data that has been transformed according to the rules defined in the Tritium script. Like jQuery, idiomatic Tritium code is structured around selecting a collection of elements via a CSS or XPath selector and then chaining a series of operations on them. For example, the following script will select all the HTML table elements with id of foo and change their width attributes to 100%.

While Tritium supports both XPath and CSS selectors via the $() and $$() functions (respectively), the preferred usage is XPath. For example, the above code rewritten to use the equivalent XPath selector would be:

Comparison to XSLT Both Tritium and XSLT are designed for transforming data. However, Tritium differs in key ways to make it more familiar and easier to use for web developers:

Familiar syntax: Tritium's syntax is similar to CSS and jQuery so that it is more familiar and readable to web developers than the XML based syntax of XSLT. Imperative style: Tritium uses an imperative programming style instead of the functional and recursive processing model of XSLT. While functional programming has key advantages, it is less familiar to web designers than imperative programming. Input transparency: In XSLT any input elements that are not specified by a transform rule are removed from the output. Tritium reverses this behavior: any input elements that are not specified by a transform rule are passed to the output unchanged. HTML-compatible: Tritium was designed to process HTML, XML, and JSON, whereas XSLT only works on XML.

References

External links Open Tritium website GitHub page for Open Tritium Official Tritium website Applying Transformations to Responsive Web Design Tritium tagged questions on Stackoverflow

Worked examples

Example 1 — a first encounter with Tritium (programming language)

Start with the simplest possible case. Write down what Tritium (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Tritium (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Tritium (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Tritium (programming language)

In research
Tritium (programming language) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Tritium (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Tritium (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for Tritium (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Tritium (programming language)” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Tritium (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Tritium (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Tritium (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Tritium (programming language) in simple terms?

Tritium is a simple scripting language for efficiently transforming structured data like HTML, XML, and JSON. It is similar in purpose to XSLT but has a syntax influenced by jQuery, Sass, and CSS versus XSLT's XML based syntax.

Why does Tritium (programming language) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Tritium (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Tritium (programming language).

Tags

  • Programming languages

Keep exploring