pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
[personal profile] pne

Quite a while ago, I started to post my weight to a community I created for that purpose, [livejournal.com profile] milixograke—in Klingon cheb and cheb'a', just for the heck of it.

A while later, I wrote a Perl script that would do the conversion from kg to cheb automatically, and post to LiveJournal (through the "flat" interface) while it was at it. I later added some code to convert to stone and pounds as well as calculate the BMI, then add that information to a database. (Haven't done anything with the data yet, though.)

That went all fine and dandy for over a year. A week or two ago, I thought I'd try to write the script in Python, mostly for practice in that language, since I had never really written anything in it.

That went reasonably well, after I figured out how to read and write HTTP and how to write to a database. What made the conversion slightly annoying is that Python is more strictly typed than Perl as regards strings vs. integers; in Perl, I could do something like $kg = sprintf("%.1f", $input); $lb = $kg / LB; (that is, use the string as a floating-point number), while in Python, I had to convert around with float() and int() a little bit. (Posts from the Python script go to [livejournal.com profile] milixobunda, for the terminally curious.)

Then yesterday, I thought I'd convert that to Java. My goodness, was that ever a lot of faffing around! Everything seemed more complicated and to involve more typing and looking things up than in Perl or Python.

Even after having got used to the need to convert a bit, doing so in Java seemed more complicated. For starters, the internationalisation got in the way; I wanted to be able to do something like sprintf("%.1f") for the subject line of the posts, but all the decimal-formatting things I found easily seemed to be locale-aware, so on my German Windows would give, say, "84,1 kg" which was not what I wanted. What I wanted was something equivalent to the "C" locale under C. Sites in the Web which discussed formatting numbers always seemed to use the default locale—which is pretty similar to the "C" locale when you're in the States, but not necessarily elsewhere. So that involved some faffing around with the DecimalFormatSymbols class, for example.

In the end, I got it to work… but it was fairly annoying along the way. Something might possibly have easier solutions that I just don't know about, but for now, it seemed that I was more productive in Perl and Python.

(Hm, I wonder whether I should give it a try in Tcl and Ruby, as well? Anyone have any other recommendations? Though completely different paradigms such as those of Haskell, OCaml, Smalltalk, or Lisp might be more challenging than I'm up for at the moment. Suggestions please only if accompanied by pointers to how to do (a) HTTP POST, (b) MD5, and, preferably, (c) how to insert a record into a MySQL database.)

Date: Sunday, 9 July 2006 06:43 (UTC)
From: [identity profile] ibneko.livejournal.com
Hey, friending you pretty randomly. I was actually looking through an old mysqldump of a livejournal clone I used to run (IBCorner.servehttp.com, now long gone. Go use archive.org if you're curious...) and noticed "(1,'email',0,'Philip Newton','pne@livejournal.com','open','7b7a5cyyj3gdqef',1,'I\'d like an invite code',1060406657,1060406657,0,0);" in the 'support' table, and thought I'd come over to say, "Hi, nope, sorry, I can't give out invite codes anymore," but I've found your entries to be pretty interesting, so uh.. you've got yourself another reader.

Date: Sunday, 9 July 2006 15:48 (UTC)
ext_78: A picture of a plush animal. It looks a bit like a cross between a duck and a platypus. (Default)
From: [identity profile] pne.livejournal.com
Welcome! I'm glad you found my entries interesting.

IBCorner does ring a bell, vaguely... There was a time when I tried to get an account on as many LiveJournal clones as I could find. Many of those are dead now, and I'm sure news ones have sprung up since then, too.

Profile

pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
Philip Newton

June 2015

S M T W T F S
 12 3456
78910111213
14151617181920
2122232425 2627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Thursday, 1 January 2026 19:00
Powered by Dreamwidth Studios