Archive for October, 2010

Recommended Book: DSLs In Action

2 commentsWritten on October 9th, 2010 by
Categories: Books

I was recently asked by Manning to review their upcoming book on DSLs, called DSLs In Action. Obviously, i agreed to the review because not only does that mean i get a free book, it's also on a topic that i happen to be very interested in right now because we're writing a DSL at work. Let's go over the contents of the book, shall we?

The first chapter is an introduction to the importance of everyone involved with a project speaking the same language and DSLs in general, including a good listing of the benefits and drawbacks of implementing a DSL. If you've already done any kind of DSL implementation, there's nothing new for you in this chapter, though it is a very good introduction to people who are new at it and want to learn more about it.

Chapter 2 wastes no time in showing you how you can start building your own DSL. The first example is done in Java, but is quickly superseded by a Groovy implementation which is far more expressive than its Java counterpart. The author then covers some DSL implementation patterns for both internal and external DSLs, and then discusses some of the factors you need to keep in mind when deciding to go with an internal DSL (running within the context of a host language) or an external DSL (stands on its own without having to run inside a host language). Chapter 3 covers some of the topics that you'll definitely need to be aware of when implementing a DSL, such as patterns for integration of your DSL with the actual application that you're building (both in the context of internal as well as external DSLs), dealing with errors and exceptions, and finally, some performance related factors worth keeping in mind.

The next 3 chapters cover internal DSLs exclusively. Chapter 4 discusses a set of implementation patterns for internal DSLs, such as leaning on meta-programming techniques, taking advantage of typed-abstractions, runtime generation, and macros for compile time code generation. Obviously, the applicability of these techniques depends on which language you're using, and are nicely illustrated with examples in Ruby, Groovy and Scala. Chapter 5 covers the implementation of a DSL in each of the following languages: Ruby, Groovy and Clojure. Again, the examples do a nice job of highlighting each language's strong points and what kind of results you can get from them. To conclude the chapter, a nice list of common pitfalls that you need to avoid is discussed. The next chapter covers the implementation of a DSL in Scala. It's very heavy on the Scala usage (obviously) and was IMO, one of the two most difficult chapters of the book. If you're familiar with Scala, it'll probably be much easier to get through though but a lot of interesting stuff is covered, even if you don't quite understand all of the syntax. And the resulting examples of the implemented DSLs are the most expressive ones in the entire book, at least as far as internal DSLs are concerned.

After this extensive look at implementing internal DSLs, the next 2 chapters shift their focus to the implementation of external DSLs. I was very curious to see how this would turn out because up until now, i'd never bothered to look into the creation of external DSLs because i thought it would be far too complex. After reading those 2 chaptes, i'm glad to say that while it's no trivial task, it's not exactly rocket science either. You'll see examples of how to define the grammar of your language using EBNF notation, and how you can leverage the power of libraries like ANTLR to make the whole task of parsing your DSL much easier. You'll also see some interesting examples using XText which is more of a DSL workbench. Chapter 8 takes you back to the Scala world to show you can use Parser Combinators in Scala to write an external DSL. This chapter is once again very complex, but very interesting at the same time. The book then concludes with a short final chapter where the author looks forward to the future of DSL based development.

All in all, there is a lot of very interesting and useful information in this book. You'll learn a lot of the things that you'll need to know about to make an informed decision as to which approaches you should following when implementing a DSL. You'll also learn a lot of cool tricks to make your DSLs as expressive as they can be. I can't think of a better book to get you started with DSL development. The only thing that prevents me from labeling this as a Highly Recommended book is that it doesn't cover some of the topics you need to learn about to make sure your success with a DSL is sustainable in the long term. Things like testing your DSL, backwards compatibility, versioning, etc are not covered and it is somewhat missed.

Evolving Reading Interests, Part Two

16 commentsWritten on October 6th, 2010 by
Categories: Books

One of the results of my recent Kindle purchase is that my craving for new books and knowledge has grown to a level that i haven't quite experienced before. It's gotten so bad that i'm starting to feel like Johnny 5, the malfunctioning robot with a strong addiction to continuous processing of new data from the terrible 80's movie Short Circuit (sidenote: while reading that wikipedia entry i was shocked to read that they plan on releasing a remake of that movie in 2011... you have been warned!).

I've got a bunch of technical books on my reading list, but my thirst for knowledge can't be satisfied solely by expanding my technical knowledge. I need more. Luckily for me, i learned the value of seeking other kinds of knowledge and understanding earlier this year and after a random browsing session through the Amazon store i quickly accumulated a rather large list of books that i'd love to read. Listed below are the 15 books i plan on reading first. I either include a small snippet from the Product Description or a featured review on Amazon, or my own reasons for wanting to read it.

  1. Guns, Germs And Steel: The Fates Of Human Societies

    Most of this work deals with non-Europeans, but Diamond's thesis sheds light on why Western civilization became hegemonic: "History followed different courses for different peoples because of differences among peoples' environments, not because of biological differences among peoples themselves." Those who domesticated plants and animals early got a head start on developing writing, government, technology, weapons of war, and immunity to deadly germs.
    As if that isn't compelling enough, it was recommended to me by the one and only Mark Meyers, which means that at the very least it should be very interesting. I'm currently about one third of the way through this, and it is indeed very interesting :)

  2. ReWork

    This book will make you uncomfortable. Depending on what you do all day, it might make you extremely uncomfortable. That's a very good thing, because you deserve it. We all do. Jason and David have broken all the rules and won. Again and again they've demonstrated that the regular way isn't necessarily the right way. They just don't say it, they do it. And they do it better than just about anyone has any right to expect.
    A book from people who've broken the rules and won? I'd be lying if i said i could resist that.

  3. Made To Stick

    Drawing extensively on psychosocial studies on memory, emotion and motivation, their study is couched in terms of "stickiness"—that is, the art of making ideas unforgettable.

  4. Leadership and Self-Deception: Getting out of the Box

    Learning how the process of self-deception works--and how to avoid it and stay in touch with our innate sense of what's right--is at the heart of the book. We follow Tom, an old-school, by-the-book kind of guy who is a newly hired executive at Zagrum Corporation, as two senior executives show him the many ways he's "in the box," how that limits him as a leader in ways he's not aware of, and of course how to get out. This is as much a book about personal transformation as it is about leadership per se. The authors use examples from the characters' private as well as professional lives to show how self-deception skews our view of ourselves and the world and ruins our interactions with people, despite what we sincerely believe are our best intentions.

  5. God Hates You, Hate Him Back: Making Sense of The Bible

    God Hates You, Hate Him Back makes the ultimate case for the claim that the God of the Bible is the most wicked character in the pages of history. With a wit as dry as a martini, and the cross examination techniques of a seasoned lawyer, CJ Werleman lays out all sixty-six chapters of the Bible to present an irrefutable argument that indeed God hates us all. If you have never read or never fully understood The Bible then you will do no better than this unique, comedic, 21st century summary of the greatest story ever sold, or in Werleman’s own words ‘never read’. God Hates You, Hate Him Back provides you with an arsenal of Biblical facts, stories, mythology and assertions to ensure you victory in your next religious debate.
    If any of my Christian readers are offended by this, please try to keep in mind that while i have my own views and beliefs, i respect and appreciate the fact that yours might be different from mine. So don't start bitching about religion in the comments, plskthx.

  6. Linchpin

    By Seth’s definition, an artist is not just some person who messes around with paint and brushes, an artist is somebody who does (and I LOVE this term) “emotional work.” Work that you put your heart and soul into. Work that matters. Work that you gladly sacrifice all other alternatives for. As a working artist and cartoonist myself, I know exactly what he means. It’s not what you do, it’s the way that you do it. The only people who have a hope of becoming linchpins in any organization, who have any hope of changing anything for the better in real terms, are those who have the capacity to do “emotional work” at a high level—to be true artists at whatever they set their minds on doing. The guys who just plod around the office corridors, just turning up for their paycheck.... Well, those guys don’t have a prayer, poor things. The world is just too interesting and competitive now.

  7. Making Ideas Happen

    Though creation always begins with an idea, ideas don't always lead to creation; examining why that's so, online entrepreneur Belsky finds that, no matter how unique or radically different ideas may be, the individuals and teams who carry those ideas to fruition share a number of common traits, such as engaging peers and leveraging communal forces. In this guide to realizing ideas, Belsky examines those traits in detail.

  8. Talk Less, Say More: Three Habits to Influence Others and Make Things Happen

    Communication is the single greatest challenge in business today. It takes just 3 habits to conquer it. Talk Less, Say More will help you achieve more with less. Less wordiness. Less tune-out. Less frustration. You'll gain more time. More positive outcomes. More rewarding relationships.

  9. Influencer: The Power To Change Anything

    An influencer motivates others to change, An influencer replaces bad behaviors with powerful new skills. An influencer makes things happen. This is what it takes to be an influencer. Whether you're a CEO, a parent, or merely a person who wants to make a difference, you probably wish you had more influence with the people in your life. But most of us stop trying to make change happen because we believe it is too difficult, if not impossible. We develop complicated coping strategies when we should be learning the tools and techniques of the world's most influential people. But this is about to change. From the bestselling authors who taught the world how to have Crucial Conversations comes Influencer, a thought-provoking book that combines the remarkable insights of behavioral scientists and business leaders with the astonishing stories of high-powered influencers from all walks of life.

  10. Power: Why Some People Have It, And Others Don't

    Political skill, not just talent, is central to success in every field. In Power, this leading scholar comes down to earth with practical, even contrarian, tactics for mastering the power game.

  11. 5 Minds For The Future

    Gardner uses a variety of explanatory models, from developmental psychology to group dynamics, demonstrating their utility not just for individual development, but for tangible success in a full range of human endeavors, including education, business, science, art, politics and engineering. A tall order for a single work, Gardner avoids overly-technical arguments as well as breezy generalizations, putting to fine use his twenty years experience as a cognitive science researcher, author and educator, and proving his world-class reputation well-earned. Though specialists might wish Gardner dug a bit more into the research, most readers will find the book lively and engaging, like the fascinating lectures of a seasoned, beloved prof.

  12. UnMarketing: Stop Marketing, Start Engaging

    Marketing expert Scott Stratten focuses on a Pull & Stay method (pulling your market towards you and staying/engaging with them, leading them to naturally choose you for their needs) rather than Push & Pray

  13. The Moral Landscape: How Science Can Determine Human Values

    In this explosive new book, Sam Harris tears down the wall between scientific facts and human values, arguing that most people are simply mistaken about the relationship between morality and the rest of human knowledge. Harris urges us to think about morality in terms of human and animal well-being, viewing the experiences of conscious creatures as peaks and valleys on a "moral landscape." Because there are definite facts to be known about where we fall on this landscape, Harris foresees a time when science will no longer limit itself to merely describing what people do in the name of "morality"; in principle, science should be able to tell us what we ought to do to live the best lives possible. Bringing a fresh perspective to age-old questions of right and wrong and good and evil, Harris demonstrates that we already know enough about the human brain and its relationship to events in the world to say that there are right and wrong answers to the most pressing questions of human life. Because such answers exist, moral relativism is simply false—and comes at increasing cost to humanity. And the intrusions of religion into the sphere of human values can be finally repelled: for just as there is no such thing as Christian physics or Muslim algebra, there can be no Christian or Muslim morality.

  14. The Winner's Brain

    In The Winner-s Brain, Drs. Jeffrey Brown and Mark J. Fenske use cutting-edge neuroscience to identify the secrets of those who succeed no matter what-and demonstrate how little it has to do with IQ or upbringing. Through simple everyday practices, Brown and Fenske explain how to unlock the brain-s hidden potential

  15. Different: Escaping The competitive Herd

    If there is one strain of conventional wisdom pervading every company in every industry, it’s the absolute importance of “competing like crazy.” Youngme Moon’s message is simply “Get off this treadmill that’s taking you nowhere. Going tit for tat and adding features, augmentations, and gimmicks to beat the competition has the perverse result of making you like everyone else.” Different provides a highly original perspective on what it means to offer something that is meaningfully different—different in a manner that is both fundamental and comprehensive.

That's it :p. I have no idea how long it'll take me to read those books, but i suspect that it'll at least take me a year. And after that, i can start working on the other 40+ titles on my wish list :)

Monkey Patching FTW!

2 commentsWritten on October 4th, 2010 by
Categories: IronRuby, Ruby

Today, i had to get a CI build of an IronRuby project that a coworker and me have been working on up and running. We have a TeamCity server and i'm pretty familiar with it, at least as far as our .NET projects are concerned. But this is the first project we're using IronRuby on, and for now it's exclusively Ruby code that has to run on IronRuby. Our requirements of the CI build are very simple: check out the latest version of the code from Subversion, run the tests and make sure we can consult the test results from the TeamCity web interface. That's it. How hard can that be, right?

The thing is... we're not using an official IronRuby version. I basically get the latest code from IronRuby's GitHub repository from time to time, build it, and we use that. I've included all of the necessary files into our subversion repository so we can just refer to the correct IronRuby version with relative paths. And no, it's not because we're trying to be cool or hardcore, it's because we depend on a fix that has been implemented in IronRuby already but that isn't present in one of the releases. So my coworker sent me a link from the TeamCity documentation that mentioned that you could just use a Rakefile with IronRuby. Easy peasy! Well, except for the fact that it would require me to install the IronRuby build that we happen to be using on the build agents, and that i'd have to update it whenever i update the IronRuby binaries that we're using. Not exactly an approach i'd prefer.

So i was already thinking along the lines of "great, we're gonna have to write yet another custom test runner to report the test results back to TeamCity". We did it back when nobody cared about writing tests for Silverlight code, so i guess we could do it again. But i just sort of looked up to it. And then my coworker said "why not just monkey patch the test runner so it outputs the results in the format that TeamCity can understand?". And he was right. There's no reason whatsoever not to use a monkey patch to get out of this bind.

The final result is a pretty minimal amount of code that didn't take long to write which gets the results we need. Granted, i lost some time because at first i was monkey patching Test::Unit's console TestRunner only to find out that it's not really being used anymore if you're on Ruby 1.9... it's been replaced with MiniTest, which unfortunately (yet understandably) trades clean code for runtime performance. If Test::Unit's console TestRunner was used, the final result would've been less than 20 lines of code in total. Now, it's a bit more but it's still pretty minimal.

First of all, it's important to know the format that TeamCity can understand from your custom build output. You can find all you need to know about that here. Once you know the expected format, the solution is actually pretty easy: change the behavior of the testrunner at runtime so that it formats the output in a way that TeamCity can do something with it instead of its regular output. Turns out i could limit my monkey patch to just one of MiniTest's classes, that being the MiniTest::Unit class. First of all, we need to add some helper methods that we can use to take care of some of TeamCity's formatting requirements:

  def tc_output(string)
    tc_string = "##teamcity[#{string}]"
    puts tc_string
    tc_string
  end
     
  def tc_escape(string)
    string
      .gsub("|", "||")
      .gsub("'", "|'")
      .gsub("\n", "|n")
      .gsub("\r", "|r")
      .gsub("]", "|]") 
  end

With those methods added to the MiniTest::Unit class, we can now modify the behavior of 2 methods of this class to get the result that we want and need. First up, is the puke method, and no, i'm not joking... the method is actually called 'puke':

  def puke(klass, method, error)
    error = case error
      when MiniTest::Skip then
        @skips += 1
        tc_output "testIgnored name='#{method}' message='test ignored'"
      when MiniTest::Assertion then
        @failures += 1
        trace = MiniTest::filter_backtrace(error.backtrace).join("\n")
        tc_output "testFailed name='#{method}' message='#{tc_escape(error.message)}' details='#{tc_escape(trace)}'"
      else
        @errors += 1
        trace = MiniTest::filter_backtrace(error.backtrace).join("\n")
        tc_output "testFailed name='#{method}' message='#{tc_escape(error.message)}' details='#{tc_escape(trace)}'"
    end
      
    error[0,1]  
  end

This method is called by MiniTest whenever a test has failed... ignoring (or skipping in the MiniTest terminology) a test is a 'failure' (and i can't really argue with that). And obviously, both assertion failures or runtime exceptions are considered to be test failures as well. In either of these 3 cases, the puke method is called and it is supposed to output something to the user to notify him/her of the problems. So i basically just took the existing code, and modified it so its output would be in the format that TeamCity can work with. Next up is the run_test_suites method, which is responsible for, you guessed it, running the tests in the various test suites.

  def run_test_suites(filter=/./)
    @test_count, @assertion_count = 0, 0
    old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=
    TestCase.test_suites.each do |suite|
      tc_output "testSuiteStarted name='#{suite}'"
      suite.test_methods.grep(filter).each do |test|
        inst = suite.new test
        inst._assertions = 0
        tc_output "testStarted name='#{test}'"
        @start_time = Time.now
        result = inst.run(self)
        duration = "%f" % ((Time.now - @start_time)*1000)
        tc_output "testFinished name='#{test}' duration='#{duration}'"
        @test_count += 1
        @assertion_count += inst._assertions
      end
    end
    @@out.sync = old_sync if @@out.respond_to? :sync=
    [@test_count, @assertion_count]
  end

Again, i just took the existing code and changed its output so that TeamCity can work with it.

And the final result is this:

As you can see, build #2 didn't give you any feedback on the tests, even though they were being executed properly. Build #3 reported 2 failing tests, which were my temporary test cases to see how failed assertions or actual errors would be reported by TeamCity. Build #4 reports that all tests passed. In case you're interested, our 'build script' looks like this:

..\ironruby\bin\dotnet\ir -w tests\suite.rb

And that's it... pretty simple, no?

That just goes to show that while monkey patching is considered by a lot of people to be 'evil', it certainly has its benefits from time to time. I'm not saying you should use it as much as possible. But when it makes sense to do so, and if you're aware of the downsides and the pitfalls, then there's nothing wrong with it at all. Though it does require a language that treats you like an adult and expects you to know what you're doing ;)

Start Believing In Yourself

13 commentsWritten on October 3rd, 2010 by
Categories: life, Opinions

Far too often have i seen coworkers, friends or just people that i sorta know doubt themselves for no good reason whatsoever. Far too often have i seen this lead to missed opportunities, increased frustration and an ever decreasing amount of self confidence. For no good reason whatsoever. Each and every one of those people is capable of more than they give themselves credit for, yet very few of them would agree with me on that. And it is just such a waste. It's a waste of energy, time and talent/capabilities.

Me being the person that i am, i can't avoid sharing my opinion on this with them. And more than a few of them have said something along the lines of "that's easy for you to say, things just happen for you and you often just get your way". Well, i certainly don't get my way 100% of the time, nor would i want to because it would take away too many learning opportunities. But there is some truth to what they say because things indeed go 'my way' often enough. You wanna know why? Because i have a strong belief in myself. And when people talk to me, they generally realize that i'm indeed confident in my abilities instead of being perceived as insecure (note: it certainly isn't something i was born with, i had to 'cultivate' it)

And that, truly, is what you need to achieve for yourself. You simply can't expect anyone to believe in you if you don't even believe in yourself. You need to realize that you are capable of more than you give yourself credit for. You need to believe that you can improve and that there is more to you than what you're currently doing. You need to believe that there is no reason whatsoever that you should doubt yourself. Now, that doesn't mean that you should think the world of yourself or that you can do anything. That would in fact be highly counterproductive.

There are two things that you need to achieve something: one is hard work, and the other is confidence. You'll never get anywhere with hard work if you're not confident. And you'll never get anywhere if you're confident without putting in the hard work that really is required. Combine hard work with confidence however, and you will almost surely be rewarded for it in some way, sooner or later. It is however very important to remember that you should never be (or appear to be) over-confident. In fact, i've experienced on quite a few occasions that it actually helps tremendously to be completely honest about your shortcomings or any mistakes that you've made. If 'important' people ask you a question that you can't answer, don't bullshit them. Instead, simply say "you know, i have no idea... i'd have to look into that before i could make any statements on that". A lot of people are afraid to say that, but trust me, people will respect you for it. And if they don't, well, in the long term they're not worth trying to impress anyway.

Also, don't be afraid to talk about your shortcomings or faults. Everyone makes mistakes, everyone has issues, and everyone has flaws. Pretending not to have any of those will only result in people not believing you in general. Allow me to demonstrate this with an example. I'm gonna mention something about myself that quite a lot of you will laugh at. And even though there's going to be about 3000 people reading this, it really doesn't bother me to talk about this. Ready? Here it is: i utterly suck at parking cars. Yes, i'm male. Yes, i know we're supposed to be good at that. And yes, i know many people think it's embarrassing not to be able to properly park a car. And you know what? I truly couldn't care less whether or not that made you think less of me as a person, or a developer who's blog you happen to be reading, or even worse, are subscribed to. Because i know that it doesn't define me as a person. If anyone were to think less of me because i can't properly park a car, i'd take that as a big warning sign that that person probably has a shitload of insecurities himself and he's not quite being honest with himself. You've got issues as well and you've definitely got stuff that you're not good at either. Do yourself a favor: learn to accept it and be happy with what you can do.

And it really is as simple as that. Believe in yourself. Work hard. Be honest about your mistakes and your shortcomings. If you don't get any opportunities despite that, then you're wasting time on the wrong people, trust me (it's a lesson i very recently learned all too well). Build up your confidence. Go out and score with a hot chick (or guy if that's what you want), run a marathon, build some cool software, or do whatever else it takes for you to build up your self esteem. Seriously. Once you truly start to believe in yourself, you'll be amazed at how much easier life becomes. It's still not gonna be perfect, but well, at least you're gonna do a lot better than you used to. Quite frankly, there is no reason whatsoever to doubt yourself or your capabilities. You simply need to go out there and maximize those capabilities. And if you fail, as we all do from time to time, learn from it and come back stronger. That's really all there is to it.

Recommended Book: IronRuby Unleashed

3 commentsWritten on October 2nd, 2010 by
Categories: Books

As soon as i had a shot at using IronRuby at work, i searched for some books that thoroughly covered IronRuby since the documentation of IronRuby is, unfortunately, rather lacking. I only found 3 titles: IronRuby Unleashed, IronRuby In Action, and Professional IronRuby. Seeing as how IronRuby Unleashed is the only one that is actually available (Professional IronRuby's page on amazon shows a release date of June 2009 but it can't be ordered nor can i find a reference to the book on the publisher's website and IronRuby In Action isn't out yet), i ordered it right away.

This book covers a lot of ground. It starts off with a short introduction to the Dynamic Language Runtime and IronRuby and follows that up with some basic coverage of the Ruby language. If you already know Ruby, you can obviously skip this part since there won't be anything new for you here. If you're not familiar with Ruby yet and just want to learn about Ruby and how to use it together with .NET, you'll definitely appreciate this part, though i would recommend picking up The Ruby Programming Language to learn it more thoroughly.

Things get more interesting after this part, with a chapter dedicated to the fundamentals of interoperability between .NET and Ruby, more specifically: how .NET types and concepts can be used from Ruby code. The chapter after that takes a close look at how you can write Ruby classes that inherit from .NET classes. The next couple of chapters focus mostly on writing Ruby code that takes advantage of some .NET specific technologies, like ADO.NET, Windows Forms, WPF, ASP.NET MVC (there's also a chapter on Ruby On Rails btw) and Silverlight. Some of those chapters spend a little too much time explaining concepts that are related to the actual .NET technology that's being discussed instead of focusing more closely on writing Ruby code that takes advantage of those .NET pieces, but generally speaking they do a great job of covering many of the possibilities that you have with IronRuby.

You'll then learn about some of the options you have for writing automated tests in Ruby (either to test your .NET code, or to just test your Ruby code that runs on .NET). This chapter also contains introductions to 2 of the frameworks that the .NET world continuously tries to emulate: RSpec and Cucumber. After that, you (finally) get to the topic that interests me the most: using Ruby code from C#. This is a topic that never gets enough attention IMO. I wish you could find more information about this online, but it seems that few people who're using IronRuby are interested in consuming Ruby code from .NET instead of going the other way around (consuming .NET from Ruby). Anyways, it's good that this book covers some of the essentials of doing this. The book then concludes with a chapter on extending IronRuby with 'native' .NET extensions. This is interesting as well, though it's important to realize when (and when not) to use this.

It's not the greatest book on programming you'll ever read, as some of the examples could've been better IMO, or more extensive. Then again, it's the only available book on IronRuby at the moment, and it definitely covers a lot of stuff. It's easy to follow, and you'll definitely get a good view on all of your options with regards to combining Ruby and .NET. In short: if you're interested in combining Ruby with .NET, this book is definitely worth buying.