Posts tagged with Code
You are browsing posts about Code. Check out all posts on our blog.
There is a new drama in the software development community, and it's about
whether you should learn to
code or
not.
I think the best ideas are somewhere in the middle of all the extreme statements
and blog post titles that get upvoted on Hacker
News.
I think you should learn to "code," but not because it might make you a
"coder".
More after the break.
→ Read More

Highgroove really likes Pry. It's a great tool for digging into your code and seeing what's going on with tons of great features. However, there are situations where using a standard binding.pry breakpoint will not block your program and allow you to inspect it. I recently ran into this situation when trying to debug an application that used Foreman to manage it's processes. Luckily, the pry-remote project turned out to be a great solution.
→ Read More

The latest version of Ruby comes standard now with Comma Separated Value support built right in via the CSV
library written by one of our very own alumni, James Edward Gray II. You might know CSV as the extremely portable format file used for everything from Excel Documents, to Numbers Spreadsheets, to lists of emails, to even generic data files. The CSV library is quite generic and useful by itself, but sometimes, you really need the expanded capabilities that only an Excel or Numbers document can support. Read on to find out how to generate Excel and Numbers compatible .xlsx files with Ruby.
→ Read More

As the web continues to mature, JSON APIs (and XML if you're into that)
have become increasingly important. But if you've tried to use Rails to
write an API recently, you know there are a handful of competing
methods and gems focused on making this better. I'm all for
interchangable libraries, but, as Yehuda Katz pointed out in his recent
talk at RailsConf, Rails needs a "convention over configuration" approach
to solving the JSON serialization problem once and for all. So I was
pretty excited when I heard about Jose Valim's ActiveModel::Serializer.
→ Read More
Sunspot, a Ruby interface for Solr
usually backed by ActiveRecord objects, recently introduced native geospatial
searching capability in the master branch (currently a 2.0.0 prerelease).
While the functionality has not been released as a stable version yet, I felt
that a blog post introducing the features is appropriate with the hope that
folks will try it out and give feedback!
Read on for a short example.
→ Read More
At Highgroove we really like testing and are constantly looking for ways to
improve our testing process, how quickly our tests run,
and how exactly we execute our tests. How often during your Test Driven
Development (TDD) cycle do your tests fail "mysteriously"? You've written your
tests, written your code, and most of them pass but one or two stubbornly fail
even though you are fairly certain they should pass given the testing setup
you've provided? At Highgroove we bias towards action so we are likely to
launch a debugger session or a pry session to get
to the bottom of this. Another approach, which won't break your existing TDD
workflow, is to use your test-suite in place of a more traditional debugger.
After the jump we'll talk about how we've been using this strategy to dig into
code quickly and easily.
→ Read More

Database-bound tests are a drag. Inconsistent tests are a pain.
Database-bound, inconsistently failing tests are the worst!
The following commit message is from a real code base:
Run in transactions by default.
When we added controller specs they weren't being run w/any kind of DB
cleaner b/c there was no default strategy and they weren't explicitly included
in a group. Now, we use :transactions be default, setting request specs to
use :truncation
Also, I saw a 2 second speed up from this change!
Let's look at what we changed in this commit to turn our inconsistently
failing database-bound tests into slightly faster, consistent, database-bound
tests.
→ Read More

This weekend we Highgroovers (a.k.a. Taconauts) took some time to do one
of the things we really love: create and release Open Source Software. In
fact, we released not one, but three new tools into the world:
grocer, git_tracker, and puppet-osx_defaults.
→ Read More

Refactoring is a something we spend a bit of time on at Highgroove, so much that David recently wrote about refactoring and related tools in Red, Green, Refactor and I'm writing with even more on refactoring and the 'Refactoring Rabbithole'.
"When refactoring, it's easy to see 10 other things that probably should/could be refactored"
Spending time on refactoring is a tough sell to clients: by definition, the 'backend' can be completely re-done without any visible changes in an application. As the complexity and size of a project grows, refactoring can be necessary to keep things as simple as possible, keep the code quality high, and keep the number of bugs low.
→ Read More

Ruby inherits the philosophy of "there's more than one way to do it," or TMTOWTDI, from Perl. Of course, TMTOWTDI is worthless unless at least a handful of those ways can be written clearly not just for the author, but (perhaps more importantly) for future readers and editors. So, how do you make the best use of the many ways Ruby and Rails allow you to do things?
→ Read More

A recent project we worked on at Highgroove involved scheduling events
on a calendar. These events had a lifecycle of "statuses," such as
"pending approval" and "approved."
All users were able to set the "status" to values such as "pending
approval," but only certain privileged users could move them to states
such as "approved."
We were already using CanCan for
authorization, but there was no built-in facility for authorizing
field-level changes. There were workarounds in certain cases, such as
using custom
actions, but none
of these fit with our specific use case.
Read on for how we modeled the problem and used a Plain Old Ruby Object
(PORO) to keep things clean.
→ Read More
Waaaayyy back in December, I had the pleasure of attending a code
retreat.
In that post, I discussed what I learned.
This month, I had the pleasure of facilitating a code
retreat a few weeks
ago. Thanks to
Highgroove, TapJoy,
FourAthens, and my co-coordinator Travis
Douce, the Athens Code Retreat was a resounding
success.
Also, a special shout out to our Code Retreat homies in South
Africa led by
Corey Haines, who handed off the baton to us late in
their day but early in ours.
Read on to find out how lessons learned from facilitating compares to attending,
how the general "You" actually means "I" in the blog title, and how many times
it takes (me) to learn the four rules of simple design.
→ Read More

It's easy to say "We're agile" and "We use Behavior/Test Driven Development" and
thus "we use the right tools to empower our developers!" but what are those
tools? For me that discussion is entirely about the tool stack you choose, how
that stack empowers you as a developer to do things right the first time.
Luckily thanks to the ruby community as a whole we have a large number of
high-quality choice to choose between.
→ Read More
by andy
Published January 10, 2012 in
Code

We help one of our clients operate a high traffic API that, among other
things, returns data that is associated with an IP address range. It's
similar to querying for information from WHOIS.
The IP address ranges are specified in a MySQL database with ip_start and
ip_end columns. The IP addresses are first converted to their
representation as 32-bit integers.
For instance, the range 1.1.1.1 to 1.1.3.3 would look like:
| ip_start |
ip_end |
... |
| 16843009 |
16843523 |
... |
Read on for more about how we helped optimize the queries that search
for an IP within these ranges.
→ Read More
I've often felt like Ruby Regexp captures are a bit clumsy.
Let's say we need to break apart phone numbers:
After executing this match, we might do something like this with the parsed number:
What's up with the dollar signs and the sequential numbers?
I feel like I'm writing assembly code and referring to registers or memory offsets or something.
If I'm a new Ruby programmer reading this code, I might have no idea what is going on here.
We can do better
→ Read More
In case you missed it, the awesome Globay Day of
Coderetreat occurred on
December 3rd. The amount of fun I experienced was unexpected and impressive!
I learned some things too. Read on to find out what.
(Also, don't worry if you missed the code retreat, sad kitten has some good news
for you at the end of this post.)
→ Read More

One of the more complicated Ruby/Rails projects we work with at Highgroove
has many points where it interacts directly with the filesystem.
Writing tests for an application whose code requires reading from or
writing to the filesystem presents challenges, especially if done
naively.
While it's tempting to simply use the real filesystem during unit tests,
this presents a few problems:
- The tests may be brittle, breaking on systems that are not setup
just like the initial developer's local environment.
- Setting up fixtures on the real filesystem may not be plausible;
for instance, if the code interacts with system files (such as in
the example coming below!).
- Test code must be careful to clean up afterwards, even in error
cases. Otherwise, the file system could be left polluted, dirtying
the developer's machine and possibly breaking tests on the next run.
- Tests running in parallel may interact with one another, causing
random failures (e.g., on a continuous integration server or with
parallel_tests).
- The filesystem is slow; when attempting to make unit tests as fast
as possible, the time to write, sync, and/or read from the
filesystem may become significant.
So what's the solution? Fake the filesystem during unit tests.
More after the break.
→ Read More

At Highgroove Studios, we're hyperspecialists in Ruby on Rails web application development. Not only do we write amazingly complicated code on time and on budget, but we follow up all our work with tests so we know our code works.
This is not without its problems however, as a test suite can become just as bloated and difficult to update as the code base it tests! This week, I'll talk about some of the ways I've learned to approach writing tests.
→ Read More

Cluster analysis methods have been gaining popularity as a way of Relating pieces of data in large datasets with one another. Examples in social networking are obvious: friends on Facebook cluster into cliques and communities, which cluster into even larger groups. Demographics and other marketing research can also be aided by sorting prospective customers into groups based on preference.
→ Read More
RubyConf, ahhh Rubyconf.

How was it this year you ask? To answer that question we must first address the
question:
How was my first ruby conf?
→ Read More

I recently got to work on some really interesting, big data problems at Highgroove. One of our clients needed to record every api call and analyze specific time periods for averages and usage metrics. Hadoop fits this use case pretty well with a distributed file system and map reduce framework built in. But, I'll be honest, I wasn't too happy about having to write map reduce jobs in Java. While looking for alternatives I found Wukong; a gem that adds a Ruby wrapper around the Hadoop Streaming utility. Here's an example of how easy it makes writing map reduce jobs.
→ Read More
Here at Highgroove, we do
code
reviews,
which ensures everyone is reading some code on a regular basis. However, being a
developer usually means you'll be reading code regularly anyway. In the past, I used to avoid this if I could. However, now I've learned how much I can get from it, and use it to improve myself as a developer.

Reading code isn't easy, and I certainly didn't want to do it when my only goal
was figuring out why a gem wasn't doing what it promised. It was much easier to
just find someone familiar with it and pick their brain. However, there's more
to be gained from reading source code than you may think.
→ Read More
ActiveRecord is wonderful for the easy queries. But there are times, in the
name of performance, when one must bust through the ORM facade and dip below
into SQL.
Edit: Updated gist to fix SQL injection. Thanks to all the code reviewers, uh I mean commenters, for pointing it out!
Also pointed out in the comments, using lambdas in this pattern makes most sense for Rails 2. In Rails 3, AREL is composable so one can use class methods.
Wed Jun 29 13:55:27 EDT 2011
→ Read More
by andy
Published May 04, 2011 in
Code
At Highgroove, we are pragmatists. While we value writing clean, maintainable, and extensible code, we also value shipping features for our clients in tight iterations.
Sometimes it feels like achieving both of these goals is simply not possible … and yet focusing on either one at the expense of the other is not satisfactory either.
To achieve a balance, we aim to periodically refactor our code: improve or restructure it without affecting its external function.
More after the break.
→ Read More
Bug-free code is hard to come by, but we strive to do the best we can. The most important part of this is automated testing, and code coverage metrics are a commonly used indicator of the quality of tests. However, code coverage is a misleading metric: Having “Good” code coverge in your tests isn’t really an indicator of good testing, but having “Bad” code coverage definitely means that your tests are insufficient.
In Ruby (and most other common languages), it’s possible to get “C0” code coverage metrics. All this means is that a particular line of code was executed. It seems like this would be the holy grail of testing, but it’s anything but that. Heres a simple psuedo-ruby example of something that would not be adequately checked even with 100% C0 coverage:
def simple_check?
true
end
def my_great_function
simple_check? or (foo? and bar? or (baz? not bat?))
end
test "my_great_function should work" do
assert_equal true, my_great_function
end
The foo/bar/baz/bat logic never gets looked at in the test. While a contrived example, situations like this come up a lot in code and just because one line gets executed, there could be all sorts of bugs.
A more appropriate use of C0 metrics is to identify code that is “definitely” undertested. If you’re tasked with getting some legacy code that is new to you and isn’t very well tested into shape, running C0 metrics will give you the places you should start looking first.
Other types of coverage include:
- C1 – branch coverage – each branch of each line of code. Some languages support this, but it’s a little tricky. “Good” tests should have ~50% or higher C1 coverage. A 100% C1 metric would mean that the example given above would be properly tested. There aren’t any C1 tools for Ruby yet.
- C2 – path coverage – each path through each method is covered. A very hard metric to collect, and one that requires lots and lots of tests. It’s not recommended to try and improve this coverage metric as it will lead to an un-maintainable mess of test code that is at least an order of magnitude larger than your application code.
To get C0 metrics, we used and loved a little Gem called rails_code_qa with our Ruby 1.8 applications. It runs a handful of tools including rcov which provides C0 code coverage information, but due to changes in Ruby rcov no longer works with Ruby 1.9.
Enter cover_me. This gem gives you the same C0 sort of metrics that rcov does, but it works with Ruby 1.9. Setting it up is very straightforward, and the end result is a simple report (that automatically opens in your browser!) that provides C0 information both in aggregate and for each of your files. cover_me works with all the common Ruby test frameworks, and there isn’t a reason to not include it in all of your projects.
If your C0 coverage is around 100%, your code to test ratio is above 1:1 (We try for 1:1.4, you can get this number for Ruby on Rails projects by running `rake stats`), and you’ve been doing Test Driven Development all along, chances are pretty good that your code might well tested.
You are writing automated tests for all your code, right?
Highgroove does, and if you’d like us to take on a project for you, we’ll deliver uncommonly bug-free code.
Related Tags: