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.)

(will be screened)
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

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 Monday, 5 January 2026 05:38
Powered by Dreamwidth Studios