Moving data around your code - different approaches
I was thinking about this the other day, and I realized I can't particularly think of a label to attach to this concept. Anyone out there got a name for this? This could be due to my lack of formal computer science training, so I thought I'd ask, at the risk of looking stupid (I'm having an off day, so that's a very real possibility).
If you have a series of functions, say: a(x), which in turn calls b(x), which calls c(x), and so on, and you end up with a faily long call chain, out to say m(x), and you subsequently decide that m(x) needs an additional piece of information that is contained in a local variable in the body of the a(x) function - how do you get it to m(x) ?
- You could simply make it a global variable! That's easy and generally a pretty bad idea.
- You could modify every function signature between a(x) and m(x) to look like b(x, y), c(x, y). That's a lot of work though. And what happens if something *else* needs to get passed around?
- In an object oriented language, you could make x an object, and attach y to it, so that you mostly pass it around just as before.
- Along the same lines, you could make x a hash table, so that you can look arguments up by their name, to have some idea what they are.
- You could just make x a list, and remember what position everything is in. That's not so nice though if you have to revisit the code and you didn't document where everything is, and why it's there.
- Other things? You could make a(x)'s scope visible to m(x), I suppose, although that sounds like it's a fairly involved, and potentially hairy answer.
It seems the answers are basically either 1) add the parameter to all the functions and everything that calls them, or 2) use some kind of composite type to stash the one or more values in.
It seems that this is a reasonable common thing to have to do, so it must have a name. How well does your language handle that kind of refactoring?
Geek Dad: "Skywalker Story"
I don't usually talk about personal stuff here, but I'll make an exception:
I got tired of telling our two year old daughter the same old stories about children lost in forests, bears, witches, evil stepmothers and so on, so I turned to some other material I know fairly well. I started recounting simplified bits and pieces of the first Star Wars movie over the course of a week. She thought it was great fun, what with wookies and robots and a princess and lots of adventures, and now, every evening, asks for "Skywalker story!". I'm quite proud, although my wife rolls her eyes a bit.
Rails I18n translate with empty string - bug?
Normally, it's pretty easy in Rails to take advantage of the simple i18n tools provided. You just write I18n.t("some_key") and it'll translate that into whichever language.
Today, however, I discovered what seems like a problem. If you do I18n.t(""), it returns a hash of all possible translations! And if you give it a nil, it returns an error because that's not a key in the DB.
The first behavior doesn't sound correct at all, and the second seems dubious as well. I'm thinking about fixing it like so:
def translate(key, options = {})
return nil if key.nil?
return "" if key == ""
locale = options.delete(:locale) || I18n.locale
backend.translate(locale, key, options)
rescue I18n::ArgumentError => e
raise e if options[:raise]
send(@@exception_handler, e, locale, key, options)
end
Is there any reason not to do this?
On the block: squeezedbooks.com
In keeping with the idea that I want to focus on things where I sell something directly to people, rather than just advertising, I am putting http://www.squeezedbooks.com up for auction on flippa.com. The auction is here:
http://flippa.com/auctions/99073/Business-Book-Summary-Site
Here's what I wrote about it:
I like to read business books, but many of them contain a nugget of valuable information, and lots of fluff, because you can't sell a 10 page book. Some of them are pure fluff! Occasionally, one of them has profound implications.
I created this site several years ago in order to have a place to summarize a series of books I'd read, with the aim of creating a community interested in summarizing and, most of all, discussing business books. To be honest, that community hasn't really materialized, although there are a number of registered users (585 at last count). Most other business book summary sites are for-pay - you pay $X dollars a month and receive Y summaries. I wanted to create an open site, in order to foster discussion and communication between people reading summaries.
In any case, one baby later and in a different country, my heart isn't really in it any more, so I've decided to put the site up for sale. I still think the idea is a good one, and that in the right hands, the site could take off.
It was a fun site to work on, and really do think that in the right hands, it, or something derived from it, could be successful. I could conceivably hang on to it and keep trying different things with it, but I've decided I really need to impose this limitation of "make something to sell directly" on myself in order to avoid wandering off into "cool, but no idea how to make money" projects.
Edit:
One thing that I'd like to state explicitly and publicly is that I'm not giving up on open source, just that I think I need to draw a really clear line between "I hope to make some money with this" and "this is a cool project I want to share with the world". In other words, I think I'd rather avoid the middle ground where stuff is sort of openish, and go either for projects that pay directly, or stuff that's pure open source under an Apache or BSD license. Hopefully, if I ever hit on a project that takes off, I'll be able to dedicate some time/resources to open sourcing some of the infrastructure, as I think that's currently one of the better models for producing open source software.
Ovi Lays an Egg
In the local dialect here in Padova, Italy, "ovi" means "eggs". For those who aren't native English speakers, "to lay an egg" means to fail at something or do it poorly. The connection is very appropriate.
To see what it was about, and if it was worth pursuing, I decided to submit a couple of simple applications to Nokia's OVI store. Nothing fancy, or that I'd spent much time developing, and they were actually little things I'd done for myself before the ovi.com store came out, but I had hoped to see about making a bit of money out of the time invested nonetheless.
So I went ahead and started adding them, with a quick glance the publisher guidelines. Too quick, as it turns out. A month after submitting my application, their "QA" process lets me know my application is not going to be accepted because it's not signed. Uh... yeah? Couldn't you have simply run a script on the file I uploaded to tell me the same damn thing? It's not exactly as if you have to have a human look at the file with a hex editor to determine whether it's signed or not. My phone can tell, of course - presumably Nokia ought to be able to figure it out programmatically and let me know? Sure, I should have read their big, long document prior to starting, but come on, it would have saved everyone time if their software had simply informed me that my application, being unsigned, was not ok.
Now, when it comes to signing, Java ME is pretty much the worst in the business, although Apple is giving them a run for their money. At least Apple does it to make the applications good for their users (for their definition of good).
- Java ME: Ovi suggests using http://javaverified.com/ - where it costs $200 to sign up, and then something like at least 75 euros to run an application through *their* whole process. For each version. The hell with that!
- Android: you have to pay $25 to get access to the marketplace, but can self-sign applications. For free. Put that in your pipe and smoke it, Nokia & Larry.
- BlackBerry: I was sure this one was going to be expensive and painful given that BB is mostly aimed at big companies that could certainly spare the money. It's not: $20 gets you a certificate that you can sign everything you want with, and it's pretty quick and painless to get it. This is how Nokia ought to be doing things in terms of signing applications.
- Apple: $100 gets you the dev kit and then you can submit your apps to the somewhat bureaucratic and slow apple approval process. Plus you have to own a mac to develop on, if you don't already have one. But still, only $100 a year, and you can do as many apps as you want.
So there you have it, Java ME involves more fees than the other ones, and is probably as slow and bureaucratic to boot. I'm not going to find out, though, this pretty much concludes my experiment with ovi.com - there's no way I'm going to spend all that money on a little fun application that I'd only sell for a few euros. Being a fan of open source and openness in general, my next phone will certainly be Android based.
I think someone at Nokia probably realizes things are broken: they appear to be working on a way to make it not cost anything to sign Symbian apps. But I don't have a Symbian app, so that's pretty useless for me.
Oh, and while I'm bitching about their whole process, their publisher interface was down all of last weekend in order to "add a new set of metadata which will improve the Ovi Store user experience". It took a whole weekend of downtime to add that?
Furthermore, I signed up for Ovi as soon as it came out - I was going to push Hecl to it (but didn't bother at the time) but now it appears they want 50 euros from you just to sign up. Here's a hint: save your money.
Ok, first one on the block: leenooks.com
The problem with selling off these sites is that I am a bit attached to them emotionally. Leenooks.com is a cool domain, I think - it's how Linus pronounces Linux, supposedly. It's also one of the first sites I put together: the original version was done in Perl with CGI back in ... '97? The current incarnation runs on DedaWiki a wiki I put together that is built with Ruby on Rails.
The idea behind the site was that, rather than keep track of all the hardware out there that works well with Linux, let's focus on the stuff you really want to avoid as that is a smaller set of things, and hopefully one that, one day, will be empty!
It seems to have been fairly popular over the years, and has helped pay for the server it runs on. However, "popular" doesn't necessarily translate into "oodles of money", and especially now that I have a daughter who is a lot of fun to play with, I need to cut back on my "spare time" projects. So this one is the first one up on the auction block.
I fervently hope that whoever acquires it can dedicate a bit more time and energy to making it do what it does, only better.
A Minor Erlang Rant
In an earlier post, I compared node.js to Erlang: http://journal.dedasys.com/2010/04/29/erlang-vs-node-js - which admittedly has a whiff of apples and oranges about it. Still, though, I think there's something to it. Node.js is creating lots of buzz for itself these days. Some of that will turn into actual production use, and at that point actual companies will have a vested interest in seeing the system improved. Currently, it is not as 'good' as Erlang. Erlang's VM has a built in scheduler, so you simply don't have to worry about manually creating bite-sized chunks of processing that feed into one another, it all "just works". For instance, my current Erlang project involves reading from twitter's stream, and distributing that to IRC and the web. It's pretty simple, works well, and is quite robust.
I haven't had the best of days though, and one little annoyance of the many I dealt with today really caught my eye. I need to do an HTTP POST in Erlang, and:
- The documentation does not have examples.
-
Here's an example of how to do a POST:
http:request( post, { "http://scream-it.com/win/tests/posttest.cfm", [], "application/x-www-form-urlencoded", "x=2&y=3&msg=Hello%20World" }, [], [] ). -
Aside from being ugly and not very leggible, you'll note that he's passing the parameters as a string, and also has to manually include the "x-www-form-urlencoded" header.
-
To create that string, you'd want to url encode it. Actually, ideally, you'd just pass in a list of key/value pairs and let the library module handle it.
-
However, there's nothing in the http module that does that.
-
If you look through various bits of Erlang code on the web, you'll note many, many versions of url encoding and decoding, because the http module makes no mention of how one might go about doing so.
-
It turns out, that the edoc_lib module does have a uri encode function!
-
That isn't documented in its own man page.
-
And certainly isn't linked to in the http page.
So, in 2010, doing an HTTP POST in Erlang is still a pain in the neck. I'd be happy to put my money where my mouth is and submit a patch (at least one for the documentation), but you have to wonder why no one has fixed the problem so far - maybe they're not very accepting of patches?
Some difficult decisions?
I am, by nature, a tinkerer. I love to build things to see how they will work or because I have an idea that I think is fun. I am not so much of a natural business guy. I go build something "because it's there". Or rather, it's there in my mind, and I want to make it.
I earn money, however, via consulting work. There are problems with this line of business though, namely that it doesn't scale very well unless, besides being good at a skill, you've also got the skills to build up a consulting business, which is very much about adding and managing people, something I'm not all that passionate about and would rather avoid. So what happens is that you go through slumps with less than full capacity, and then things pick up again, and before you know it, you hit your upper limit and can't take on any new work, putting a ceiling over your potential earnings. Sure, you can raise prices a bit, but that'll only get you so far. For a while now, I've been considering this problem, and I think some sort of product would be an ideal way out. Stories like Balsamiq's are inspirational, and along the lines of what I think might be nice. Don't get me wrong, I like my clients and like to help people solve problems a lot, but it's a stressful job in that you're never very far from having no income.
I'm not much of an entrepreneur, though, in the sense of someone with a nose for making money. I tend to think about building something cool first, and not really worrying about making money with it. Predictably, some of the sites I have created are popular, but don't make any money. Sure, they have some ads, but that doesn't really make much unless you get really huge page views or have some sort of content that attracts users who will click on very lucrative advertisements. I've started to think that perhaps I should constrain myself in new initiatives to creating things that have a direct source of revenue: you want to use it, you pay. In my daydream world, I'd probably just hack on open source all day long, but there's no money in that for someone like me who is not the author of some huge, famous piece of software, nor a particularly great hacker in any case (I've met some, like Andrew Tridgell, and it's a really humbling experience).
So that brings up the question of what to do with the aforementioned sites. One option would be to sell them off via a site like flippa.com, another would be simply to just let them sit there and stew, but they do take up some resources on my server, and require some maintainance now and then, and they're a bit of a distraction too (I start wondering about things to add or how to fiddle with them). Maybe there's a way to make money from some of them, but I'm too blind to see it.
The ones I'm thinking about, are, in no particular order:
- http://langpop.com - this one gets decent traffic, but programmers are about the best people in the world at ignoring advertisements.
- http://leenooks.com - the Linux Incompatibility List attempts to point out hardware that people should avoid if they intend to run Linux on their computers. Happily, there is less need for this site than when I conceived of it some 10+ years ago, but I think it's still a helpful resource.
- http://linuxsi.com - (in Italian) this one is a place that highlights stores and consultants who are "Linux friendly". Want to buy a computer with Linux? There's probably a store near you. I have had fun with this site, but, once again, no revenue.
- http://squeezedbooks.com - "open source" business book summaries and discussion. There are plenty of competitors in this space who make their money by churning out summaries and charging for access for them. I had hoped to build a community interested in reviewing and discussing books out in the open. There is a lot of fluff in business books, mostly because you can't sell a 10 page book that describes your idea, but need to pad it out with lots of examples and repitition and so on to make an actual book out of it, but that doesn't mean the idea at the heart of the book in question isn't an interesting or new one.
Erlang: Log to Files
Since I had a heck of a time finding out how to do something that ought to be really easy, I thought I'd post what I found. If you want Erlang to write errors to a file instead of stdout, add this to the command line:
-kernel error_logger '{file, "/tmp/erl.log"}'
Maybe there's a better solution, in which case feel free to correct me.
Better Software 2010
Florence, Italy, is an extremely popular tourist destination, and for a good reason: it's absolutely full of beautiful architecture and famous art. It apparently gets more than a million tourists a year. So it felt kind of odd for me, as a foreigner, to hole up in a conference talking about computers, software and business within a stone's throw of this.
It was well worth it though. "Better Software" was a very interesting conference, and extremely professional. One anecdote: since there were so many people signed up, they did the lunch and coffee breaks in another facility nearby, about a block away. However, the weather wasn't very nice, so the organizers rounded up a bunch of umbrellas, and put them near the door with a sign saying "take one if you need it", so that people could stay dry while going back and forth. Of course, having grown up in Oregon, I don't trust the weather much, and carry an umbrella, but it was a really nice gesture and attention to detail.
I expected it to be good, but it ended up being a really great event.
Some memorable bits:
- As always, it's good to catch up with old friends, and meet new people.
- Giacomo "Peldi" Guilizzoni's talk about Balsamiq was really good: he's an entertaining speaker, and the success of his company is a great story.
- Andrea Santagata gave an insightful talk about startups in Italy, and managed to cover a number of points that I've seen from people like Paul Graham and other "startup gurus".
- I had some interesting discussions with people about open source, business and economics, a topic I gave a presentation on.
- It was quite motivating to meet so many people working on cool things. Italy absolutely does not have a talent problem.
- The dinner was great: Bistecca alla Fiorentina for me, accompanied by red wine.
I suppose that, given the huge success of the event this year, they may look for a larger facility for future events, but I hope it doesn't end up in some soulless place in the suburbs; even if I didn't do any sightseeing, I liked being in the city center.
While the organizers would be more than capable of putting on a more international event, I enjoyed the focus on Italy, and the cool things people are doing here, and I feel it also contributed some to the positive atmosphere. It's one thing to have some guy come in from abroad and tell you something, another to see someone like Peldi talk about how he did what he did. And what with all the problems Italy has right now, some "positive energy" was more than welcome. Like I said, Italy has a lot of really talented people; the problems lie elsewhere.
A big thanks to the organizers and everyone who came, and I hope to see you there next year.