Sep 21 2007

Java, Ruby, and even Python Sucks

There is a bit of a flame war unfolding between Javanistas and Rubyists. I could trace this most recent scuffle to an article posted on JavaLobby by Daniel Spiewak about a little Java library called ActiveObjects. The aritcle is promoting this Java-based but Rails inspired Object Relational Mapping library. ActiveObjects is a Java implementation of the Active Record pattern made famous by Ruby on Rails and it’s use of convention over configuration. In touting the benefits of ActiveObjects, Daniel complains and grossly exaggerates that in Hibernate “you have to write more XML than code!”

Gavin King, the founder of Hibernate, responded that XML was soo 1999 and now they overuse annotations. Gavin wrote, “Hibernate Annotations has been around since early 2005 and there is no longer any good reason for people to define mappings in XML.”

Out of the blue and into the blogosphere, Obie Fernandez responded to Gavin’s ‘FUDdly’ remarks with his top 10 rant why Java sucks ass! Basically Obie resorts to fighting FUD with FUD. Obie goes ballistic on compilers, IDEs, frameworks, libraries, High School Musical 2, and Java developers themselves. Obie rants that most Java Programmers are morons. From his writing, it is clear that Obie idol worships DHH as the fucking second coming of the fifth generation computer language era. Obie’s top ten reasons why Java sucks include that the language makes money for vendors. From his Ruby rage you think he hopes to make Java vendor money by writing Ruby books.
Continue reading


Aug 27 2007

Running with Shoes – 2D Graphics and Animation

I’ve already gone over the basic UI features of the Shoes toolkit. Shoes is a nice little domain specific language for developing GUI applications in Ruby. Here I’ll go over some of the 2D graphics and animation capabilities in Shoes.

Shoes has a light weight 2D support where you can draw lines, rectangles, and circles. To create an application that draws a line we can execute the following bit of code.

[source:ruby]
Shoes.app :width => 200, :height => 200 do
# line x1, y1, x2, y2
line 20, 40, 60, 80
end
[/source]

To draw an oval insert the following code inside the shoes code block.

[source:ruby]
Shoes.app :width => 200, :height => 200 do
# oval center_x, center_y, width, height
oval 50, 100, 100, 50
end
[/source]

And to a simple rectangle, you can do so by using the rect method.

[source:ruby]
Shoes.app :width => 200, :height => 200 do
# rect top_x, top_y, with, height
rect 100, 100, 30, 10
end
[/source]

Shoes also supports the animate method which can be used, as it’s name applies, to repeatably call a block of code that animates some graphics. The animate method takes a parameter, the number of frames per second. For example, to draw a new image once a second we can call animate(1). To draw an image twice a second call animate(2). Here is a simple example of the animate method in action.

[source:ruby]
text_field = nil
Shoes.app :width => 200, :height => 200 do
text_field = text Time.new.to_s
animate(1) do
text_field.replace Time.new.to_s
end
end
[/source]

The above piece of code creates a text field and updates the value of the text field with the current time once a second. This way you can animate a simple text-based clock.

Here is another animation example. The following code draws a rectangle. The rectangle is moved twice a second to a random location within the application window. This code uses the fill and stroke methods, which accept arguments to define the fill and stroke color respectively. You can also use the strokewith method to set the width of the pen stroke. Also notice that the following example invokes the width and height methods which return the current width and height of the application window.

[source:ruby]
moving_box = nil
Shoes.app :width => 200, :height => 200 do
# fill red, green, blue, alpha
fill 1.0, 0.5, 1.0, 1.0
stroke 0.5, 0.5, 1.0, 1.0
strokewidth 5
moving_box = rect 10, 10, 20, 20

animate(2) do
x = (0..width-20).rand
y = (0..height-20).rand
moving_box.move x, y
end
end
[/source]

As you can see, it is easy to draw 2D graphics using Shoes.

Technorati Tags: , , , , , , ,


Aug 27 2007

Running with Shoes – A Mini GUI Toolkit

Shoes is a cross-platform mini-gooey toolkit for the Ruby programming language written _Why. I installed Shoes on an Ubuntu box ran with it (bad pun intended).

Let’s move from puns to code. A simple Shoes application is wrapped around the following piece of code.

[source:ruby]
Shoes.app :height => 250, :width => 200 do
end
[/source]

As you can see, a Shoes application is simply a Ruby block. You can pass in a hash or arguments with the values for the window’s default height and width. If you save the above piece of code as Appy.rb you can run it from the Shoes installation directory by running the following command.

./shoes Appy.rb

If you run the above application it simply opens a empty application window. An empty window is pretty much useless. An GUI application needs buttons and text fields to be of practical use. Lets add two buttons to our application that when pressed print out an informational bit of text to the console.

[source:ruby]
Shoes.app :height => 200, :width => 200 do
button “Button One” do
puts “Button One Pressed”
end
button “Button Two” do
puts “Button Two Pressed”
end
end
[/source]

When working with soft gooeys the second thing one needs to learn after how to add a button is how to layout it out. As of this writing (Release 117), Shoes provides two layout managers, Stack and Flow. Stack lays out your components from top to bottom. The Flow layout container lays out UI widgets from left to right. Building on top of our Shoes application the following code layouts out the two buttons using the Stack cointainer with a 10 pixel margin.

[source:ruby]
Shoes.app :height => 200, :width => 200 do
stack :margin => 10 do
button “Button One” do
puts “Button One Pressed”
end
button “Button Two” do
puts “Button Two Pressed”
end
end
end
[/source]

To add a simple text field just call the text field with the default text value.

[source:ruby]
Shoes.app :height => 200, :width => 200 do
stack :margin => 10 do
button “Button One” do
puts “Button One Pressed”
end
button “Button Two” do
puts “Button Two Pressed”
end
text “Text Field”
end
end
[/source]

Here is how the above code renders.

Running With Shoes

I would be a bit more practical if we can update the text field based on some condition, say when a button is pressed. Since we need to reference the text field in the code block for each button we need to have a variable for it. Also, instead of printing text to the console, we will display it in the text field.

[source:ruby]
my_text_field = nil
Shoes.app :height => 200, :width => 200 do
stack :margin => 10 do
button “Button One” do
my_text_field.replace “Button One Pressed”
end
button “Button Two” do
my_text_field.replace “Button Two Pressed”
end
my_text_field = text “Text Field”
end
end
[/source]

As you can see, you can get started writing Shoes GUI applications fairly quickly. But as mentioned earlier, Shoes is a mini-GUI toolkit that is still under development. _Why has mentioned that he intends to keep Shoes small. From what I can gather from sample applications and the online code repository Shoes provides additional widgets such as an edit_line, edit_box, and list_box. But I was not able to find any information regarding tabs, check boxes, radio boxes, or trees.

In the next installment of Running with Shoes, I’ll go over it’s 2D and animation capabilities.

Technorati Tags: , , , , ,


Jun 26 2007

Favorite Programming Tumblelogs

According to wikipedia, a tumblelog is a variation of a blog, that favors short-form, mixed-media posts over the longer editorial posts frequently associated with blogging. I like to think of a tumblelog as a miniblog. Here are some of my favorite programming related tumblelogs.

  • Anarchaia – This might have been the first tumblelog, according to Kottke.
  • Dr Nic’s Journey – Dr Nic writes about “the small things in my day so I don’t clutter the Dr Nic site.” He writes mostly about Ruby, Rails, JavaScript, and popular culture.
  • technoweenie, wtf – Technoweenie writes about his tumblelog, “Probably a lame project.ioni.st wannabe.” Mostly popular culture form this well known Rubyist and Railer.
  • Application Error – “application-error.com is a tumblelog; an assorted buffé of rubbish presented by your host for the night Johan Sørensen.”
  • Projectionist – This tumblelog is contributed by Rubyists Marcel Molina, Sam Stephenson, Chad Fowler, and others.
  • ni.hili.st* – A classic tumblelog covering programming and popular culture.
  • A Rubyist Railstastic Adventure – This is my own Ruby/Rails tumblelog which supplements some of the Ruby related writing found on this site.
  • Java Musings – This is my Java related tumblog. It contains mostly quotes, most often than not from the Java Posse.
  • Happy Coder’s Daily Digest – This is my tumblelog RSS feed reader. It gets the feeds for programmers such as James Gosling, Graeme Rocher, Nick Sieger, Romain Guy, Peter Cooper, Charles Nutter, Tor Norbye, Joel on Software, Chad Fowler, and _Why.

Technorati Tags: , , , , , , ,


Jun 13 2007

JavaOne 2007 Conference Notes

Here are all my notes taken at CommunityOne and JavaOne 2007. I was in San Francisco for 5 days and attended over 40 technical and birds of a feather sessions and managed to put together this 30 page document. For you download pleasure you can find a PDF version of all my conference notes.

CommunityOne 2007: Monday
Welcome to CommunityOne 2007
Getting Started and what’s New in GlassFish v2
Lunch with the Java Posse
Ajax Applications Made Easy with jMaki and Scripting
Swing GUI Building with Matisse: Chapter II
JRuby: Understanding the Fuss
Up the Stack
G2One

JavaOne 2007: Tuesday
Tuesday General Session
JRuby on Rails – Agility for the Enterprise
Evolutionary Java – General Session
Java Puzzlers
Using jMaki in a Visual Development Environment
Java Persistence API – Best Practices and Tips
Developing a Real-World Web Application with NetBeans 5.5 Visual Web Pack
Grails, Sails, and Trails – Rails Through a Coffee Filter
Rapid Seam Application Development with the NetBeans IDE

JavaOne 2007: Wednesday
Wednesday General Session
Swing Vector Graphics
Effective Java Reloaded – This Time It’s for Real
Building JavaServer Faces Applications with Spring and Hibernate
Extreme GUI Makeover 2007
Anatomy of an Eclipse RCP Application
Tricks and Tips with NIO
Dive into the GlassFish Aquarium
Seamless Web Browser Integration
Putting a Swing Front End on a Web Application

JavaOne 2007: Thursday
Thursday General Session
Being Productive with Swing
Technical Overview of GlassFish v2
JavaScript FX
Why Spaghetti is Not Tasty
Beans Binding
Write a 3D Game in Java
Web 3.0 – This is the Semantic Web
The Java 3D API and Java Binding for OpenGL
Glossitope – An Open-Source Java-based Widget Container

JavaOne 2007: Friday
Friday General Session
Bringing Life to Swing Desktop Applications
Ajax and JavaServer Faces Tooling in Eclipse
Bytecode Manipulation Techniques for Dynamic Applications for the JVM
Filthy-Rich Clients – Talk Dirty to Me
Writing Games with Project Darkstar

Technorati Tags: , , , , , , , , , ,


Jun 12 2007

Bytecode Manipulation Techniques for Dynamic Applications for the JVM

This JavaOne 2007 technical session seemed like a panel discussion between Eugene Kuleshov and Tim Eck of Terracotta, Tom Ware of Oracle/TopLink, and Charles Nutter of Sun/JRuby. The session started off by describing the Java Virtual Machine, the Java bytecode, and the ASM framework. The Java Virtual Machine (JVM) is a proven and reliable platform aimed at high-performing applications. The JVM is designed for statically-typed languages but provides class loading and a reflection API for dynamic languages. The discussion also delved into the class file format. The class file format simply consists of field and method names, string literals and constants, and debug information.

The ASM bytecode framework is a simple, small, and fast library for adding dynamism to your Java application. The ASM framework is useful for Java code generation and modification. Terracotta, TopLink, and JRuby use ASM to dynamically inject code into an existing class.

Charles Nutter described how the JRuby team is using the ASM framework to support Ruby’s dynamic and open class nature. Speaking of JRuby’s move to ASM Charles said, “To be slower than one of the slowest dynamic languages was embarrassing.” Using ASM, recent version of JRuby are performing better than the C implementation of Ruby in some cases.

As a word of warning, you should always document use of code generation because it is hard to debug and maintain if you don’t know what is going on.

Technorati Tags: , , , , , ,