July 9, 2014
chrislewis/MapIsFold.scala

In scala, map is fold (don’t do this).

9:50am  |   permalink
FILED UNDER: Scala 
April 17, 2014
"The more terrible the programming language people use, and the more they know it is terrible (even if they will not admit it), the more scandalized they will be that you point out that it is, indeed, terrible. It is as if you had said something about their weight or the pimples on their cheeks."

Bertrand Meyer

8:59am  |   permalink
April 15, 2014
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius—and a lot of courage—to move in the opposite direction."

— Albert Einstein

January 1, 2013

This Year Begins With an End.

Rather my knowledge of an end. It is due to my negligence of personal relationships that I learned today, January 1st, 2013, that a dear friend of mine passed away in November of 2012. This is news I will be processing for a while, but I am compelled to write a few meager words in an attempt to illuminate the profound effect that the life of Steve Anderson had on my own.

I was sixteen years old when I met Steve, a frail man in his early fifties at the time. School was out for the summer and I was looking for a job on the Outer Banks. Steve ran the kitchen at a seasonal seafood buffet then, and he was looking for dishwashers. My employment requirement was a paycheck at anything above minimum wage, and so I became a dishwasher at the Soundside Buffet.

Upon first meeting Steve, one might not be given the impression that he was a kind man; he seemed curt, frustrated, and at times vulgar. I found him to be slightly frightening and downright hilarious. As the summer passed I was moved from washing dishes to doing basic prep work in the kitchen, a time during which I believe he began to enjoy my company. I had always enjoyed his company as I found him to be both personable and entertaining, but the reality was that underneath his rough veneer lay a loving husband, father, and an extremely compassionate human being.

When the summer ended I stayed in touch with Steve, coming back on a weekend here and there during the school year to help in the kitchen. After a while Steve left the restaurant and for about a year we were not in contact.

It was at least a year before a friend of mine told me that he had seen Steve working at a new restaurant, and I was again looking for a summer job. I remember walking into the kitchen of the Bacu Grill and seeing him there, in what I perceived as his true element, and the happiness I felt. When he looked up and saw me I knew he was relieved; not only because he trusted me as a worker, but because he was happy for the time we would again have.

That was the summer I truly learned how to work a kitchen. Yes, I did dishes when they needed doing, but I worked as a classic apprentice beside Steve, a seasoned tradesman, and another senior chef and alumnus of the Culinary Institute of America. I learned about preparation of simple dishes, layout, capacity planning and inventory, ovens and gas lines, health codes, how to properly clean soft shell crabs, how to perfectly clean a tenderloin, and loads of knowledge on dishes and methods that I have kept with me. It was this experience that taught me a great deal of self-reliance, confidence and responsibility, and it seeded in me a passion for true craft and skill.

After the summer we stayed in touch. I worked frequently in the off-season and spent a great deal of time with him and his family at their home. He and his wife DiAnn treated me like a son and their daughters, Kelli and Kim, treated me like a brother. I spent many a night there, cooking dinner, helping with whatever odd-job or chore Steve wanted, and we spent hours chatting or simply enjoying the fading summer evenings.

I have many other memories of our time together, and in the coming days I will meditate on them intently. I lost touch with the Anderson family for a few years, for no other reason than that I was a negligent fool. For this I learned only today that he passed more than a month ago, after he and I had not spoken in at least four years. I will carry this weight for a time, but I digress.

It is not my intent here to focus on this mistake, nor on the details of Steve’s passing, nor even that he has passed. Rather I wish to say simply that I am the person I am, in no small part, because of Steve Anderson. I am honored to have known him, more complete because of him, and grieved to have lost him.

I say to you reader, be you friend, family or stranger: consider those in your life who have played a part in making you a better, fuller person. Honor them in what you do and how you do it, and thank them. In person. Right now.

11:56pm  |   permalink
August 4, 2012
"There can be no comparison between the difficulty of improving the performance of a slow system designed for simplicity and that of removing complexity from a complex system which was designed to be fast."

— Ben Moseley / Peter Marks (Out of the Tar Pit)

11:55am  |   permalink
November 1, 2011

Idea: Validation + Adapters for Terminal Programs and Web Services

Derive a common utility or library for options and constraints from something like scopt and Unfiltered's parameter validation library. With a common way to specify input arguments, functions to produce boiler plate for command like programs and web endpoints would be easy to write. This would be a great use for scalaz / validation.

1:18pm  |   permalink
  
FILED UNDER: projects todo 
August 27, 2011

Too much curry!

What does a compiled curried method in Scala look like in java? Compile this:

object Concat {
  def concat(s: String)(ss: String) = s + ss
  def concat(s: String)(i: Int) = i + s
}
Now inspect the resulting class with javap:
Compiled from "Concat.scala"
public final class Concat extends java.lang.Object{
    public static final java.lang.String concat(java.lang.String, java.lang.String);
}
After compilation curried methods look like normal, multi-parameter methods. It doesn’t matter how many parameter lists you define, nor how many parameters each list takes; in the end you get a plain old method. Knowing this we should expect overloading to work fine, so let’s overload our curried method:
object Concat {
  def concat(s: String)(ss: String) = s + ss
  def concat(s: String)(i: Int) = i + s
}
As expected, this compiles, and javap gives expected output:
public final class Concat extends java.lang.Object{
    public static final java.lang.String concat(java.lang.String, int);
    public static final java.lang.String concat(java.lang.String, java.lang.String);
}
Great, let’s use it!
object Concat {
  def concat(s: String)(ss: String) = s + ss
  def concat(s: String)(i: Int) = i + s
}

object Concatter {
  def greet(who: String, msg: String) = Concat.concat(who)(msg)
}
And compile:
Concat.scala:7: error: ambiguous reference to overloaded definition,
both method concat in object Concat of type (s: String)(i: Int)String
and  method concat in object Concat of type (s: String)(ss: String)java.lang.String
match argument types (String)
  def greet(who: String, msg: String) = Concat.concat(who)(msg)
                                               ^
one error found
Well, that was unexpected! The compiler let us overload a curried method, but it won’t let us use either of them. The error tells us that the compiler is unable to disambiguate the method. This seems strange as we’re explicitly passing values for all arguments. Try as we may, there simply is no way to use these methods as defined. As it turns out, this is a problem of scope. Let’s try different access modifiers:
object Concat {
  def concat(s: String)(ss: String) = s + ss
  protected def concat(s: String)(i: Int) = i + s
}

object Concatter {
  def greet(who: String, msg: String) = Concat.concat(who)(msg)
}
This compiles because Concat.concat(s: String)(i: Int) is not in scope at the call site (it’s not accessible). However, within Concat both are in scope:
object Concat {
  def concat(s: String)(ss: String) = s + ss
  protected def concat(s: String)(i: Int) = i + s
  def con = concat("")("")
}
Concat.scala:4: error: ambiguous reference to overloaded definition,
both method concat in object Concat of type (s: String)(i: Int)String
and  method concat in object Concat of type (s: String)(ss: String)java.lang.String
match argument types (java.lang.String)
  def con = concat("")("")
            ^
one error found
If you’re overloading curried methods, remember that you must demarcate their potential scopes with access modifiers. Two overloaded curried methods with the same access levels will never be callable; they will compile unless you try to use them. Perhaps a more fundamental lesson to learn from this is to eschew method overloading in general, always.

7:38pm  |   permalink
  
FILED UNDER: scala 
July 22, 2011
"There’s always a “best” tool for any job, but if programmers don’t know how to use it, they’ll choose an inferior tool because they think their schedule doesn’t permit a learning curve. In the long run they’re hurting their schedules, but it’s hard to see that when you’re down in the trenches."

Steve Yegge

12:13pm  |   permalink
July 12, 2011

Moving to New York City

For several years now I’ve felt that, at some point, I’d like to move to New York City. I visited the city for the first time in 2009, and I was just taken. Its history, strength, character, diversity, and cultural wealth captivated me.

Still, there was something else. I had just recently discovered the Scala programming language. I’m a polyglot programmer but I’ve spent a lot of time on the jvm. When I was exposed to Scala, my first reaction was merely: “Wow, this is cool!” And then the paradigm shift began as I inadvertently embarked on a mind-altering journey into the world of functional programming. It’s been frustrating, illuminating, continuous, and it just keeps going.

But I digress. One of the reasons that I’m moving to New York is that there are many bright, passionate people that make up a vibrant community of programmers; functional and aspiring-to-be alike. It is a place where exploring concepts with others is easier; a place where cross-pollination of ideas and paradigms common. What’s more, there are companies building great products that are harnessing this energy (like the one I’m joining). I’ll be making the switch from full-time Java to full-time Scala, and while I’m new to the company’s industry, I’m no newbie to Scala. I’m full of an excitement laced with a bit of healthy fear, and I can’t wait to start.

7:54pm  |   permalink
  
FILED UNDER: nyc scala functional 
June 28, 2011
"If anything were actually “immeasurable,” it would bear no relationship of any kind to the rest of the universe, it would not affect nor be affected by anything else in any manner whatever, it would enact no causes and bear no consequences - in short, it would not exist."

— Ayn Rand

11:11am  |   permalink