Meet devChix member Susan Potter

July 13th, 2011 by comment

Susan Potter is a wearer of many hats, but mostly software engineer and practicing applications architect (based in Chicago, IL).

Employer: Finsignia

Extras: Last month, Susan presented at WindyCityDB conference in Chicago, IL on Link-walking with Riak. She was a speaker at Code PaLOUsa 2011 in June. Talk: Deploying distributed software services to the cloud without breaking a sweat. She is very active in the open source community with GitHub personal repositories, Twitter4R and collection of Gists.

Our short Q&A with Susan Potter:

What is your technical background?

At university I studied Mathematics, but audited Computer Science courses while writing an experimental parallel and distributed PDE solver first in C, then in C++ and finally in Java, which didn’t have much utility other than to teach me how not to write multi-threaded or distributed software.After graduating I worked for investment banks in London before skipping off to a San Francisco startup building a B2B trading platform and have since been working as a senior software consultant for hedge funds, investment banks and technology startups all over the US.

What industry sites or blogs do you read regularly?

To be honest, I use my Twitter timeline and some private lists as a fairly reliable source of interesting, relevant and/or thought-provoking technical resources from all over the internet. However, the following links have been fonts of recent software engineering wisdom or great resources in the areas I currently practice within:

What are a few of your favorite development tools and why?

I recently wrote a blog post on the (types of) tools that have made me a better software engineer. In short these are: emacs, vi(m), make, gdb, UNIX commands / utilities, UNIX shells, LaTeX, Git. The blog post explains why.

What tip or advice would you like to impart to women interested in programming?

If you enjoy software development, always learning new things and are excited about the possibilities in this field, then do not let anyone discourage you from persuing it further. There will always be a job market for self-starters that can teach themselves even if they don’t have the right educational background. Make sure to back up what you have learned on your own. Open source projects, blog posts or screencasts that demonstrate your skills in the areas you are looking to get into help much more nowadays than simply having a CS degree with no public portfolio IMHO.

If you were a computer part, what would you be?

A CPU socket comes close. It provides multiple connections (mechanical and electrical) between the microprocessor and circuit board. In the technology community it seems I am always connecting people based on their interests and needs such as connecting business founders with technical founders or hiring managers with skilled developers (mechanical connections). Other times I am suggesting new architectures, software stacks, tools, etc. to solve the problems people I talk to are currently encountering (electrical connections).

ˆ Back to top

Meet devChix member Aimee Daniells

June 2nd, 2011 by comment

aimee daniells (lowercase as requested) is a self-employed software crafter from Winchester, UK.

Her twitter handle: @sermoa and thoughts: http://sermoasquared.co.uk/

 

Our short Q&A with aimee daniells:

 

What is your technical background?

I was sponsored through university by IBM. I had an integrated degree where I worked at IBM 3 days a week and studied Computer Science at university 2 days a week. After I graduated I worked for IBM for a few years. Although I began as a developer, they decided to retrain me as a tester. I didn’t like the way IBM made decisions for me.

Now a tester, I looked for a job where I could begin as a tester but progress back into development. This didn’t really work. Fortunately I was learning in my spare time. I learned Ruby on Rails and made the application mychores.co.uk – a team based tracking system for recurring tasks. On the strength of that I got a job with Eden Development, an agile web development and consultancy company.

I worked at Eden for 3 years and took an apprenticeship under Enrique Comba Riepenhausen. I learned an incredible amount about good quality, reliable, well tested software and user experience design. Towards the end I took on two apprentices, one of whom I am still in regular contact with.

I am now an independent software crafter, doing freelance work and visiting companies to work as a contractor. I love what I do, I love meeting people and I love learning and sharing. At the last company I’ve just finished working at, I was approached by somebody who wanted to be mentored by me, who has now become my newest apprentice.

 

What industry sites or blogs do you read regularly?

I do not read RSS. I used to be subscribed to hundreds but I couldn’t read them all. These days I get all the news I need through twitter.

 

What are a few of your favorite development tools and why?

I love my macbook. It just does exactly what I want it to do, feels reliable and very rarely annoys me. I prefer to develop using Vim because I feel it is very powerful and I can express my intentions using intuitive combinations of keystrokes. I typed on the Dvorak keyboard layout for years, but I’ve recently changed to Colemak. I find it very comfortable and efficient to type on.

 

What tip or advice would you like to impart to women interested in programming?

Ask questions. Better to ask a silly question one day than give a silly answer another day. There is no such thing as silly questions, only silly answers. Listen a lot and ponder. Think carefully about what you believe. Share your opinions when asked. Share whatever you know. Be generous. Blog about things you find interesting: somebody else will do too. Ask for things you need. If you want to learn more, find a mentor. Don’t wait for people to do things for you. Make your own luck. Be extremely proud of who you are. Look yourself in the mirror every day and tell yourself how wonderful you are. Be humble. Don’t brag, but let your skills speak for themselves.

 

Last question on our q&a, if you were a computer part, what would you be?

I would be the Any key! :)

 

ˆ Back to top

Meet devChix member Nola Stowe

May 19th, 2011 by comment

Nola Stowe is a co-founder of devChix from the Texas, USA.
You can reach her at @rubygeekdotcom on twitter.
She is currently a web developer at Game Salad.
Game Salad is a free tool that creates games for the iPhone, iPad, Mac
& Web with no coding required.

Her linkedin: http://www.linkedin.com/in/nolastowe &
She blogs at RubyGeek.

 

Our short Q&A with Nola Stowe:

 

What is your technical background?

I started programming the summer I turned 13. I had a TRS-80 and read the BASIC programming book that came with it, along with another programming book I bought at Radio Shack. I had a cassette tape drive to save my files and a 5inc thermal printer. I programmed math games for my siblings. I distinctly remember making a program that would roll five dice and using ascii characters to draw  a box around the number. You could then choose which dice to re-roll. Ahh, sometimes I long for those summer days and also think: “…. boy, how much better I could have been if I had the internet like now!”

In college, I discovered the fun of web development so I majored in Computer Information System and Design Studio minor. I actually petitioned to have my water color class count towards my CIS degree, arguing that since my chosen field was web programming with a design minor, it is good to have the training and understanding of color principles from my water color class. They accepted my petition

 

What industry sites or blogs do you read regularly?

I check:

rubyinside.com – ruby is my favorite language; this is a great site to keep up with the ever-changing landscape

techcrunch.com – to keep up with what’s new with facebook, google, etc

railscasts.com – weekly screencasts, they are super informative

teachmetocode.com – screencasts on web development, very helpful

peepcode.com – screencasts at affordable prices, and great supporters of devChix.com

 

What are a few of your favorite development tools and why?

I use vim and textmate. It depends on the environment. For home development, I am on Ubuntu so I use Vim. For work, I use a Mac so I use both Vim and Textmate , but lately I’ve been using Textmate a lot.

 

What tip or advice would you like to impart to women interested in programming?

It’s a mans world for sure. Do not take it personally when someone gives you slack. Focus on doing the best work you can so people cannot tell the difference between your work and that of any other. Do not assume every issue you come across is “because you are a  girl” … just focus on what is needed to get the job done.

 

If you were a computer part, what would you be?

I would be a keyboard because I am always focusing on what is needed to get the job done. If we did not have keyboards, we would not be able to get much done. :)

 

ˆ Back to top

Book Review: "Refactoring in Ruby"

January 4th, 2010 by comment

“Refactoring in Ruby” written by William C. Wake and Kevin Rutherford.
Published by Addison-Wesley

This is more like a “workbook” then a “how to write awesome code” book. You can download the code from github http://github.com/kevinrutherford/rrwb-code and you will find tests/specs for the exercises.

The book is arranged in three parts, The Art of Refactoring, Code Smells, and Programs to Refactor.

There are explanations of “code smells” which are one characteristic of code that could be improved. Some of them are long parameter lists, unnecessarily complex, global variable, feature envy sections, etc. One thing I find interesting is the “How did it get this way?” section. It gives some insight into the thought process and reasoning behind the smell. I think this is good, as programmers our ego may be rather miffed to hear “This code stinks” but with some reasoning, it makes the pain less and I think firms up in our minds when this happens again, to do it this other way. I always want to know why when someone says I could do such and such thing better.

In addition to the code smell examples there are three programs to refactor in the end of the book. In a conversational tone, it walks through and gives some hints on what needs refactoring. Its almost as if you had a pair programming buddy working with you and identifying in small chunks what can be improved. This is definitely something I want to work through more carefully.

What I find odd, is that not all the code smells have code examples. The inspiration for the book I think is the Martin Fowler book “Refactoring Improving the design of Existing Code” which has examples for every code smell. Maybe Ruby smells less than Java? Or those fixes are really trivial? I don’t know. Overall, this is a great book and is certainly worth the price and investment and you will be a better programmer because of it!

ˆ Back to top

Don't go splurging at the widget store

February 15th, 2009 by comment

It is easy for clients, I have noticed, to mistakenly conflate adding widgets, effects and acronyms — Sliders, Sorters, Expanding-Menus, Oh My! — with implementing an idea. The client talks excitedly, rattling off a Rube Goldberg chain of widget-to-widget interactions, their voices rising, the importance of each and every widget in the chain perceived critical to the achievement of the Internet Holy Grail: Angel Investment. Or at least, a really slick site.

Don’t get me wrong. I think everyone is in favor of a well-placed widget.

They can be so smooth and beautiful that you gasp. They can glow yellow for just the correct duration before fading to white (“where has that beautiful apparition gone?”, you wonder, before drunkenly clicking again. And again. And again.). They can add an item to a list almost magically: never was it so fun to have so many things To Do. They can save you clicks, keep you in one place, slide items into carts with almost illicit ease.

In short, they can make things so simple that a tear comes to your eye, and you rush off, hat in hand, in the quest of The Holy Spinner to deliver your payload.

The Holy Spinner

But stop.

What are you looking for? Forget the elevator pitch, as it can be intoxicating: the sound of your voice, people nodding enthusiastically, the doors shut blocking their escape (especially if you are stuck between floors). Instead, do the quiet room test. You alone. Your idea. Naked. A convergence of souls.

“What do you need, Idea”, you ask, “in order to fully manifest your glorious Idea-ness?”

If your idea is quiet, do not rush to speak for it. If your idea speaks but is simple, do not scoff. Do not dress your idea up in Widget Drag, so it looks like a teenager searching for their identity at the Web 2.0 Store. If your idea does not need a Yellow Fade or slider, that is OK. If you remove the slider and yellow fade and find there is no idea underneath, that’s OK, too. Go for a walk. Another idea will come.

Think about building a UI like listening to the ones that you love. You observe them. You listen to their likes and dislikes so your gifts will please them, not reflect your tastes. It’s not about the shiny present: it’s about the connection, the need anticipated and met, a little bit of the edge taken off. Brush cleared, the path made simpler.

If you’re tempted to drive up to your date in the red corvette of ideas — or wow your user with the accordian navigation ’cause it like, opens and closes! — remember that you might be saying more about yourself than anything else.

And then ask yourself: Do you need that rainbow-colored slider on your site?

ˆ Back to top

The Creative Commons license, and change.gov: Our new president gets it!

December 2nd, 2008 by comment

I was really excited and moved to see this:

http://change.gov/newsroom/entry/towards_a_21st_century_government/

This copyright license affects most content on the website change.gov, guaranteeing transparency and the feedom to redistribute and discuss it’s content.

All I can say is, wow. This president not only believes in transparency, but understands how to implement it using existing tools and conventions. He understands the spirit of Open Source software development, and everything that has come about since this movement began. Imagine an “Open Government”, genuinely implemented and influenced by the people, and it’s hard not to want to get involved.

The change.gov web site has a very nice, simple form, requesting your ideas and suggestions. They already have proposals for nationwide fiber optic broadband, automation and transparency in the patent process, and automation of health insurance data to bring healthcare costs down. There are many more places where technology can automate away inefficient and error prone processes.

We here on DevChix all know how technology has changed our lives. Let them know how it can change a nation. Submit your ideas and suggestions, and let’s help educate and influence this new administration.

Gloria

ˆ Back to top

From Python 2.6 to PHP 5.2: A circuitous journey

November 20th, 2008 by comment

When I started heavily using PHP 5.2 (not by choice, I’ll admit), I was impressed, but I suffered from some incorrect assumptions about what PHP5 is and is not capable of doing. The good news is that it is more object oriented than it’s predecessor, but has some caveats to consider. Here are some things to be aware of when switching from a pure OO language to PHP5:

1: A nonexistent PHP array key generates no error or warning. When trying to iterate over a nonexistent array key, a warning occurs. In other languages, both of these conditions throw an exception.

Try this code for example:

<?
$dictionary=array('one'=>'got one','two'=>'have two','four'=>'missing three?');
foreach (array_keys($dictionary) as $key)
{
	print "Key is:".$key.", value is:".$dictionary[$key]."\n";
}
print "Try undefined key three, no warning occurs:".$dictionary['three']."\n";
foreach ($dictionary['three'] as $value)
{
	print "Now we're iterating over a nonexistent key:";
	print "Key is: three, value is:".$dictionary['three']."\n";
}
?>

Running it results in this output:

php test.php
Key is:one, value is:got one
Key is:two, value is:have two
Key is:four, value is:missing three?
Try undefined key three, no warning occurs:

Warning: Invalid argument supplied for foreach() in /root/test.php on line 8

If it is vital to me to make sure I am aware of missing keys, I only have two choices. If I need a proactive solution, I have to use the array_key_exists() function to do existence checking before use. If I want a reactive solution, I write a log scanner, to pick up on these warnings. In every other OO language I have used, an exception was thrown for this condition, and my exception handling determined if the error was vital enough to have to exit immediately or not. This seems like a more efficient way to handle this condition. I would imaging PHP5 does not do this because of it’s need to be backward compatible with PHP4, but this is a guess.

It would be wonderful to have a -OO flag for PHP, which gives you the option to run PHP and expect more standard, stricter OO behavior in these instances.

2: Warnings cannot be “caught” like exceptions. Exceptions and warnings are distinctly separate beasts, and never the twain shall meet. Fine, I thought, maybe I could detect warnings similar to how we detect errors. But it seems like warnings cannot be detected when they happen. There is no PHP code I know of which can check if a warning had occurred in runtime. I tried to detect it using array error_get_last() but to no avail. if you know how, post your trick here.

3: In PHP, ‘true’ evaluates to an integer ’1′. To get the boolean ‘true’ value from a ‘true’ statement, one needs to var_export() a true statement. Similarly, or maybe not, ‘false’ evaluates to no output. Here is an example:

<?
print "\nThe raw value of a true statement in PHP:".true;
print "\nThe raw value of a false statement in PHP:".false;
print "\nThe exported value of a true statement in PHP:".var_export(true,true);
print "\nThe exported value of a false statement in PHP:".var_export(false,true);
print "\n";
?>

And the output:

The raw value of a true statement in PHP:1
The raw value of a false statement in PHP:
The exported value of a true statement in PHP:true
The exported value of a false statement in PHP:false

This may not be noticeable to you in a standard expression. But if you’re doing funky stuff, like using the evaluated expression values as key references into the dictionary of a decision tree, for example, 1 does not equal ‘true’, and the difference matters quite a bit.

4: Long running processes with recursive circular references (such as Doctrine code) run out of memory. This is documented in many places, and the free() function works sometimes. A fix is coming in PHP 5.3. The foolproof solution for my code in production today (youch!) is to periodically restart the daemon. If you’re cringing right now, know that you’re not cringing alone.

There may be a part II to this article. Feel free to add your own PHP5 observations.

Gloria

ˆ Back to top

Rails Summit Latin America

October 16th, 2008 by comment

I am currently in Sao Paulo, Brazil at Rails Summit Latin America and the experience has been great thus far.

Ladies at the conference there is information at the end of this writeup about how to join. If you don’t feel like reading everything in this writeup that is fine but please do read about joining.

In contrast to many conferences I have been to recently I have been to just about every talk at this conference and I have thoroughly enjoyed them all. I say just about because there is a second track that is going on in another room but I haven’t been to those sessions.

The Organizers:
Fabio Akita and Gilberto Mautner Founder of locaweb have done a great job with the conference and I would like to give them a special thanks. The lineup, venue and everything has been great. Obrigado!

Theme:
I think most conferences, through the keynotes, some how seem to create a theme. The theme that I am picking up on at this conference is this: “Have No Fear” and “Just Do It”. No one actually said either of those two things but thats basically what I am taking away from most of the keynotes. They have all been especially encouraging for people to become involved. Contribute, create, and code. Give back to the community and get involved. Don’t be afraid .. put yourself out there and learn from the feedback you get.. learn from the experiences of creating.. do side projects.. basically be PASSIONATE.

The Talks:
All the talks I have seen have been excellent. I give them an excellent rating because they have all had the qualities I look for in a talk.
1. The content is good and interesting.
2. The delivery of that content is entertaining or at least engaging.

Chad Fowler – I really enjoyed Chad’s talk and as I sit here I am struggling to figure out a way to describe his talk and actually do it justice. He spoke about his background in music and how that has translated to his life as a developer. In addition, he spoke about being remarkable. He talked about many ways in which people are remarkable and many ways in which we ourselves can become remarkable people. He touched on many things and did so in such a way that I was able to stay engaged with him. There were pictures and video’s and graphs and fake numbers and.. anyway about the best I can say is that I personally really enjoyed his talk.

Dr. Nic Williams – Dr. Nic’s presentation is a little easier to sum up but at the same time I can’t really do it justice. Dr. Nic is one of those speakers that if you ever have a chance to see him speak you should definitely take the opportunity. He is hilarious and has a good message. His talk was all about how to contribute back.. how to get involved.. how to participate. Make the future you proud of the you now. Dr. Nic also talked about newgem

Chris Wanstrath – Chris’s keynote started off being about the future of Ruby and RoR but in the end he took it back to the past and where we have come from. He went through a great deal of history on how we got here which I personally enjoyed especially when he pointed out the first ENAIC programmers were all women, unfortunately he was speaking quite fast so I think a lot of his talk was lost in translation. I think the primary thing Chris was trying to get across is to not be afraid. If you have an idea.. make time to get to it you never know where thats going to go. In the very least you gain experience and you gain knowledge. Chris has had many projects in the past but his current claim to fame is all about github.

Jay Fields – Jay’s talk was about the immaturity of testing as a whole. While I agree with some of the things he said I also disagree with some of the things he said. I have had the luxury of getting to pair with Jay on projects before and its always interesting for me to see him speak because I have first hand experience with a lot of things he talks about. He described the problem of immaturity in testing as a whole first with the fact that we can’t even agree on common terminology. He then proceeded to talk about various tools and the pros and cons of each. He covered Selenium, Test:Unit, Rspec, Syntasis, and Expectations. The last two being the most immature of them all and bleeding edge. i.e. use at your own risk. He also answered a few questions about how to make your test suite fun faster and his response was basically that if you are willing to deal with the pain that goes along with it there are tools you can look into using such as null_db, unit_record, and ARBS. You can read about them on the null_db page on Agile Web Development site. That page links out to the other plugins. Jay also pointed out that all the things he was talking about are from his point of view. In other words its the context in which he works that causes him to have some of the testing beliefs he has.

David Chemlisky – David’s first talk was about doing TDD and in my opinion he did an excellent job of demonstrating TDD. I have seen him give a talk similar in the past and of all the people I have heard try to describe TDD, David is one of the most skilled at it. He gave the talk from the point of view of a teacher which in my opinion is really the only way you can truly explain TDD. He went through the process step by step with us all to show us the way. :)

His second talk was more about Acceptance testing and story runner and the newest version of story runner which is being called cucumber. He demonstrated how it worked and made sure to give context around all the terminology such as user stories etc. Hopefully there will be some way of seeing this talk again maybe through a screen cast or something of that nature. I’ll be sure to ask him if he would be willing to do that. Or maybe there is one with cucumber? Not sure haven’t had a chance to look yet.
Couple of links to stuff he talked about.
Cucumber
webrat on github and a blog post on it here

On that last note I am actually interested to know if these talks are being recorded and if they will be available somewhere? Anyone know the answer to that?

Obie Fernandez – I haven’t actually seen Obie give his talk yet but I have seen the talk (insider information) so I am going to go ahead and give a recap.. I asked him to plug DevChix and wanted to have this write up already done before he did so.. ;-) So Obie’s talk will be about the “Hashrocket Way”. He is basically giving up our secrets.. Like Dr. Nic said no secrets! His main focus will be around how we work, the fact that we follow Agile Tenants and that we value fun, collaboration, and effectiveness. We achieve those things through certain practices such as pair programming, TDD, Story Carding, launch parties etc. Again you should check out his blog.

Ninh Bui and Hongli Lai a.k.a The Phusion Guys – I woke up late so I didn’t catch all of the talk from the Phusion guys but the part that I did catch was hilariously funny and explained things like caching and database sharding. Additionally, they gave a demo of yuumis_comments.. and here is also a link to their blog

I call out all of these guys because they are some of the best speakers I have ever seen and I actually saw them speak at this particular event.

Phillippe Hanrigou – Phillippe is going to be giving a talk on how to effectively do acceptance testing which I am looking forward to but I won’t be able to cover that here because I haven’t seen it and since I don’t have insider info on that one I’ll just have to wait like everyone else. I do know that he will be talking about one tool I hadn’t heard of before called Deep Test. You should check Phillippe’s blog as well

Luis Lavena – Luis will also be giving a talk about surviving with RoR and Ruby as a windows user.. again I think the talk is going to be awesome but its in the future so I can’t really talk about that yet. You should check out his blog!

The Venue:
The venue is quite nice. The main auditorium is very well arranged and has plenty of room despite the fact that there are a lot of people here. There is a very large screen making it easy for everyone to see the slides as well as the speakers. The lighting on the actual speakers is a little weird but other than that the actual conference room is great. The audio is fantastic and the actual hang out area is quite nice as well (other than the lack of air conditioning but thats just me being a little whiny its not really that hot). One other really important point that I want to bring up is the translators. You can get a headset at the checkin area that will translate the talks from English to Spanish and Portuguese and from what I understand the translators have been doing a kick ass job so a special thanks to all those ladies in the booths translating for us.

The Community:
I was very encouraged by the number of people at the conference, the number of people using github (vast majority) and the number of people doing Ruby and RoR development on a day to day basis. It is always an exciting moment for me when I realize it is gaining in support because how much I love the language. In addition, everyone has been extremely helpful and friendly. We meet Tim Case the first day and he was more than willing to take us under his wing and show us around.

One thing that was both encouraging and discouraging is the number of women at the conference. There were women, thats the good news, the bad news is that I think from a ratio point of view the number of women at the conference is on par with what I have experienced at Ruby and RoR conferences in the US. That is to say its pretty small. Usually at conferences since there are so few women I can manage to talk to most of them and but here I have been some what intimidated by the language barrier. One other thing to point out is that there were no women speakers but hey that isn’t really that uncommon. I am hoping that when Obie does his talk and plugs DevChix for us that many of those women who were at the conference that I didn’t get to meet will come to the site and join.

Ladies Please Read
For those women who do happen to come to the site from Brazil and other countries. I would like to say that we have members world wide who can speak a number of different languages so please don’t let that discourage you from joining and participating. We would LOVE to have you all as part of the group. Also encourage other female developers you know.

If you are a women, a developer, interested in joining and/or contributing to DevChix, please contact Desi McAdam at info(-at-)devchix.com with your:

1. Name
2. Email
3. Do you know any one from DevChix?
4. A short 2 sentence bio describing your development background/experience (or what you hope to learn) and a link to your blog if you happen to have one.

Obrigado! :)

ˆ Back to top

A Hello World for Ruby on Ragel 6.0

January 13th, 2008 by comment

This is an updated version of this tutorial. This updated version is compatible with Ruby 1.8 and Ruby 1.9, and Ragel 6.0. A version of this tutorial in Portuguese is available here.

By the end of this post, you’ll be able to turn a simple string “h” into the much longer and more interesting string “hello world!” using the magic of Ragel, all from the comfort of Ruby. Ragel is a very powerful state machine compiler and parser generator, which is at the heart of software like Mongrel and Hpricot. It’s able to generate C, C++, Objective-C, D, Java or Ruby code.

Ragel has excellent documentation provided by the author. My goal here is just to give you some context so that the documentation “sticks” when you read it, and to give you a working example which you can modify as you explore Ragel’s functionality. If you want to skip ahead, the full example is here.

The first step, of course, is installing Ragel. The Ragel home page has a Download section which lists ports for various platforms. If you already have Ragel installed, check that the version is 6.0 or higher. You can also compile and install Ragel from the source. Even if you don’t want to install from source it’s handy to have a copy of it to get some examples to play with. The subversion repository for Ragel is located here:

http://svn.complang.org/ragel/trunk/

As usual the test/ directory is your friend, also check out the examples/ directory. As per this thread, try searching for “LANG: ruby”.

When writing Ragel code, you create a file with a .rl extension. The .rl file is written in the “host” language, in this case Ruby, and the Ragel machine specification is embedded within the Ruby code using special delimiters. There’s actually no obligation to specify a state machine, so a perfectly valid .rl file is:

puts "hello world"

Don’t worry, I’m going to do a better Hello World than that, but this is a good place to start. To convert this .rl file into an executable .rb file, use the “ragel” command with a -R flag to indicate that you want Ruby code.

ragel -R hello_world.rl

This will create a file entitled hello_world.rb with the following contents:

# line 1 "hello_world.rl"
puts "hello world"

I’ll, er, leave executing that file as an exercise for the diligent student.

Ragel actually does this conversion in 2 stages. First it creates an XML file, then converts the XML to Ruby. If you want to view this intermediate XML then you can pass the -x flag in addition to the -R flag.

ragel -R -x simple_state_machine.rl > simple_state_machine.xml

Now, let’s write some actual Ragel. Start a new .rl file or download the example and read along. We’re going to create a machine which prints “hello world!” when it’s passed the string “h”, and does nothing otherwise. To indicate to the ragel compiler that we are writing instructions for it, and not Ruby code, we need to place our Ragel code within double-percent-sign-curly-brackets %%{ and }%% , or you can enter a single line instruction by just typing %%. (See page 6 of the User Guide.) Here’s our state machine specification:

%%{
  machine hello;
  expr = "h";
  main := expr @ { puts "hello world!" } ;
}%%

A quick overview of what’s happening here. The name of this machine is “hello” (Ragel makes us name it). It recognizes a single token, the string “h”. When it encounters that token, it performs (in Ruby) the action:

puts "hello world"

Now, if you were to run the ragel command on this file it would compile, but you would basically end up with a blank Ruby file. We have only specified the machine, we also have to tell Ragel to actually translate this machine into Ruby code using Ragel’s write statements. The first write statement we need to add is

  %% write data;

If you add this line after the state machine definition block, it will compile, as long as you remember to add a blank line afterwards. (After you’ve worked with parsers for a while you come to appreciate newlines in a whole new way.) After adding this line and compiling, you should have a rather significant Ruby file with lots of class << self statements all generated by Ragel. You don't need to study this code, at least not right now. It's pretty dull and ugly. And, if you run the ruby file at this point, you won't see any output.

There are 2 more write statements to add, and for convenience we're going to place them within a ruby method. The argument to this method is going to be the string we want to parse. Ragel expects to find a variable named "data" containing an array of ASCII codes, so we will need to convert our string to an array. This is done very easily in Ruby using the unpack method.

def run_machine(data)
  data = data.unpack("c*") if data.is_a?(String)
  %% write init;
  %% write exec;
end

write init tells Ragel that we want to generate initialization code for the state machine. The code Ragel generates here is:

begin
  p ||= 0
  pe ||= data.length
  cs = hello_start
end

The variable p keeps track of which character in the data string we are currently parsing, starting at 0. pe is an upper limit for p. cs stores the current state of the state machine, and here it is initialized to the starting state of the state machine. These variables are discussed in the User Guide.

write exec tells Ragel to write the meat of the parser (finally!). The code generated here will actually take an input (the data argument) and determine what the state of the system should be based on that input, executing any actions which might be triggered along the way. Let's add some puts statements so we can follow the code execution.

def run_machine(data)
  data = data.unpack("c*") if data.is_a?(String)
  puts "Running the state machine with input #{data}..."

  %% write init;
  %% write exec;

  puts "Finished. The state of the machine is: #{cs}"
  puts "p: #{p} pe: #{pe}"
end

Just add 2 more lines at the end to call run_machine with various arguments and then we can actually compile and run our state machine.

run_machine "h"
run_machine "x"

And here we go...

Running the state machine with input 104...
hello world!
Finished. The state of the machine is: 2
p: 1 pe: 1
Running the state machine with input 120...
Finished. The state of the machine is: 0
p: 0 pe: 1

It worked! Now, to help us interpret the values of p, pe and cs let's take a look at the state chart of this state machine. Ragel has built-in Graphviz support to create state charts. We need to use the -V flag instead of -R.

ragel -V simple_state_machine.rl > simple_state_machine.dot

If you render the resulting simple_state_machine.dot file in Graphviz, you should get something like this:

State Chart for Simple State Machine

We can see that the state machine has only one possible transition, from state 1 to state 2. When we passed "h" as the parameter to run_machine we did indeed end up with the variable cs (current state) equal to 2 at the end of our run. When "x" was passed, we ended up with cs = 0. 0 is the error state, indicating that an error occurred in the state machine. (You can tell that 0 is the error state by reading some of the variable assignments generated by write data, the code I said was dull and ugly.)

In the label 104/4:18 over the arrow transitioning from state 1 to state 2, the 104 corresponds to the ASCII code for the letter "h". (Type "?h" in irb.) The / indicates that an action is being performed, and 4:18 tells us that the action starts at line 4, column 18 of the .rl file. Had we given our action a name, that would have appeared here instead of the file position.

By the way, here's the (textmate-specific) shell script I use to run all these steps quickly:

ragel -R simple_state_machine.rl
ragel -V simple_state_machine.rl > simple_state_machine.dot
dot -Tpng simple_state_machine.dot > simple_state_machine.png
open simple_state_machine.png
ruby simple_state_machine.rb
mate simple_state_machine.out

Now, try running this code:

  run_machine "hh"

You should get:

Running the state machine with input 104104...
hello world!
Finished. The state of the machine is: 0
p: 1 pe: 2

You don't get "hello world!" twice. Sorry. Our state machine is only looking at a the first character we pass. It knows we gave it two characters, the variable pe = 2, but after it evaluates the first character it's in a final state. There's no arrow coming out of the state 2 circle. So, passing additional input results in the system entering the error state. If we want the entire data string to be evaluated, we need to make a small change to our machine specification.

main := expr+ @ { puts "hello world!" } ;

Endless Simple State Machine

(Try expr* instead of expr+ and see how the state chart is different.)

Now, try running this new state machine with inputs "hhh" and "hxh":

Running the state machine with input 104104104...
hello world!
hello world!
hello world!
Finished. The state of the machine is: 2
p: 3 pe: 3
Running the state machine with input 104120104...
hello world!
Finished. The state of the machine is: 0
p: 1 pe: 3

When we pass "hhh", we get a "hello world!" for each "h". When we pass "hxh", we get the first "hello world!", but when we hit the "x" we enter the error state, so the last "h" doesn't get evaluated.

Here's one more example, this time without defining a run_machine method:

  %%{
    machine hello_and_welcome;
    main := ( 'h' @ { puts "hello world!" }
            | 'w' @ { puts "welcome" }
            )*;
  }%%
    data = 'whwwwwhw'
    %% write data;
    %% write init;
    %% write exec;

Hello and Welcome State Machine

welcome
hello world!
welcome
welcome
welcome
welcome
hello world!
welcome

So, there you go. Hours of entertainment await you. We've only scratched the surface of Ragel's features here, but you should now be able to navigate through the User Guide without too much trouble. If you need a better reason than "fun" to play with Ragel, then bear in mind that parsers are a great tool for constructing Domain Specific Languages (DSLs), and state machines are magic code shrinking machines for situations where you need to keep track of the, er, state of something and control the transitions between states (i.e. business logic). I would highly recommend everyone to read this article about Ragel which inspired me to check it out. If you're into Rails, then take a look at the acts_as_state_machine plugin which might be more intuitive than Ragel at first. If the DSL angle is more your cup of tea then you might want to look at ANTLR instead, which has a different focus and feature set than Ragel.

ˆ Back to top

Programming from the (under)ground up

January 5th, 2008 by comment

Hello. Welcome to my first article.

And my brand spankin new, made-from-scratch stab at programming. It’s going to be a bumpy ride: bumpy like fun-old-rollercoaster-bumpy not trainwreck-bumpy (universe willing).

Please allow me to rattle off some quick background facts so you know what planet I’m coming from. I’m a 26 year old retired bartender. I did that for more years than I care to say (ok fine, 8). I fancy myself an amateur artist; basically, I paint for therapy and fun. I’ve always liked things of a nerdy nature (i.e. writing very basic html in a webshell on angelfire when I was 13, Magic the Gathering, guys who majored in Astrophysics, etc). I consider myself very confident and intelligent, and it’s a shame that went to waste for so many years. That being said, years of bartending with no substantial plans for the future wore me out and made me feel quite desperate for awhile.

Then something changed. I got beat down so much by the universe’s way of telling me to stop f’ing around, that I got fed up with being fed up. Well, Desi McAdam happens to be one of my favorite people on the planet and a very close friend, and she had always offered to teach me programming…intensively. She and my other longtime friend/ROR evangelist Obie Fernandez had always told me they thought I’d be a great programmer. I didn’t know what they were talking about. So I called up my dear Desi and said “I’ll do whatever it takes. Let’s do this thing.”

I thought I was going to be learning in my off time while still bartending and getting tutored whenever Desi was in town. I knew this would take a very, very, very long time, but I felt ready for the challenge.

As it turned out, she and Obie were down here in Florida on the beach working with this fabulous guy Mark Smith. I had met him some weeks before, and we all had a great time together. They wanted to bring an apprentice on to the small team, so voila! Here I am. I am now in full on training starting with nothing but my instinctual and intellectual abilities and no experience. I am extremely grateful for the opportunity I have, and I intend to give back to Desi and Obie by trying hard to be a bad ass programmer.

Desi is putting alot of effort into being my personal, full-time tutor, and I think she rocks socks for it.

So I’m offering up myself, my victories, and my many future foibles here for your musing and amusement.

Cheers and enjoy

ˆ Back to top

cheap research papers