Sunday, September 18, 2011

More interpretation required for interpreted languages

After I finished ruby koans (and they are absolutely awesome). I started to look at python koans. In the very beginning I realized that there is something extremely silly about programming languages, you still have to write things like below (to avoid introducing not needed empty spaces):
        string = "It was the best of times,\n\
It was the worst of times."

It is not the same as
  
        string = "It was the best of times,\n\
                  It was the worst of times."

Same problem is displayed in ruby koans:
    long_string = %{
It was the best of times,
It was the worst of times.
}

There are times when this is extremely inconvenient, and your style can only be saved by using templates as in:
require "erb"

#test.erb:
# hubba
# hubba <%= oink %>

erb = ERB.new(File.read("test.erb"))
oink = "hubba"

puts erb.result

No comments: