<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Rafael Martins — gentoo</title>
  <id>https://rgm.io/atom/gentoo/index.xml</id>
  <link href="https://rgm.io/atom/gentoo/" rel="self" />
  <link href="https://rgm.io/" />
  <updated>2016-05-21T15:25:00Z</updated>
  <author>
    <name>Rafael Martins</name>
    <email>rafael@rafaelmartins.eng.br</email>
  </author>
  <subtitle type="text">Rafael Martins' website</subtitle>
  <generator version="0.20.1.13-2435">blogc</generator>
  <entry>
    <title type="text">balde internals, part 1: Foundations</title>
    <id>https://rgm.io/post/balde-internals-part1-foundations/index.html</id>
    <updated>2016-05-21T15:25:00Z</updated>
    <published>2016-05-21T15:25:00Z</published>
    <link href="https://rgm.io/post/balde-internals-part1-foundations/" />
    <author>
      <name>Rafael Martins</name>
      <email>rafael@rafaelmartins.eng.br</email>
    </author>
    <content type="html">
      <![CDATA[<blockquote><p><strong>Warning:</strong> This is a legacy post. I have no plans to write more posts
in this series.</p>
</blockquote>
<p>For those of you that don&#x27;t know, as I never actually announced the project here,
I&#x27;m working on a microframework to develop web applications in C since 2013.
It is called <a href="https://balde.rgm.io/">balde</a>, and I consider its code ready
for a formal release now, despite not having all the features I planned for
it. Unfortunately its <a href="https://balde.rgm.io/doc/">documentation</a> is not good
enough yet.</p>
<p>I don&#x27;t work on it for quite some time, then I don&#x27;t remember how everything
works, and can&#x27;t write proper documentation. To make this easier, I&#x27;m starting
a series of posts here in this blog, describing the internals of the framework
and the design decisions I made when creating it, so I can remember how it
works gradually. Hopefully in the end of the series I&#x27;ll be able to integrate
the posts with the official documentation of the project and release it! \o&#x2F;</p>
<p>Before the release, users willing to try balde must install it manually from
<a href="https://github.com/balde/balde">Github</a> or using my <a href="https://github.com/rafaelmartins/gentoo-overlay">Gentoo overlay</a> (package is called
<code>net-libs&#x2F;balde</code> there). The previously released versions are very old and
deprecated at this point.</p>
<p>So, I&#x27;ll start talking about the foundations of the framework. It is based on
<a href="https://developer.gnome.org/glib/">GLib</a>, that is the base library used by
Gtk+ and GNOME applications. balde uses it as an utility library, without
implementing classes or relying on advanced features of the library. That&#x27;s
because I plan to migrate away from GLib in the future, reimplementing the
required functionality in a BSD-licensed library. I have a list of functions
that must be implemented to achieve this objective in the
<a href="https://github.com/balde/balde/wiki/Converting-from-LGPL-to-BSD">wiki</a>, but
this is not something with high priority for now.</p>
<p>Another important foundation of the framework is the template engine. Instead
of parsing templates in runtime, balde will parse templates in build time,
generating C code, that is compiled into the application binary. The template
engine is based on a recursive-descent parser, built with a parsing expression
grammar. The grammar is simple enough to be easily extended, and implements
most of the features needed by a basic template engine. The template engine
is implemented as a binary, that reads the templates and generates the C source
files. It is called <code>balde-template-gen</code> and will be the subject of a
dedicated post in this series.</p>
<p>A notable deficiency of the template engine is the lack of iterators, like
<code>for</code> and <code>while</code> loops. This is a side effect of another basic characteristic
of balde: all the data parsed from requests and sent to responses is stored as
string into the internal structures, and all the public interfaces follow the
same principle. That means that the current architecture does not allow passing
a list of items to a template. And that also means that the users must handle
type conversions from and to strings, as needed by their applications.</p>
<p>Static files are also converted to C code and compiled into the application
binary, but here balde just relies on <a href="https://developer.gnome.org/gio/stable/glib-compile-resources.html">GLib GResource infrastructure</a>. This is
something that should be reworked in the future too. Integrate templates and
static resources, implementing a concept of themes, is something that I want
to do as soon as possible.</p>
<p>To make it easier for newcomers to get started with balde, it comes with a
binary that can create a skeleton project using GNU Autotools, and with basic
unit test infrastructure. The binary is called <code>balde-quickstart</code> and will be
the subject of a dedicated post here as well.</p>
<p>That&#x27;s all for now.</p>
<p>In the next post I&#x27;ll talk about how URL routing works.</p>
]]>
    </content>
  </entry>
</feed>
