Learning F#

I’ve been curious about F# for quite some time, and I recently decided to pick up a few books on it, and see if I could learn it. More generally, I wanted to learn more about functional programming. I thought about learning something like Haskell or Scala, but F# seemed like a good choice. I already know a good bit about the .NET Framework, and the CLR, so I wouldn’t be starting entirely from scratch, and I could stick with tools I already know (Visual Studio).

The three books I picked up are F# for C# Developers, Book of F#, and Programming F# 3.0.I bought them all from as DRM-free e-books from O’Reilly. (This was right before O’Reilly lost the license to sell Microsoft Press books, so the “F# for C#” book would no longer be available from them, if you were looking for it.) I haven’t started the “Programming F#” book yet, so I can’t say anything about it. But I have read a few chapters from each of the other two books.

“F# for C# Developers” is published by Microsoft Press. It’s reasonably well-written, but I haven’t really found it to be particularly engaging or interesting. Of the chapters I’ve read thus far, I’d say that it lives up to its name, in that it is oriented to folks with a good grounding in typical .NET development. I think it would make for a good reference book to keep at my desk, if I was doing some serious F# development at work, and needed to remember the difference between :> and :?>, for instance.

Given that I didn’t feel like I was really learning functional programming from that book, I decided to put it down and start reading “Book of F#”. For my purposes, this is turning out to be a better book. I’ve read the first four chapters so far, and I’m finding that I like the tone of it (including Doctor Who references!), and the general style. I’m finding the example code to be a bit more understandable and interesting than in the other book.

I’ve experimented a bit with re-doing some of the Project Euler problems in F#, as I’ve mentioned before, and I’ve found that to be a good exercise too. Oh, and I’ve solved through to problem 31 there, so I’ve managed to make some overall progress on Project Euler.

Spring Cleaning

I received a letter from my landlord this week notifying me that they would be coming through on Monday and spraying for bugs. The letter said that I should clear off my kitchen counters, and move everything out from the cabinets below the counters, and from under the bathroom sink. I only recall them sending out a notice like this once before, maybe seven or eight years ago. As far as I can tell, we don’t actually have a pest problem, but maybe there’s an issue elsewhere in the building.

Either way, I took this as an opportunity to do some spring cleaning this morning. In addition to throwing out a bunch of random stuff from the kitchen, I also decided to toss out a bunch of old computer books. I threw out maybe 30 or so books. I’ve done this before, and probably blogged about it, so I’m not sure if I’l be saying anything new here. But I wanted to take a break from cleaning and write up a blog post, so here we are.

I haven’t been buying a lot of hard-copy computer books lately, preferring DRM-free e-books instead. At my current job, I have exactly one hard-copy book at my desk. I also have three e-books on my computer that I refer to regularly. At my previous job, I kept maybe a half-dozen hard-copy books on my desk, and a few e-books. At the job before that, I had a whole bookshelf unit, probably six feet tall and three feet wide, full with books (and admittedly a large array of random knick-knacks), most of which I’d bought myself. I left quite a few of them behind when we went out of business, but I took a couple of boxes of them home; most of those went into the recycling dumpster today.

I’ve been buying most of my e-books from O’Reilly. Generally, I wait for them to have a good sale, as they did last week, on the Day Against DRM. Packt had a really good sale too, any book for $10. I ended up buying three books from Packt. They publish such a wide variety of stuff, I found myself with maybe 15 tabs open while I was shopping, looking at all the cool stuff I’d like to learn about. But I know, at this stage in my life, and with the speed that technology changes, that I’m not going to read 15 programming-related books before at least 12 of them are hopelessly out of date. So I settled on buying just three.

I should make a point of checking back in a year, and seeing how many of them I’ve actually read. But, hey, if I don’t read them, I’m only out $10 each and there’s nothing to drag out to the recycling bin!

F# on the Mac

I’ve been messing around with F# lately. It works fine in VS 2013 Express on my Windows 8 laptop, but I wanted to be able to play around with it on my Mac too. I have Xamarin Studio installed on the Mac, and I added the F# support to it, and that works OK. I wanted to be able to use FSI from the terminal too, though. That turns out to be pretty easy too, though it’s called “fsharpi” instead of “fsi” like it is on the PC.

base 36 conversion

I haven’t posted any code on here in a while, so here’s a quick little bit of code that might be useful to somebody. I had to write some code this week to do conversion from base 10 to base 36 and back, in Dynamics AX. So I just took some simple code from the Wikipedia article on base 36 and converted it to X++. Nothing fancy. The code below is all in a job, but I’ll probably put it in a utility class when I actually implement it.

// https://gist.github.com/andyhuey/5c2404b65939b5fccab8
static void AjhBase36Test(Args _args)
{
    // ajh 2014-05-07: 611.23
    // adapted from http://en.wikipedia.org/wiki/Base_36.
    // note: handles non-negative integers only.
    #define.NBASE(36)
    #define.CLIST("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")

    int64 base36_decode(str base36_input)
    {
        int64 result = 0;
        real pow = 0;
        int i, pos;
        str c;

        for (i = strLen(base36_input); i > 0; i--)
        {
            c = subStr(base36_input, i, 1);
            pos = strScan(#CLIST, c, 1, #NBASE) - 1;
            if (pos == -1)
                return pos;  // error
            result += pos * power(#NBASE, pow);
            pow++;
        }
        return result;
    }
    str base36_encode(int64 input_num)
    {
        int64 work_num = input_num;
        str result = "";
        int digitidx;
        str c;

        do {
            digitidx = int642int(work_num mod #NBASE);
            c = subStr(#CLIST, digitidx + 1, 1);
            result += c;
            work_num = work_num div #NBASE;
        } while (work_num > 0);
        return strReverse(result);
    }

    print base36_decode("");
    print base36_decode("0");
    print base36_decode("A"); // 10
    print base36_decode("7PS"); // 10,000
    print base36_decode("255S"); // 100,000
    print base36_decode("!@#$"); // error
    print base36_encode(0);
    print base36_encode(123);
    print base36_encode(10000);
    print base36_encode(100000);
    pause;
}

Streaming Music Services

In general, I’ve never been the kind of guy who likes to listen to music at work. And in most of my previous jobs, I really wouldn’t have been able to listen to music, since there were a lot of interruptions and interactions that would have prevented me from getting too far into anything before I’d have to take my headphones off to answer a call, or run over to a user’s desk, or whatever. But, in my current job, I’m doing a fair amount of “heads down” programming, with few interruptions. And I’m actually finding that some of the office noise distracts me enough that drowning it out with music allows me to be more productive.

For a while, I tried just listening to Coffeetivity. This was kind of helpful, but also kind of boring. I may give it another try at some point. I also tried focus@will. The idea here is kind of cool, but I’m not convinced it would make me more productive than listening to music of my own choosing. Again, I may give it another try at some point, maybe the next time they run a 50% off sale on a year’s subscription to their “premium” service. And, as I’ve mentioned previously on this blog, I was really in love with turntable.fm. Unfortunately, they shut down a while ago.

After messing around with all this stuff, I settled into a habit of listening to Pandora a lot. I set up some “stations” based on my favorite artists, and that worked out pretty well. About a year ago, I paid $36 to subscribe to Pandora One for a year, so I could get rid of the ads. That didn’t seem like a bad price, even though it really doesn’t buy you anything other than ad-free listening.

This past weekend, I got a notice that it was time to renew. (Normally, that would have happened automatically, but my credit card got stolen a while back and I had to replace it, so they couldn’t put through the charge on my old card.) I really wanted to just renew it for another whole year, but Pandora discontinued the annual plan a while back. So the $36/year (effectively $3/month) plan would become a $4/month plan with no annual billing option. I wasn’t sure if I wanted to go forward with that, so I basically just let the subscription lapse. Then, on Monday, when I looked again, I realized that I was no longer eligible for the $4/month “loyalty price,” and would have to go on the new $5/month plan. So I decided that was a but much, and I’d look around at other options.

For now, I’ve settled on Slacker. The ad-free version is $4/month, and it gets you a few things that you don’t get with Pandora. The one feature I really like, and I wish Pandora allowed, is the option to download stuff for offline listening. I can’t use my employer’s wifi to stream music to my phone at work, so I have to rely on my Verizon data connection. This generally works OK, but I can wind up getting pretty close to my data cap sometimes, and I think it drains the battery a lot more than listening from a local cache. So just being able to download a cache of stuff over my home wifi, before leaving for work, is useful.

I’m also finding that Slacker’s “curated” stations are interesting. I listened to “The Current” station today, and it was really good. I’m not sure how often the content on that station is refreshed, but I could see myself listening to that one quite a lot. So, overall, I’m finding Slacker to be just as good as Pandora, but with a few more bells and whistles. Over time, I’ll see how well it holds up — whether or not there are any glitches with the app, how often content is refreshed, and stuff like that. But I’m feeling pretty good about it.

a little more on digital comics

As a follow-up to my post earlier today, I spent some time today looking through my e-mail receipts for Comixology and Dark Horse Digital purchases, and made lists in Evernote for stuff I’ve read and stuff I haven’t read yet. First, let me say that I was surprised to see how much stuff I’ve bought, in both apps, but haven’t actually read yet. But now that I have decent lists to start from, I should be able to keep track of it all, going forward.

Thoughts on digital comics

OK, this is going to be my obligatory post on Amazon’s purchase of Comixology, and possibly some related topics, depending on whether or not I run out of steam before I get to all the stuff that’s in my head right now. 🙂

First, let me say that I have hundreds of books in my Comixology library. I can’t tell you how many, because Comixology’s web interface for browsing your library really doesn’t tell you much. (OK, picking up my iPad and looking at the app, I can see that it’s apparently 635. But there’s no way to see that on the web, as far as I can tell.) This is the main beef I have with Comixology, both with their web interface and their apps. Since their books are DRM’d, I can only store them and read them in the Comixology apps (and site), and they really haven’t put much work into making any of their interfaces really useful for people with more than a handful of books. Even something as simple as keeping track of read vs unread status across devices would be nice. They have said that they’re “working on it” and “we need to do this“, but they really haven’t done it. The iPad app will mark as “new” stuff that you’ve just downloaded and haven’t read yet. But that’s only tracked in the app itself. The “cloud” view doesn’t track when or if you’ve read something. And since they just replaced their apps with new versions, all that info from the old app is effectively gone now.

I’ve recently started using Goodreads to keep track of my reading for dead-tree and Kindle books, and I’m thinking that maybe I should use it for Comixology too. Though single-issue comics don’t fit well into Goodread’s model, really. Maybe I should just track them in Evernote? The thing that really clutters up Comixology is all the free comics. Not that I’m complaining about all the free comics I’ve downloaded from Comixology, but it can make it hard to find the stuff I’ve actually paid for. Even just having a simple user-contolled tagging system or folder system would solve this problem. How hard would that be to implement? 

Moving on to the subject of Amazon’s purchase of Comixology, this could be good or bad. Removing the in-app purchasing option wasn’t a big surprise. You can’t do in-app purchase in the Kindle iPad app either. I want to say that Amazon’s purchase might let them spend more money on both the web and app interfaces, and maybe implement some of the stuff I’d like to see there, but then I remember what the interface looks like in the Kindle app, and on the Kindle itself, and I laugh at the idea that Amazon might implement nested folders or useful tagging in the Comixology app. (Not that I’m bitter or anything..)

Meanwhile, I just recently bought Comic Zeal for my iPad, so I can have a nice interface for managing and reading my DRM-free comics. Previously, I’d used Goodreader to read some comics I had in PDF format. Goodreader is a pretty great piece of software, and it works OK for comics, but it’s not perfect for them. So I looked around at comics readers, and Comic Zeal seemed to have the best reviews. I’ve loaded a bunch of stuff into it, including comics I’ve bought from Matt Howarth and some stuff from Drive-Thru Comics. I really like the ability to organize stuff. It’s quite easy to put stuff in folders by series, to tag books, and to reorder the list of books. The software does keep track of your reading progress in individual books, but I haven’t found any option to, for instance, show only unread books. But really, since I’m only using it for DRM-free books, I can just delete stuff that I’ve already read, and just keep that stuff on my PC. In terms of the actual reading experience, I’ve found it to be a bit slow on page-turning for some PDF comics. I really haven’t used it enough to have formed much of an overall opinion yet though.

I’m thinking about picking up the Image Comics bundle that Humble has on sale right now, so that would give me a bunch of new stuff to load into Comic Zeal and enjoy. If I do that, and actually get around to reading some of it, then I’ll probably post a follow-up with more thoughts on how well Comic Zeal works in practice.