Sunday, January 26, 2020

strategic v0.8.0 - Painless Strategy Pattern in Ruby and Rails

Strategy Pattern is one of those patterns that many developers agree is good but few practically apply in day to day work. As a result, you see codebases littered with hard to maintain if/case conditionals.

This problem is finally solved with the 'strategic' rubygem (Painless Strategy Pattern in Ruby and Rails):


if/case conditionals can get really hairy in highly sophisticated business domains. Domain model inheritance can help remedy the problem, but dumping all logic variations in the same domain models can cause a maintenance nightmare. Thankfully, Strategy Pattern as per the Gang of Four solves the problem by externalizing logic variations to separate classes outside the domain models.

Still, there are a number of challenges with repeated implementation of Strategy Pattern:

  • Making domain models aware of newly added strategies without touching their code (Open/Closed Principle).
  • Fetching the right strategy without use of conditionals.
  • Avoiding duplication of strategy dispatch code for multiple domain models
  • Have different strategies mirror an existing domain model hierarchy

"strategic" solves these problems by offering:

  • Strategy Pattern support through a Ruby mixin and strategy path/name convention
  • Automatic discovery of strategies based on path/name convention
  • Ability to fetch needed strategy without use of conditionals
  • Ability to fetch a strategy by name or by object type to mirror
  • Plain Ruby and Ruby on Rails support
"strategic" enables you to make any existing domain model "strategic", externalizing all logic concerning algorithmic variations into separate strategy classes that are easy to find, maintain and extend.

Learn more on GitHub:

Tuesday, November 26, 2019

Glimmer v0.1.10.470 Computed Value Data Binding

Glimmer v0.1.10.470 has just been released with Computed Value Data Binding.


Computed Value Data Binding Example:

Read more about Computed Value Data Binding under the Syntax section.

Sample on GitHub:

Happy Glimmering!

Wednesday, July 03, 2019

Is OOP compatible with Functional Programming?

Actually, OOP (Object Oriented Programming) was born out of Functional Programming and as such is still considered an advanced application of it.
Watch this 1986 MIT Computer Science class about the SICP book (Structured Interpretation of Computer Programs) and see how it covers OOP in Lisp, one of the oldest Functional Programming Languages out there:
OOP is basically illustrated as nothing other than smart data that knows its own operations automatically through polymorphism.
Complex numbers can have one of two representations:
  • Rectangular
  • Polar
Each representation has its own algorithms for basic algebraic operations:
  • Add
  • Subtract
  • Multiply
  • Divide
To avoid manually selecting the right algorithm function for each data representation, one may rely on typed data in Lisp so that the data representing complex numbers will know its own operations based on whether its internal representation type is rectangular or polar, and be able to dispatch the right function automatically via polymorphism.

Sunday, June 30, 2019

Puts Debuggerer (debugger-less debugging FTW) v0.8.1

Puts Debuggerer (debugger-less debugging FTW) Version 0.8.1 has been released.

Yes, many of us avoid debuggers like the plague and clamp on to our puts statements like an umbrella in a stormy day. Why not make it official and have puts debugging become its own perfectly legitimate thing?!!
Enter puts_debuggerer. A guilt-free puts debugging Ruby gem FTW!
For background, please read this blog post by Aaron Patterson:
Ruby gem may be found over here:

Thursday, February 14, 2019

Tic Tac Toe Sharp

Though I have many years of experience in Java and Ruby, I just got my first experience in building a C# project the other day, a small Tic Tac Toe game. It is a command-line program coded with the new Visual Studio Community for Mac.

The code has been posted over here:

Pattern Applied: Model-View-Presenter.

TicTacToe is the game Model based on IGame interface, which houses all the logic for making moves, checking for win or draw, and maintaining the board status after every move.

TicTacToeUI is the Presenter of the game model, sending game output to the View and acting as a controller to process input from the user.

MyConsole based on IConsole interface and leveraging C#'s Console is the View, which renders output to the screen and receives input from the user

Noteworthy Details:

  • Starting development in C# with the mentality of Java development worked out quite well
  • Looking for Functional Programming features such as Lambda Expressions from Java 8 and block iterators from Ruby got me discovering LINQ pretty quickly
  • Dynamic typing was available too, which I toyed with initially given my attachment to it from Ruby, and then later reverted to static typing given I discovered the types I needed
  • Attribute getters and setters are on par with Ruby's and probably better than Java's non-existent support for attributes (without using some meta-programming annotations)
  • Operator overloading/indexers are on par with Ruby's and better than Java's lack of support for operator overloading
  • Interface based polymorphism of methods felt cumbersome compared to Java as I had to cast a class object into its interface to invoke interface methods
  • Package management was as good as Java's
  • xUnit testing was as good as Java's and Ruby's
  • Utility methods seemed to support me completely and be on par with utility methods in Ruby and perhaps slightly better than Java's (felt that way though could be just equal)
  • While Visual Studio Community for Mac includes some built-in refactoring features, such as class rename, it is definitely inferior to Eclipse, IntelliJ Idea, and IntelliJ RubyMine. It seems ReSharper, a tool offered by IntelliJ's company JetBrains to enhance Visual Studio is a must. I didn't get to toy with it, but I would imagine I'd do so on future C# projects.
Overall, I felt well supported by C#'s versatility and not lacking any programming features from Java and Ruby.

That has not been my experience with other languages that compare to Java or Ruby. For example, Rust, which I've looked into recently, has a very steep learning curve (albeit quite fun) to writing code that auto-manages its own memory without a garbage collector (Rust's highest selling point and greatest innovation). Also, Perl in its later incarnation seemed to be a clone of Perl-inspired Ruby, providing most of Ruby's features, but with alternative syntax, making me wonder why switch at all. Yet again, that means I get to have the option of consulting for Perl projects if need be (though no sane Rubyist would :P ). The same goes for C# after doing more learning in it. 

I probably did not exploit every C# feature in the course of writing this mini-project.

Comments are welcome, especially that I could be way off in this article due to being new to C#, and would like to be corrected if so.

Cheers and happy coding!

Saturday, January 12, 2019

What is Software Value?

In software engineering, we are often asked to deliver value. Yet, what exactly is software value?

The following questions and answers might help explain it:

What truly constitutes value?

Serving the customer true business needs as opposed to only responding to customer requests, thus providing true customer satisfaction in the long term.

Isn't value subjective?

Value can be subjective, thus requiring a lot of business analysis and usability research to figure out the best software to build. For example, in usability engineering, user testing involves observing users and discerning what serves their needs independently of what they say.

Isn't value the sole concern of the business?

Employees serve the business, and so business concerns become their own too, but each plays a specific role towards attaining software value. For example, in baseball one may think that winning is the sole concern of the team's head coach/general manager, and yet every player must keep that concern in mind while playing their specific role; pitcher, batter, or catcher.

Isn't value a vague term?

All terms are vague if you don't share context with others. Nonetheless, keeping value delivery in mind focuses us on doing what's right to truly serve the customer. Otherwise, we risk getting lost in copying the competition or offering people what they say without addressing their real concerns.

Isn't delivering value as obvious as doing what the manager asks you to do?

It could be if you're a junior software developer unable to discern value yet. As you grow and progress in the field though, you start bringing your own perspective regarding what value is and better discerning what serves the customer and business.

How about value being as obvious as making people feel good?

Feeling good is not the same as customer satisfaction. For example, if a user is getting work done with a piece of software, what serves their needs is doing work correctly and fast, which might not necessarily feel good as it's hard work. As such, you wouldn't target good feelings or else you risk falling into the trap of offering irrelevant features. For example, imagine online spreadsheet software that offers music playback as a feature because it feels good to listen to music while working. Obviously, this is useless for work software not concerning music and might even distract from a good job. Instead, target offering the best business and customer value by figuring out how to best serve business needs (e.g. cloud storage of spreadsheets instead of requiring upload/download on every use).

Always stay open-minded about the perspectives of your colleagues to come up with the best value. I like to share just enough of my opinion, while listening to other developers as well as other team players like usability designers, software architects, and quality assurance folks.

In summary, deliver software value, keep the business and customer in mind, and learn to focus on customer needs not wants.

Saturday, November 25, 2017

puts_debuggerer 0.8.0 is out!

puts_debuggerer, the library for improved Ruby puts debugging, now has better support for Rails.

In a Rails environment, puts_debuggerer now automatically outputs to Rails logs at the debug level. This is facilitated using the new "printer" support, which is a configurable option that comes with smart defaults.

The "printer" option value can be a global method symbol or lambda expression to use in printing to the user. Examples of global methods are :puts and :print. An example of a lambda expression is lambda {|output|}
It defaults to :puts , but if Rails is detected, it defaults to: lambda {|output| Rails.logger.debug(output)}
# File Name: /Users/User/example.rb
PutsDebuggerer.printer = lambda {|output| Rails.logger.error(output)}
str = "Hello"
pd str
Prints out in the Rails app log as error lines:
[PD] /Users/User/example.rb:5
   > pd str
  => Hello

Learn more about puts_debuggerer over here: