Caffeine-Powered Life

Body Acceptance

I have now completed 10 weeks of CrossFit at TitanFit. I am getting stronger. I am working hard. I love it. I never knew there was a strong person inside this body. I am thisclose to being able to do a real, unassisted pull-up. And the people are really encouraging.

I have been logging all my workouts on Fitocracy. Yes, I was doing the Fito thing before Miss America made it so popular. Was that hipster enough? Talk about a lot of body-positive people.

Last night, Meaghan and I went shopping. I need a new belt. I should get a suit. I don’t own a suit. Shouldn’t every man own a suit? I found one that I loved at Banana Republic. A nice, three-piece gray suit. It was quite the handsome affair.

Tailored Slim Fit.

Fuck.

As I look around, all the pants are “Classic Straight”, “Slim Fit”, “Tailored Slim Fit” (wasn’t Slim enough), and “Matchstick”. What the fuck is Matchstick fit? I’m in the men’s section, right? Yes, I am. Oh, they don’t sell clothes I can wear. Isn’t that a thing women say? Do guys say that? And then, this thought hit me, in the way that thoughts are known to hit people.

I cannot wear pants from Banana Republic. AND I AM FINE WITH THAT!

I have spent a long time – ever since I started this weight loss journey – thinking that 175# was this ideal weight for me. According to my height and BMI calculation, 175# is my perfect target. But maybe that’s not me. I kept thinking I should be 175# with 15% body fat.

So why is CrossFit relevant to this story?

I weigh, plus or minus 3 pounds, the same as I did in November: 199#. I am working out 5-6 days per week, with some decent weight training on four of those days. My push-ups suck, but they’re getting better. My cleans suck, but I think that’s because my form is terrible. I can kill box jumps and squats. Ten weeks ago, my one rep max on standing overhead press was 75#. This week, my max is 100#, and I lifted 75# 13 times in a single set. Progress!

I have dropped 2.5” off my waist, but I can’t buy smaller pants because my thighs have gotten bigger. (Thus, the reason I am shopping for a new belt.) And I’m perfectly fine with that. A large shirt has gone from being tight in the belly to just about perfect.

Maybe I’m supposed to be closer to 200#, but with a bodyweight bench press and a 315# squat.

And I don’t need to be some bulked-up monster, either. Just fitter and faster.

I am still not happy with the way I look. My body fat, based on pictures, is still probably close to 20-22%. But it’s much better than the 25-27% it was a few months ago. And I will drop weight – probably my usual 10# – this summer once I’m running and cycling outdoors more frequently. But I’m not going to look. I have quit using my scale. I’m going on three weeks without looking. I will just keep doing stuff and pushing myself hard. The mirror, my clothes, and my performance tell me 1000 times more than that one number on that damned device.

That’s just me, I suppose, and guys are probably just as fucked up as girls when it comes to body acceptance. But I do feel better about myself — a little bit every day.

I Want Conditional Assignment in All the Languages

I get that not every language can have every feature. But there are some language features that just seem obvious to me. Conditional assignment is one of those features.

What Is Conditional Assignment?

Not every language has this feature. The super short answer is that it is an assignment that happens conditionally. Specifically, it prevents assignment from happening twice. In these examples, suppose we want to ensure we have defined an array. I’ll use integers, but it really doesn’t matter what you’re putting in the object.

In C#, you would do conditional assignment one of these two ways.

csharp_example.cs
1
2
3
4
5
// Using the ternary operator
array = (array != null) ? array : new int[] { };

// Using the null coalesce operator
array = (array ?? new int[] { });

In JavaScript, you can use the or || operator to accomplish the same thing. This works in JS because the || operator returns a value, not a boolean.

javascript_example.js
1
array = (array || []);

Examples of Conditional Operators

Having conditional assignment takes care of null checks for you. It’s one of those things that makes a language simple on the eyes, and it cuts down on character noise. Here’s what it would look like in CoffeeScript.

coffeescript_example.coffee
1
2
3
4
5
6
7
8
9
10
11
# Using ternary
array = array ? array : []

# Using unless
array = [] unless array

# Using JavaScript, because JS still works in CS
array = (array || [])

# Using conditional assignment!
array ?= []

In Ruby, conditional assignment looks like this.

ruby_example.rb
1
array ||= []

I don’t see any reason we couldn’t add this feature to C#. We have assignment. We have null checks. Create a new operator for the language!

enhanced_csharp_example.cs
1
array ??= new int[] { }

I want this feature in every language. Language designers, go make that happen!

Getting to Global Variables in CoffeeScript

I’m trying something in CoffeeScript this morning. Right off the bat, I need to be able to access the global window object. CoffeeScript really likes to keep it’s area nice and tidy. It does everything in its power to keep you out of the global namespace. That’s fine, right up until you need to get to the global namespace.

The answer is to add a line like this to your code.

1
root = exports ? this

Instead of accessing the window global, you will use root instead. This only makes sense when you consider that CoffeeScript is designed to be an anywhere-JavaScript framework. With tools like Node, JavaScript isn’t just for the browser any longer.

Solution

Here’s the code you need. You’ll need the line from above. And, you must explicitly add whatever you’re adding to the root object. If you do not do this, your code will be wrapped in a closure and inaccessible from your local code.

1
2
3
4
5
6
7
8
root = exports ? this

class Tester
  sayHello: (target) ->
    alert "Hello, #{target}!"

unless root.tester
  root.tester = new Tester

Here’s the result when compiled into JS. Verbose, isn’t it? Why 6 lines of CoffeeScript becomes 14 lines of JavaScript is beyond me. If I’m writing my own JavaScript classes, I typically won’t use prototyping. Not that there’s anything wrong with that. It’s just not how I would do the same thing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(function() {
  var Tester, root;

  root = typeof exports !== "undefined" && exports !== null ? exports : this;

  Tester = (function() {

    function Tester() {}

    Tester.prototype.sayHello = function(target) {
      return alert("Hello, " + target + "!");
    };

    return Tester;

  })();

  if (!root.tester) {
    root.tester = new Tester;
  }

}).call(this);

Now you can see why using root works. When this is run in your browser, the .call(this) is passing window as the root object. Still, it all works as expect. I open this up in my browser, and all works exactly as expected.

Hope this helps. Thanks to this question and answer from StackOverflow for pointing me in the right direction.

I Will Rise & Heavenly Dance

So, I’m pretty used to putting myself out there. I put photos of myself on Facebook. I obviously have no problem with writing public on just about any topic. I play piano in front of people every week. But I’ve never recorded myself solo.

Until now. Here are two songs that I’ve played for St. Christopher’s choir.

Neither of these songs are, by any stretch of the imagination, perfect. There are missed and omitted notes. There are passages that I have simplified. The tempos aren’t quite perfect. Whatever. This is me, and this is something I love to do.

I am amazed by anyone who will post video of themselves playing any instrument on YouTube. The amount of musical talent in this world is incredible.

So there. It’s out now. I hope to do this more often. Now, back to practice.

Fashion Is a Form of Expression

Fashion is one of the very few forms of expression in which women have more freedom than men.

And I don’t think it’s an accident that it’s typically seen as shallow, trivial, and vain.

It is the height of irony that women are valued for our looks, encouraged to make ourselves beautiful and ornamental… and are then derided as shallow and vain for doing so. And it’s a subtle but definite form of sexism to take one of the few forms of expression where women have more freedom, and treat it as a form of expression that’s inherently superficial and trivial. Like it or not, fashion and style are primarily a women’s art form. And I think it gets treated as trivial because women get treated as trivial.

Greta Christina Fashion Is a Feminist Issue

Via FreethoughtBlogs.com.

I really don’t want to go too deeply into this. First, I am a man that shapes the world I see differently. Second, without my bride, I would probably have no fashion-sense at all. If I look good, Meaghan gets the credit. If I don’t, then it’s my fault.

The article, originally from September 2011, is quite a good read. You should check out the rest of it.

Mocking an HTTP Response in RSpec

One of the great parts about the Ruby language is that all classes and open and active at all times. That means that testing is incredibly easy because you can overwrite any class at any time for the purposes of a test.

Let’s get right down to it. Here’s the production code…

1
2
3
4
5
6
7
8
9
10
11
def widget_content
  if self.content
    self.content
  elsif self.content_source
    uri = Uri.parse(self.content_source)
    response = Net::HTTP.get_response(uri)
    response.body
  else
    ""
  end
end

I keep reflecting on the .NET world, probably because I have so much experience in that environment. The above method, as written, is untestable in .NET because of the static method get_response. Attn Rubyists: .NET “static” is mostly the same as a Ruby class method. You would have to create an adapter interface for the HTTP operation and create a concrete implementation of that interface. You would then inject the adapter interface, either into the method as a parameter or the class itself. Or you would need to use a Service Locator to retrieve the adapter. Although there are plenty of developers who will tell you that Service Location is an anti-pattern.

Anyway, on with the show. Here’s the Ruby test.

1
2
3
4
5
6
7
8
9
10
11
class FakeResponse
  def body
    "<html><body><h1>Hello, World!</h1></body></html>"
  end
end

it "fetches widgets content from content source when content source is given" do
  Net::HTTP.stub(:get_response).and_return(FakeResponse.new)
  widget = DashboardWidget.new({ :content_source => "http://www.example.com" })
  widget.widget_content.should include("<html>")
end

My fake lives inside by test spec. I don’t have any unnecessary adapters or implementations in my production code. This makes production code much more obvious to the reader.