Code Kata: Translate a decimal text to roman

A code kata is a an exercise of coding where the objective is to use simple requirements to train the coding and testing skills.You can use it to train brainstorming and analysis within the team as well.

The subjacent idea is to use the martial arts concept of kata to coding, where repetition leads to perfection.

A few tips:

  • Try to fit the analysis, coding and testing within a small range of time, like 2 hours or less.
  • Remember if it takes too long or demands a big effort, there will be no motivation to repeat it in another session.
  • Most of the exercises exist to train the TDD methodology.
  • You can find several exercises in the internet for your use, or just invent one yourself.

Translate a decimal text to roman

Imagine you have a text, or a list of texts, such as the one below, with words and numbers.
(or just write a text with words and numbers):

You want to replace all the decimal numbers with roman numbers

That said, there is also considerable cause for optimism among those who support OER. The awareness and adoption levels may be low, but they also show steady year-to-year improvements. For example, the open-licensed textbook adoption rate of 9% for 2016-17 represents a substantial increase over the rate of 5% for 2015-16. Likewise, awareness of both Creative Commons licensing and OER itself has increased each year.
OER also addresses a key concern of many faculty: the cost of materials. A majority of faculty classify cost as “Very important” for their selection of required course materials. Faculty report that their required textbooks have an average price of $97, and only 22% say that they are “Very satisfied” with that cost. It is therefore not surprising that most faculty report that not all of their students buy all the required texts for their class, with only a third saying that 90% or more of their students have purchased the required textbook.

Have a nice session!


If you implement this kata and you publish it in the internet, be kind a refer to this article. 😃

The text used in the exercise was extracted from a text file I have found in the internet. There is no special meaning to consider.

dynamic and ExpandoObject

tree_volteretaThe dynamic and ExpandoObject have a relation of love and hate with .NET developers. One side defends strongly typed objects to handle data, so it’s possible to handle a lot of issues at compile time. The other side, are developers used to develop scripts, python, and in other similar languages. They defend the dynamic nature of the current projects, with a lot of Xml, Json and unstructured data, so they prefer to use the more dynamic and functional structures of C#. Both are right! Some like to live strong typed and predictable, others like to live on the edge!

Personally, I am a hybrid developer, I like the strong type of languages, but love python and dynamic freedom, like C# provides. So it’s usual for me to use strongly typed objects on my projects, but every time I have to deal with unstructured data, I use the dynamic word and other constructs like Tuple class.

Because sometimes there are too many DTOs on the project!

ExpandoObject Basic Usage

ExpandoObject with methods

Reflection on the ExpandoObject

Java Infinite Loop

An Infinite loop in Java, but not to everyone!

One of the things, after all these years, that keeps me fascinated about coding, it’s finding curiosities in a few lines of code that make me think for a while!

public class JavaPearls {

    public static void main(String… args){

        Integer a = new Integer(10);

        Integer b = new Integer(10);

        for(;a<=b && b <= a && a != b;)




Shared or Static – Visual Basic vs Java?

MP900386814 In Java there are 2 fundamental concepts that any developer should know: instances and classes. Class its the base of your code, your specification about an entity, like Account, Customer or Supplier. Instance its what you get after a “new ” (an object in the heap). So you have at maximum 1 class and N instances of that class.

Although a class its just the specification, in Java a class could have state and behavior like an instance, but with the condition “There could be only one” shared for all instances! Everything that are declared as static are executed(static blocks for instance)/initialized at class load time by the JVM, the rest (instances) are executed/initialized in runtime, after load time.

This word, static comes from very long time, since C, C++, C# and others, but Visual Basic uses other word “shared which somehow implies the behavior of the fields declared as static(java) or shared(visual basic) after a Class “is running”! After the JVM has loaded your class, every static(java) field are shared(visual basic) between all instances, so the question is:

What of these words captures better this behavior (of static) “static” vs “shared”?

So, although I really like a lot languages like C++, Java and C#, I must admit Visual Basic its somehow more expressive and more closely related with the true meaning of “shared” fields!

The not so ACID transaction properties

If you work with Database Servers you know that ACID its not implemented/active by default! And if you have it implemented you have a really poor performance on your database server!

Lets examine each one of these properties:

A = Atomicity

Definition by wikipedia: “Atomicity requires that each transaction is “all or nothing”: if one part of the transaction fails, the entire transaction fails, and the database state is left unchanged. An atomic system must guarantee atomicity in each and every situation, including power failures, errors, and crashes.


– “… and the database state is left unchanged“. Unless you configure your database server with ISOLATION LEVEL SERIALIZABLE this is not true. By default most SGBD are configured with Read Commited, with allows some changes like phantom reads.

C = Consistency

Definition by wikipedia: “The consistency property ensures that any transaction will bring the database from one valid state to another. Any data written to the database must be valid according to all defined rules, including but not limited to constraintscascadestriggers, and any combination thereof.”

RIGHT for schema state, WRONG for value state (explained in atomicity above)

I = Isolation

Definition by wikipedia: “The isolation property ensures that the concurrent execution of transactions results in a system state that could have been obtained if transactions are executed serially, i.e. one after the other. Each transaction has to execute in total isolation i.e. if T1 and T2 are being executed concurrently then both of them should remain unaware of each other’s presence

WRONG! Only in dreams! its possible, yes, but in the way you encounter DEADLOCKS and Poor performance. If you want a performance database server you must drop the isolation to the lowest level possible! Its the price to pay for having fewer locks in the middle of your transactions.

D = Durability

Definition by wikipedia: “Durability means that once a transaction has been committed, it will remain so, even in the event of power loss, crashes, or errors. In a relational database, for instance, once a group of SQL statements execute, the results need to be stored permanently (even if the database crashes immediately thereafter).”

RIGHT! Well, I give this one, and I’m glad I could, what was a database server without it! 😉 However, actual high performant database servers have some kind of memory cache where there is a risk of loosing data, but, as far as my knowledge goes, it only happens in some NoSql databases… I hope…




php learning

Learning PHP – Step 4 – Statements

In my last post I’ve talked about variables and operators. Now, lets see what can we do with them.

Statement: if

The “if” statement has 3 main forms:

        Learning PHP – Step 2
                 $name = "José Cruz";
         $even = 10 % 2;
         $odd = 10 % 3;
         $someValue = $even * 4;
         $ifvar = 1;
         // it’s even – simple "if"
         if($even == 0) {
             echo "10 its even!";

         // it’s even – simple "if" with an else
         if($even == 0) {
             echo "10 its even!";
         } else {
             echo "10 its odd! Really?";
         // it’s even – complex "if"
         if($even == 0) {
             echo "10 its even!";
         } elseif($ifvar == 1) {
             echo "Althougth true, the first branch has already taken the flow! :(";
         } elseif($ifvar == 2) {
             echo "Just to ensure you understand this construction!";
         } else {
             echo "10 its odd! Really?";


Statement: switch

“switch” it’s a variation of “if”, but for cases where we have some kind of a list of values belonging to a common domain, like: weekdays, months, (1,3,4,5), etc.

The expression inside “switch()” its evaluated and the result will be compared with each of the “case ”. Each “case” can have the “break” statement, which terminates the statement. If its missing, the execution flow goes to the very next “case” (if its valid) until a “break” it’s found.

If a “case ” was not found, then the “default” its used (it it exists).

        Learning PHP – Step 2
                $weekday = 1; // assuming a week starts on sunday with value 1
        switch($weekday) {
            case 1:
                echo "Sunday";
            case 2:
                echo "Monday";
            case 3:
                echo "Tuesday";
            case 4:
                echo "Wednesday";
            case 5:
                echo "Thursday";
            case 6:
                echo "Friday";
            case 7:
                echo "Saturday";
                echo "big mistake1";


And that’s it!

Next post about loops!


Technorati Tags: ,,,,,,,
Windows Live Tags: programming,else,switch,if,php,Statements,expression,break
WordPress Tags: programming,else,switch,if,php,Statements,expression,break

php learning

Learning PHP – Step 3 Basics

Following previous posts, lets start with the basics.


– Always start with $ and can have the following chars _ [a-z] [A-Z] and [0-9]. the first symbol must be an _ ou a letter.

$count = 0;
$name = “José Cruz”


What about types? If you know python, ruby or the “var x = 0;” construction from C# you know how PHP works. It converts the variable for the type defined by the value initialized. For instance: $count = 0; will be an “integer”.

Lets use some variables in our script:

        Learning PHP – Step 2
                $name = "José Cruz";
         echo $name . " is starting to understand PHP!";

If you run the script above it will display “José Cruz is starting to understand PHP!”

PS: The dot between $name and “ is starting… ” is the concatenation in strings. This is new. Other languages usually use the plus sign or some function to do it.

The operators are the same as C or mainstream languages:

Arithmetic: +, ++, –, –, *, /, %

Assignment: =, +=, –=, *=, /=, %=, .=

Comparasion: ==, <=, <, >= >, <>, !=

Logic: &&, ||, !

PS: You can use “(“ and “)”

Some examples:


$a = 5 + 2 * (7 + 5);
$b = $a –4;
$c = $a / $b;
$even = 10 % 2;
$a+=7; // same as $a = $a + 7;
$even = 10;
$even %= 2;
$verytrue = 2 < 7;
$veryfalse = 6 >= 3;
if( $a > 3 ) …. // future post we talk about if and other statements.
if( $a > 3 && $b < 10 || $even == 0 ) …


As with other languages:

– Unary operators precede all other ones ( “!” )

– then: *, / and  &&

– Last: +, –, ||


Lets try this in our php website:

        Learning PHP – Step 2
                 $name = "José Cruz";
         $even = 10 % 2;
         $odd = 10 % 3;
         $someValue = $even * 4;
         echo $name . " is starting to understand PHP with some operators" . "
         echo "even values: ". $even . "
         echo "odd values: ". $odd . "
         echo "some value = " + $someValue . "


Run it!

Next post: statements.

Technorati Tags: ,,,,
WordPress Tags: language,programming,Variables,Basics,PHP

php learning

Learning PHP – Step 1


I develop in several programming languages like C#, VB.NET, VB, Java, JavaScript, Python, Groovy, Powershell, PL-SQL, T-SQL, a little of Ruby, C, C++, Assembly (in the last years not so often), Prolog, List/Scheme, F#, Perl and and few others less used. I’ve read and I can understand PHP, from the knowledge I have from “C” Languages, but I never developed a complete project in PHP, and I don’t know if in the future I will need to do it, but from what I’ve been reading PHP is used in the TOP CMS Frameworks/Applications as WordPress, Drupal, Joomla, etc.

I’m thinking to create a synergy here, I will deep my understanding and knowledge about PHP and WordPress, tweaking my blog, this blog! Which I think will enrich my CV and, in the future, my career, making me a better team leader and software architect.

Starting PHP.

1) It’s a language to use in web sites.

2) You mix HTML with PHP, which is different from ASP.NET and JSP for instance. To differentiate the HTML from PHP you use in the middle of the HTML. The server will know how to process the PHP and merge it with HTML.

My first example in PHP


This code will output “My first PHP!” in the browser.

Great! It’s the first step!

Next Post let’s install the software we need to run this example. Then, the sky it’s the limit!