Categories
ASP.NET C# code General Git Tips

Show me your progress with your commits

Git Commit

I’m currently working in a new application. It’s an ASP.NET MVC site written with C#. We are using the following technologies: Windows Communication Foundation, Knockout, Bootstrap, PostgreSQL, and Git.

I’m working on a new feature that will require me to make changes to the UI, javascript files, add new database tables, add service methods, add unit and integration tests. In other words, I have to modify all layers in our application.

To accomplish this task, I decided to try something different. I want to show my progress with my git commits. I want to complete small tasks and then commit my changes. For this specific task, I started writing a falling integration test. This failing test forced me to create the new database tables needed. After creating the tables, I ran the tests again and this time everything was back to green. At this point, I’m ready to commit these changes. This commit is the beginning of my work and it gets me closest to the final goal. I go ahead and commit this change.

commitTableCreation

After adding the database tables, sql scripts to generate them, and some unit tests, I’m ready to start adding service methods, data contracts, etc. For this task, I follow the same technique as above. My unit tests pass and I have not broken the build so it is time for another commit. With this second commit, I’m feeling productive. I have accomplished something. I can show my progress to my boss or team members with these small commits.

On the other hand, working for a long time without committing your changes, makes me nervous. What would happen if your hard drive fails? It happens all the time. I think we all have experienced losing our work. Many times it was something other than a hardware failure. It was a human error. For example, we deleted some files that were not in source control by mistake.

That’s why I like to commit often. As long as my project builds and my unit tests pass, I’m going to commit my small changes. I know that these commits don’t fulfill a complete feature, but they take me a step closer to my finish line.

After a few commits, I have accomplished enough back-end code that I can concentrate on the UI. Here is the initial version of the UI:

ContractSurvey

It is not perfect. I know that changes are inevitable. I would say that right now I have completed 80% of the task needed to bring this work to completion. I have 20% more to go and I can see the finish line. Seeing the finish line motivates me to do my best and finish strong.

I urge developers to commit small changes and commit often. Remember that these small changes will help you accomplish your goals sooner rather than later.

Categories
Beginners code ruby ruby on rails rubygem unit tests

Read Minitest To Learn Ruby

I continue my quest to master Ruby. Lately I’ve been reading the source code for Minitest. Minitest is a Ruby gem to help developers write unit tests. In addition, you can also use Minitest to write specs and do your development BDD style. The gem also has support for mocking and benchmarking.

Let’s concentrate our attention on the assertions.rb file located at https://github.com/seattlerb/minitest/blob/master/lib/minitest/assertions.rb. Inside that file, we can see that the assert method takes 2 parameters: test and msg. Below is the actual Ruby code.

##
#  Fails unless +test+ is truthy

def assert test, msg = nil
  self.assertions += 1
  unless test then
    msg ||= "Failed assertion, no message given."
    msg = msg.call if Proc === msg
    raise Minitest::Assertion, msg
  end
  true
end

The first line inside the assert method, self.assertions += 1, is increasing the assertions variable by 1. This value is display after your unit tests are run. Something like 10 assertions, 5 pass, 5 failed. Next we see the unless keyword followed by test and a block. Having the comment above this method, really helps us understand what unless is. The unless block will be executed if test is false. Inside that block, we set a default message to msg if msg is nil or false. The next line checks if the msg passed to our method is a Proc object. If msg is a Proc object, msg will be assigned the value returned from invoking the block. To learn more about the Proc class, go to the official Ruby docs. Then we raise an exception by calling Minitest::Assertion and passing the msg variable.

After executing the unless block, we return true.

I believe Minitest is an excellent resource to learn Ruby. It’s a small code base compared to other projects.

Categories
code open source python

My first contribution to the Python language

contributing to python

Python is an object-oriented language created in the early 90’s by Guido van Rossum. It is used by major corporations like Google, Dropbox, Mozilla, Ebay, Paypal and many others. Since Python is an open source language, contributions from the public are encourage and welcomed.

For the last few weeks, I decided to install it on my machines and start reading the documentation. Python’s documentation is well written and easy to follow. The first thing I did was to start reading the PEP files. PEP stands for Python Enhancement Proposals. These documents are text files submitted by the community to enhance the language. One of the most popular PEP is PEP 8 which is the style guide for Python code.

When I started reading PEP 3, there was a broken link. I tested this issue with different browsers and I was always getting a 404 error. So I decided to email the python development group. Within a few hours, I got a response from Victor that indeed PEP 3 had a broken link and he gave me the correct link. I was in the process of creating a new bug and submit a patch but a core developer was able to update the link.

pep8UpdatedLink

Based on the positive response and support I received from the python contributors, I plan to keep contributing to the python code. If you want to start contributing to Python, go to the developer’s guide to get familiar with the documentation and source code.

Categories
Beginners code ruby

Hour of code with Ruby

hour of code with ruby

Ruby is a “dynamic, open source programming language with a focus on simplicity and productivity”. That’s the definition taken from the official ruby site. Ruby is a fun and easy language to code in. Recently, I heard of hour of code, a movement to introduce computer science to million of students.

With that in mind, I want to share an excellent site to learn ruby. Go to tryruby.org and follow the instructions to start writing ruby code. There is nothing to install and you get clear instructions and instant feedback.

For example, you can type “2 + 2” and then press enter in the interactive window, you will see “4”.

Go ahead and have fun learning ruby.