The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Haiku in Code

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Haiku in Code Posted: May 3, 2008 11:00 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Haiku in Code
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

I'm sitting in Nashville, Tennessee this morning, planning how to make sure OOPSLA ends up another great conference this year.

One of those moments of inane absurdity that I seem to gravitate to came in confluence with the discussion of the LISP 50th Year Birthday Party and Dick Gabriel's penchant for poetry, I hit upon the notion of poetry in code.

What if we mapped code expressions to poetry? Can one come up with an analog to meter (e.g. lvalue rvalue rvalue, lvalue rvalue rvalue) and write code along that lines? Or rhyming. What would an analog be?

What I hit upon though, was to look at Haiku in code. Haiku in poetry sets the rule that your poem is 3 lines, of 5, 7, and 5 syllables each. I chose to interpret this in Smalltalk code as 3 statements, with 5, 7, and 5 program nodes per statement in the body of the method.

Rather than be creative myself, I just chose to mine the existing code base. Here's the expression I used to find methods that are written in Haiku:


results := OrderedCollection new.

CompiledMethod allGeneralInstances

	do:

		[:each | 

		source := each getSource.

		([RBParser parseMethod: source]

			on: Error

			do: [nil])

			ifNotNil:

				[:tree | 

				tree body statements size = 3

					ifTrue:

						[wordCounts := tree body statements

							collect: [:statement | (NodeCounter new visitNode: statement) count].

						wordCounts asArray = #(5 7 5) ifTrue: [results add: each]]]]

NodeCounter is not a standard part of the system, here's a fileout of the code for that, it's simple.

So running this, I get a couple hits in a normal development image. Here's an example of Haiku in Smalltalk:


swap: oneIndex with: anotherIndex

		| save |

		save := self basicAt: oneIndex.

		self basicAt: oneIndex put: (self basicAt: anotherIndex).

		self basicAt: anotherIndex put: save

Run this on your code. Do you have any good Smalltalk Haiku methods? Or maybe you'd like to change your perspective and see if you can't write a method that follows these lines.

Read: Haiku in Code

Topic: jQuery Profile Plugin Previous Topic   Next Topic Topic: Chunkout 2

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use