My Clojure Journey: Simple Expressive Tests

One thing my team has struggled with in enterprise C# development is the complexity of unit test setup. This is complicated by Domain Driven Design, which encourages the use of concrete classes for entities and values. Test setup often becomes nontrivial as you are often required to set up considerably more of the object graph than what’s really necessary for the test at hand, simply because of the constructor signature on, say, a value object that you want to test.

This is much less of a problem in a dynamic language like Clojure, where there are no hard and fast rules about constructing objects – you can just create a map with only the properties you need for the test. For example, here’s a test in my Hearts project that invokes a function named next-player-pos and passes it a game of Hearts, which here is simply represented as an empty map {}:

(deftest next-player-at-start-is-first-player
  (with-redefs [first-player (constantly {:pos 2})]
    (is (= 2 (next-player-pos {})))))

Continue reading

Using AngularJS: Interview with Dan Wahlin, Joe Eames and Jim Cooper

The AngularJS JavaScript framework continues to increase in popularity among developers and is being used in a wide variety of scenarios. While at the Pluralsight Author Summit in March, Dan Wahlin sat down with Joe Eames and Jim Cooper to talk about how they’ve used AngularJS, their favorite features and how it was used to build Pluralsight’s HTML5 video player. In the interview they discuss their favorite AngularJS features, benefits it offers developers as well as a few other related subjects. If you’re interested in hearing more about what AngularJS is and what it can do, check out the interview for a quick introduction.

For more information about AngularJS visit http://angularjs.org.

Antipatterns: What’s Wrong With This Code? — Answered!

The code excerpt below is a C# ASP.NET Web API controller that compiles and seems to run just fine.  Can you spot the problems in this code?  Hit the comment link and let us know what you think is wrong.  We’ll have the answer on Monday.

code

 

Answers:

  1. Use of a static field is not threadsafe.  ASP.NET Web APIs are inherently multi-threaded so using a static field is not a good idea.  There are several ways to fix this from using a SynchronizedDictionary to manually handling the locking via locks or semaphores.
  2. No Initialization of the data Dictionary.  This could cause various exceptions.
  3. Lack of defensive coding.  In several places there are assumptions being made about the content of the data dictionary that will cause exceptions at runtime.

We got lots of great answers, thanks everybody for their comments.  There were many answers given that may be technically correct but weren’t  necessarily the bugs we were hunting in this example.  Stay tuned for our next code puzzle, and rest assured we’ll work on making it more challenging.

Looking For A Career In Tech? Whats Best For You?

careersearchToday, there are alot of options when it comes to choosing a career.  With the boom in developer trends over the last 20 years, having a job as a ‘computer nerd’ is actually pretty cool and less nerdy.    There are many different titles and options out there, so don’t limit yourself!

How do you know whats best for you?   Well, lets break it down for you on today’s most popular positions are within a tech company.

Product Manager

If you are a problem solver, can define what a product should be, like making decisions while working with a team, then this title may be a good career choice for you.

The product manager defines what an application/product is and how it will be used.  The job is to imagine what it like to be the user and ensure that you are satisfied as the product user and make sure your product meets the needs of the end-user.

Continue reading

Google Reader is Closing; What are the Alternatives?

200px-Google_Reader_logoAs part of this year’s round of spring cleaning, Google has announced they will sunset Google Reader on July 1st, along with seven other services. While user adoption has declined over the past few years – in part due to social media services like Twitter and Facebook encroaching on Google’s turf – Google Reader still has a loyal following among internet power-users and productivity junkies, and many native RSS applications rely on Google Reader for sync and subscription management. So now what?

The Alternatives

Anyone who works in a fast-changing industry understands the importance of diversifying their skills, and continuing their education. One of the best ways to do this is by reading as much as possible, and having a method for keeping all of that reading material organized is imperative. While none of these alternatives quite meet the simple, yet powerful user interface Google Reader provided, they will, at the very least, provide an interim solution until other entities can try their hand at building a comparable service.

Continue reading

My Clojure journey: pure functions

PureIn my last blog post in this series, I pointed to 4clojure as a great tool to help you practice writing functions in Clojure. By its very nature, 4clojure only allows you to write pure functions. In this post, I’ll talk about the beauty that I see in pure functions, but also point out that you’ll typically need a little more than pure functions to build an app in Clojure.

It’s not so much what a pure function does that defines it. It’s more what it doesn’t do. A pure function doesn’t rely on any state beyond what’s passed to it via its argument list, and the only output from a pure function is its return value.

Continue reading

My Clojure journey: Hearts, koans, and 4clojure

HeartsI blogged recently that my boys and I have started learning Clojure. It’s been an incredibly fun journey so far, sans the challenges of cobbling together a Clojure dev environment (which I’ll talk about another day). I’ve come a long way, and I wanted to share my journey so far, which starts with a card game called Hearts.

My kids and I enjoy playing cards together, so I figured a great first project in Clojure would be one of our favorites, Hearts. Modeling a game of cards requires a bit of data modeling (a shuffled deck of cards, dealt hands and tricks as the game gets underway) along with some logic (computing who is the first to play any given trick, the winner of a trick, scoring, etc.) It felt like a great way to get started.

Continue reading

Clean up your gmail inbox

If you’re anything like me, you get so much email that you just can’t read it all. Eventually you end up with an inbox that has thousands (for me tens of thousands) of unread emails.

I used to spend a few minutes every week cleaning up my inbox by selecting “Unread” email, unchecking items to keep, and clicking the trash icon to delete the rest. After about three pages of this, it gets tremendously tedious, and I eventually gave up, which led to my fat inbox.

Continue reading

Video: Pluralsight uses Selenium – you should too!

While most of our acceptance tests are driven via FitNesse and test just below the presentation layer, we do have some Selenium smoke tests that exercise parts of our website. We used to do a lot of this manually, but it sure is nice to simply press a button and let Selenium do the work for us at 100MPH. We try to keep these test suites pretty small because UI tests can be costly to maintain, but it’s sure a great feeling to have them available!

Learn more about how you can do this on your own website! Check out John Sonmez‘s Automated Web Testing with Selenium course.

Understanding TraceRoute

TraceRoute (traceroute on Unix machines, tracert.exe on Windows, or the popular alternative, mtr – Matt’s traceroute) is a tool that allows you to examine the routes your packets take as they travel the Internet to any given host.

For example, here’s a trace I ran this morning from Riverside, CA to google.com:

Keiths-MacBook-Air:~ keith$ traceroute google.com
traceroute: Warning: google.com has multiple addresses; using 74.125.224.167
traceroute to google.com (74.125.224.167), 64 hops max, 52 byte packets

1 10.32.43.1 (10.32.43.1) 9.282 ms 9.379 ms 9.501 ms
2 dtr03rvsdca-tge-0-1-0-6.rvsd.ca.charter.com (96.34.98.16) 8.192 ms 10.394 ms 11.340 ms
3 crr01rvsdca-tge-0-4-0-3.rvsd.ca.charter.com (96.34.98.122) 20.498 ms
crr01rvsdca-tge-0-4-0-2.rvsd.ca.charter.com (96.34.98.120) 11.721 ms
crr01rvsdca-tge-0-4-0-1.rvsd.ca.charter.com (96.34.96.232) 11.049 ms
4 bbr01rvsdca-tge-0-1-0-12.rvsd.ca.charter.com (96.34.1.28) 9.681 ms 27.752 ms 19.221 ms
5 prr01lsanca-tge-0-1-0-6.lsan.ca.charter.com (96.34.3.218) 13.015 ms 13.323 ms 12.220 ms
6 72.14.212.81 (72.14.212.81) 13.625 ms
74.125.51.245 (74.125.51.245) 13.225 ms
72.14.212.83 (72.14.212.83) 15.083 ms
7 209.85.248.185 (209.85.248.185) 14.796 ms 13.597 ms 117.337 ms
8 72.14.236.11 (72.14.236.11) 29.216 ms 16.525 ms 14.231 ms
9 lax02s01-in-f7.1e100.net (74.125.224.167) 13.640 ms 11.569 ms 14.528 ms

If you’ve ever used traceroute in any form, you’ll find this Traceroute article by Richard Steenbergen invaluable in helping you make better use of the tool. Our friends over at CacheFly found this and posted it on their blog, and the article was just too good not to share.

Enter Richard Steenbergen. One of the truly gifted people out there when it comes to running a network, Richard is the CTO and founder of nLayer. A few years ago Richard made a fantastic presentation at NANOG regarding how to *really* read a traceroute, and bunch of other smart people walked a way with a much better understanding of how traceroute actually works. Richard has since converted his presentation into an article which is very easy to digest and yet provides all the info from his original presentation.

Enjoy!