Sunday, March 29, 2015

How to Attend a Programming Conference

"Cannot induce you to attend my words"
-- Shakespeare, Othello
Act III, Scene III, Line 278

Tis that time of the year.  A time when a developer's thoughts turn to conferences.

The following is about how I attend conferences.  The most important thing to know first is that I attend conferences to learn.  If your goal in attending a conference is to party it up in a fun location then this post is not for you.

First, know what type of conference it is that you are attending.

  • Is it single track or multi track?
  • Is it local, regional, or global?
  • Is run for profit or is it sponsored?
  • Is it a single day or multi day?
  • ...

For the most part when you are attending a conference the only real difference is if it is multi track or single track.  The other questions are all around what type of travel plans you will need to make, how much will it cost, and what type of other activities it will have outside of the sessions.  As such I will just focus on the differences around the number of tracks for the rest of the post.

Single track conferences often have a theme which maybe language, technology, or topic based.  This is great if you want to get really in-depth.  You'll find lots of people who are interested in the same theme.  That being said when you go to this type of conference it will most likely be on you to make the most of it by getting out there and talking to other people.  I have two tips for meeting people at a conference like this:

  • Stand/sit at an empty table during breaks.
    Often people will come over and join you (even if just to find a place to rest their snack), this is a great chance to strike up a conversation.  Remember you have at least one thing in common, you have both just seen the exact same session.
  • Join a table during breaks.
    Some times you will strike out doing this and join a table of friends that will not talk to you much, no big deal just head over to a different table.  Remember you have the conference in common, so it should be easy to find things to talk about.
Multi track conferences are a great way to branch out and learn something completely new.  With a multi track conference you can often find sessions in areas that you only have a little bit of knowledge of.  That being said it is up to you to pick the sessions and make the conference your own. I have a few tips for a conference like this:
  • Everyday go to one session in which you have no knowledge of the topic.
    Multi track conferences are a great way to get a glimpse of another world.  If you are a backend developer, go to an UI design session; if you are a front-end developer go to a session on databases.  You have a great opportunity to learn what other people are dealing with and care about.
  • See "famous" speakers.
    Not all speakers have the same speaking style or are at the same level.  Go see a "famous" speaker even if they are talking about a topic you do not care about.  If the speaker is "famous" because they are good, you'll learn something and who knows you might be able to use that new knowledge latter on.
  • See a first-timer / newer speaker.
    Everyone has their first time that they are doing something.  Uncle Bob was not born an accomplish public speaker.  Go see someone that is new to the scene, they might not be as polished as a "famous" speaker but they might have more in-depth knowledge about their topic.
  • Make sure to ask questions at the sessions.
    There is almost always time at the end of the session to ask questions, do so.  Asking questions is a great way to make sure that you understand what you just saw, it is also a good way to get advise from an expert.
A bit of warning around sponsorship and conferences.  Beware at conferences of speakers that work for sponsors of the conference.  Some of these speakers get their spots based on their own merits and may even get their company to sponsor the conference because they believe in it and want to help even more, but there are times that speakers get their spots because they work for a sponsor, this is not to say that they are a bad speaker or that the session will be a sales pitch, just beware and know that you might be getting a sales pitch in your session.

I hope you find these tips useful and if you see me at a conference stop by and say hi.

Sunday, March 22, 2015

Vectors and Maps are Only Different in Your Mind

"That roars so loud and thunders in the index?"
-- Shakespeare, Hamlet

The other day I found something interesting while reading Clojure Programming.

"While it might be counterintuitive, maps and vectors are both associative collections, where vectors associate values with indices."
-- Clojure Programming, page 100

This is yet another case of the book, Clojure Programming, stating something that I thought of but was unable to adequately express in words.
The differences placed around data structures are often either just in our minds or a condition you place on the structure its self.

In the case of the structures just being different in our minds we can look at the example of a map and vector in Clojure.



We see in the example above that we could use a vector as a map where the indices are the keys.  We see in the first example (get v 1) that we are just using the index of 1 to get the second value from the vector (indices are zero based in Clojure).  With the second example (get v 99 :not-found) we see that we can assign a default value to be return when a value is not found.  In the last vector example we see that we can associate new values in the vector resulting in a different vector being returned (do not worry vectors are immutable in Clojure).  In the map examples we see we can treat a map like a vector by using integers for the keys.

In the second case of data structures being different due to a condition imposed on them, we do not have to look an further than our example of a map.

(assoc m
1 "Mr. Jack"
0 2002
2 :good-boy)
;; {0 2002, 1 "Mr. Jack", 3 4, 2 :good-boy}

We see a map is unordered in Clojure.  If you want to have the data be stored in an order then you would want to use a sorted-map instead of a hash-map.

Sunday, March 15, 2015

Examples of Map as a Series of Applying a Function -- in Clojure and kind of in C#.

"It is now apparent?"
-- Shakespeare, Measure for Measure
Act IV, Scene II, Line 135

Every now and then you read something and think, that is exactly what I have been thinking to myself but could not find the words.  Such an experience happen to myself this week.

I was reading Clojure Programming by Chas Emerick, Brian Carper, and Christophe Grand and found exactly how I have been thinking about the higher order function map but have not been able to express in words properly (it is on page 62 in the first edition).

map f [a b c] can be expressed as [(f a) (f b) (f c)]

Likewise map f [a b c] [x y z] can be expressed as [(f a x) (f b y) (f c z)] and so on ...

So what would this look like in code?

Glad you asked.



We see that in Clojure we can get exactly what we are looking for.  As a comparison we fins that in C# using the Zip we can get fairly close.

Sunday, March 1, 2015

Roman Numeral Kata in One Line with C#

"When in one line two crafts directly meet."
-- Shakespeare, Hamlet
Act III, Scene IV, Line 211

The idea of the Roman Numeral kata is that given a number between 1 and we'll say 4999, the number will be converted into the Roman numeral form.

f(1) = "I"
f(2) = "II"
f(3) = "III"
f(4) = "IV"
f(5) = "V"
...
f(4999) = "MMMMCMXCIX"

You can test a value using Google's search by typing the number and "to roman".  Try searching for "299 to roman" to test it out.

At work, we have been using the Roman Numeral kata for interviewing candidates.  The idea is that we get an idea of what it is like to work with the person and they get an idea of what it is like to work with us.  As an added bonus there is a good chance that we will learn something new from each other in the process.

On one such interview recently, we had a candidate do something rather interesting.  Typically a candidate will just start with a series of if statements, some candidates will replace the ifs with an associative data structure (called dictionary in C#), but most will not.  This candidate did a transformation of the input into a string of "I"s and then replace those with the Roman numeral.  They did not ended up finishing or even coming to a general pattern, but I found this idea interesting and ran with it coming up with a C# one liner.



We see in the code above a few different things.

To make this a REPL one liner we create a Func which takes an integer and returns a string, we then start the lambda expression with the bond variable of number.  (In the refactoring done on the candidates code this was all in a single return statement in a method not a Func variable, but when I redid it for this post I did it on the Mono REPL as a Func variable.)

Func<int, string> toRoman = (number) =>

After that we have our associative array, which allows us to look up each of the transformation that we will be doing, this is very useful since to add another transformation we just need to add an entry to the associative array.  (I've done this kind of thing in real world application but I normally will make the look up be a private member of the class.)

new Dictionary<int, string>
{
{1000, "M"},
{ 900, "CM"},
{ 500, "D"},
{ 400, "CD"},
{ 100, "C"},
{ 90, "XC"},
{ 50, "L"},
{ 40, "XL"},
{ 10, "X"},
{ 9, "IX"},
{ 5, "V"},
{ 4, "IV"},
{ 1, "I"}
}
**Note, you do not need the "I" entry in the associative array do the the seed value of the fold, but we'll leave it in there since it is from the more general way of doing this kata.**

We then take this and run it through a fold (called Aggregate in C#).

.Aggregate(

In the seed value to the Aggregate we create a transformation string of the "I"s equal to the value given by the caller.

t(1) = "I"
t(2) = "II"
t(3) = "III"
t(4) = "IIII"
...
t(20) = "IIIIIIIIIIIIIIIIIIII"

To do this we use the string constructor that takes a character and the number of times you wish that character to repeat.

new string('I', number),

We then have the lambda of the Aggregate in which we simply take the current Key and Value from the associative array and call Replace on the transformed string replacing the number of "I"s given in the Value with the Roman numeral given in the Key.

(m, _) => m.Replace(new string('I', _.Key), _.Value));

This is not the "best" implementation of the Roman Numeral kata, but it is a one liner!



"The one I'll slay; the other slayeth me."
-- Shakespeare, A Midsummer Night's Dream

Sunday, February 15, 2015

Customs in Coding Style

"What's in a name? That which we call a rose
By any other word would smell as sweet.
So Romeo would, were he not Romeo called,
Retain that dear perfection which he owes
Without that title. Romeo, doff thy name;
And for thy name, which is no part of thee,
Take all myself.
"
-- Shakespeare, Romeo and Juliet
Act II, Scene II, Lines 43-49.1

Recently for a lunch and learn at work my team re-watched Clean Coders episode 2: Names++.  As with all Uncle Bob videos I highly recommend it.  Being a developer who programs a bit in C# I do have to disagree with his statements about bucking the convention of starting interfacing with an "I", the example he gives is IAccount vs Account.  I agree with most of what he said and having programed in many other language I completely agree that the "I" does not add any additional information but I still use it when I program in C#.  Why?

"Pindar was right, in my judgment, when he said, '[Custom] is the king [over] all.' "
-- Herodotus, The Histories
Translated by George Rawlinson
Book III

Custom is king of all.  I strongly believe that if there is a current naming standard in a language you should just follow it.  When I am doing C# in Visual Studio whatever ctrl+k ctrl+d does is the standard I follow (for the most part).

Why?  Source code is for humans to read and understand, all groups, peoples, languages, ... have customs.  These customs are often built into the communications patterns that are followed and are implied by parties taking part in the communication.

Do not believe me, how would I order a Coca-Cola where you are from?  I grew up in the Chicago area, my whole life people referred to all soft-drinks as pop.  I currently work in Milwaukee guess what they call soft-drinks?  In Milwaukee a soft-drink is called soda.  As a kid I vacationed in the Ozarks, what do you think they would call a soft-drink?  All soft-drinks in the southern part of Ozarks were referred to as coke.  There is a whole website which covers all this pop VS soda VS coke.

What is my point?  When coding in a language if you want other people who program in that language to understand what your code is doing with the minimal amount of effort you should just follow the existing standards of the language you are coding in.

There are lots of other place in software development to have a style and flair, bucking current language naming standards is not the place to do it.

"[I]f one were to offer men to choose out of all the customs in the world such as seemed to them the best, they would examine the whole number, and end by preferring their own; so convinced are they that their own usages far surpass those of all others."
-- Herodotus, The Histories
Translated by George Rawlinson
Book III