Search Results: "mpalmer"

4 January 2006

Matthew Palmer: Tabs Are For Indents, damnit!

(Working Title: "Light up the crack pipe boys, thinkin' time's over!") A tab is a wonderful thing. It makes everything line up nicely. So what does YAML ("indentation is so critical to proper interpretation of YAML" -- from the YAML FAQ) do with them? It bans them. Apparently Guido (van Python) thinks the same way -- using the key meant for indenting to indent things is a crime against humanity. And why is it such a heinous crime to use tabs, you ask? Because "they are treated differently by different editors and tools" . Where's the prohibition on using line endings, then? They're treated differently by editors and tools, too. Broken tools exist, that's true, but we don't pander to them -- we either fix them, or insult the people using them until they switch to something that doesn't suck. If tabs are criminal, why do we even bother to *have* a tab key, then? Just pry it off your keyboard and throw it out. It's obviously not useful for anything. Let us bang on our spacebars, and have endless flamewars about how many spaces a particular project should indent all it's code, instead of just using tabs consistently, and then setting your personal preference of tab stop width in your editor like the good lord intended. I am so amazingly and deeply pissed off right now. Bloody religious zealots -- "I don't like something, so neither will you".

3 January 2006

Matthew Palmer: Those who don't understand Unix...

... and so on. Today's example: For each File. Yes, you know what it does already. But that would make for a very short blog post, and that is so not my thing, so I'll quote the short description of the project:
For each File lets you run an arbitrary set of GNU BASH commands upon an arbitrary set of objects. It can be used to perform repetitive tasks such as renaming, extracting, moving, and manipulating a large number of files.
Yes, dear friends, someone has sat down and written a program (and associated manual) to implement a bash for loop (and possibly a bit of find as well). Since it's all written in bash, it's not as though the author of the program was incapable of working out how to write for i in /path/*; do [...]; done, either. I'm not quite sure which part amused me the most. Was it the ever-optimistic -devel and -user mailing lists, completely devoid of archived material? How about the user manual -- 40% of which was the licence text? Perhaps it was the fact that this not just a bash for loop -- it's a fully internationalizationable bash for loop. I know one thing, though -- with all of the energy put into this program (and it's been going for several years now, apparently) the author could have created the ultimate, never to be surpassed manual for the bash for keyword, which would have been significantly more flexible, and certainly less interesting to poke fun at. Addendum: the whole site that FeF is hosted on is accessable only via SSL with a self-signed certificate -- except for the download page, which is HTTP only. So you "know" that the non-existent list archives are really what they say they are (at least as long as you trust "Gna!" as a certificate authority, as I'm sure we all do), but the actual source code is hosted who-knows-where, with no useful assurances as to provenance whatsoever.

29 December 2005

Decklin Foster: Ruby Love

Matthew Palmer writes about the goodness that is Ruby. I, too, have just recently been won over, and am stumbling along with the online docs. In fact, this can be done in one line:
STDIN.readlines.sort_by   rand  .each    line  puts line  
But this is slow, as sort_by needs to be at least O(n lg n), and probably not perfectly random (I suppose you could do rand <=> 0.5, but that s not perfect either). What to do? We can implement a proper Fisher-Yates shuffle in a function, but that takes a couple lines. Can we still perform the actual read-and-print in one? Yesterday, why wrote something that really made me stop and go wow . We can attack the random sort problem in a similar (if more boring, as there are no lambdas to pass in) way, by simply adding another method to Array:
class Array
    def swap!(a, b)
        self[a], self[b] = self[b], self[a]
        self
    end
    def shuffle!
        each_index do  i 
            j = i + rand(length - i)
            swap!(i, j)
        end
        self
    end
end
STDIN.readlines.shuffle!.each    line  puts line  
Now that is cool.

26 December 2005

Matthew Palmer: Making DVD Movies

I recently came into posession of a collection of (smallish) WMV files containing photo slideshows. Unfortunately, they don't play on my DVD player, and SWMBO's laptop has No Hope of playing anything remotely like a video. So, technology to the rescue. Initially, I was just going to convert the movies into something that the DVD player would actually play, but by the time I had those, I was 95% of the way to doing the job properly, and it would (of course) look far nicer with menus and other Shinyness (instead of just a boring file menu), so I went all the way and made a complete DVD movie disc. The whole process was non-trivial to discover, but ultimately straightforward in practice (once you know the set of command line options to use), so I'm archiving this for posterity. I use Ubuntu Breezy. A lot of the packages I've used are under really heavy development, so slightly older versions may not work. If you're running another distro, finding compatible versions may be tricky (or not). Try the process with whatever you've got; if it works, great; if it doesn't work, try upgrading versions or something. Step 1: Convert Video Files To Something Less Bong Packages used: transcode 1.0.2-0ubuntu2 (trivial backport from Dapper; mail me if you want it, but the one in Breezy will probably work OK), mplayer 1.0-pre7cvs20050716-0.1ubuntu9, mjpegtools 1.6.3+rc2-0.0ubuntu2 As far as DVD players are concerned, WMV is non-existent (clever things). DVD players like some form of MPEG-2 video with AC3 or MP2/3 audio. So, we use transcode to convert the video. For WMV files in particular, only mplayer does the decoding right (the af6 plugin seemed to work, but the resizing didn't turn out too well). So, our command is:
 transcode -x mplayer -i $FILE.wmv -g 640x480 -e 44100,16,2 -o $FILE.tc --export_prof dvd-pal
Items of note: As I mentioned, the output from the transcode run is two separate streams -- an audio and a video stream. We want to combine them. This is quite easy:
 mplex -f 9 -o $FILE.vob $FILE.tc.m2v $FILE.tc.mpa
This is a simple "glue them together" command -- the only interesting bit is -f 9, which simply specifies a particular MPEG-2 multiplexing method (full DVD-compatibility, or some such). If things aren't working out for you, try -f 8, which I believe also works. Since you'll probably have a bunch of video files to convert at once, you'll want to automate all of this with a shell script or shell 'for' loop. Step 2: Make a DVD Layout Packages used: qdvdauthor 0.0.10-0.1 This is the bit that I thought would be hard, but is actually amazingly easy (the previous step took me two days to get completely right, this bit took me about an hour). Fire up qdvdauthor, answer any stupid questions it might come up with. When the main screen comes up, click on the 'Add Movie' button on the left hand side, then select the first video you want to add. Repeat as required to add all of the videos you want. (Remember to add the VOB files you created earlier, and not the WMVs you might still have laying around. D'oh!) Clicking on the 'Video' tab on the left hand side should list all of your videos. Check they're all there, and are the correct size. Next, create or find a suitable background picture or video to make your main menu background. I've only tried with an image, but it seems to accept videos if you give them to it. Click on the 'Add Background' button on the main qdvdauthor screen. Pick your image. The image will probably need resizing; just go with the flow and pick the correct image size. Now you need to add those funky little menu items for selecting on. This is the really cool bit. Right-click on the background image you've got, and select 'Add Text'. Drag on the background to create a text box. You'll get a dialog come up, type some text in the bottom box, then click 'OK'. This'll create the text on the background. Drag it around if you need to. Finally, right-click the text and select 'Define as Button'. Another dialog box will appear. Rename the button if you like, then pick which video you want to play from the select box marked 'vmgm'. Click 'OK'. Repeat as necessary. That's all the hard stuff done. You can add a sound clip to play over and over again if you like, but I haven't done that yet, so you're on your own there. Step 3: Make the DVD For this step, I needed to compile toolame from source. Get it from http://toolame.sf.net/. This is super-simple. Basically, just click on the giant icon labelled 'DVD' in the top toolbar. Follow the prompts. Click 'OK' as necessary. When the process is done, check the 'Keep Open' checkbox quickly, and go over the output to ensure nothing completely crapped out. Assuming all is well, you can make your DVD image by running:
 mkisofs -dvd-video -udf -o /tmp/dvdimage.iso $DVD_DIR
Naturally, replacing /tmp/dvdimage.iso and $DVD_DIR with appropriate values. Lastly, cook the ISO to appropriate media with something like:
 cdrecord -dao -eject -v speed=2 dev=1,0,0 /tmp/dvdimage.iso
Assuming all went according to plan, you should have a physical DVD you can stick in your DVD player and watch to your heart's content. Congratulations! You just did all of this in about a 50th of the time it took me.

Matthew Palmer: The Documentation Conundrum

Several times over the last few months, I've had a common experience: I write documentation (gasp!), and then nobody reads the damn stuff. This offends me primarily because (like most geeks) I despise writing documentation. However, I write it because I despise having to explain myself a dozen times over. Better to write it down, and then I never have to worry about it ever again. Then, after I've taken the effort to actually document something, nobody reads the stuff, and they just ask me directly -- and then get offended when I grunt "RTFM" at them and go back to my code. But you start to think: "why am I wasting my time reading these docs, when I could just save myself a few hours of my life and answer their questions as they appear?" Now that I've gotten into the documentation habit, lack of documentation elsewhere also offends me. I want to know something, so I go looking for some form of written expression related to the topic at hand (Google Is Your Friend) and come up completely dry. For free software, I can more-or-less live with it -- I follow TechnoYoda's advice, and Read The Source, Luke (and then document it). For other stuff, though (lock-in software, social processes) I've got no hope. I'm reduced to pouting in IRC channels until someone tells me what I need to know (and then I document it). But you start to think: "why do I waste my time looking for documentation, when it never exists anyway, and I could save myself some time by just asking directly in IRC or on a mailing list?" As we all know, there are two documentation-related universal truths in IT:
  1. Nobody ever writes documentation.
  2. Nobody ever reads documentation.
I got to thinking -- is there a causal relationship here somewhere? Did people write documentation in the olden days, but gave up because nobody ever read it, or did people originally always read the manuals, but stopped looking for documentation because it never existed (or when it did, it was content-free and useless)? Or did both of these truths appear independently, or are they both aspects of a single truth: "Everybody Hates Documentation"?

Matthew Palmer: Language Is Not Just Syntax

My current long-term learning project is Ruby on Rails, the ultra-hyped web application framework from David Heinemeier Hansson and friends. I like it (primarily because I can see a lot of my own abortive ideas from a web app framework for PHP I used to develop), but there is one big thing about it (or, rather, it's surrounding hype) that irritates me. Throughout the Rails literature (webpages, magazine and webzine articles, and the book Agile Web Development With Rails), there is a consistent message -- that, because everything is written in Ruby, you don't have to learn any new programming languages to write Rails applications. This is a wonderful theory -- no large XML config files to define my database schemas, and no castrated and irritating HTML template system to learn. From defining table relationships to printing a select tag, It's All Ruby, All The Time. Sweet, right? Sort of. The problem is that you won't find the language primitive to declare a one-to-many relationship in the Pickaxe (the definitive Ruby language reference book -- like "the Camel" for Perl, "the Bat" for Sendmail, or "the Turkey" for PHP). Defining a separate namespace in Rails for all of these operations is, of course, necessary, since the language didn't already define these operations. But, once you've defined a whole new set of methods to do all of these operations, you can look back on your hard work and see -- what? A new language -- one specifically designed to describe webapps. Don't get me wrong -- domain-specific languages are teh r0x0r. If everyone had to do all of their HTML manipulation by hand, programmers would be even more insane than they are. But, when you're writing your application in Rails, you're not speaking "pure Ruby". Your syntax and basic structure is Ruby, but your methods and attributes are new, different, and All Rails. It may not be a separate programming language in the usual sense, but by the time you've added a whole new pile of classes, methods, and attributes (not to mention whole new ways of structuring your application), how much importance is the use of the @ symbol to signify an instance variable, compared to the whole new set of methods to learn? Natural languages, of course, have similar issues. Most western european languages share a lot of common characteristics -- similar character sets, punctuation sets, and they read left-to-right. So I can look at a page of German or French, and identify most-to-all of the salient features (hey look, an 'a'!), and even grok the meaning of a few of the words (familiar to me, probably, because English misappropriated them from wherever they came from) but I still have no hope whatsoever of understanding the meaning of the passage as a whole. The language syntax looks familiar, but those nouns and verbs don't have any meaning to me. You can't plonk a Rails app in front of even a seasoned Ruby developer and expect them to immediately jump in and start hacking on it like they've been writing it all their life. The language syntax looks familiar, but those methods and attributes don't have any meaning to them. This is nothing peculiar to Rails, of course. If you want someone to hack on your Hibernate or Spring app, you'll get better results if you advertise for a Hibernate or Spring programmer than a Java programmer. But Rails advocates regularly say "it's all just Ruby, so there's nothing new to learn!", and that's Just Wrong, in my opinion. As an aside, if you're looking around for something a bit different, do seriously consider Rails (or just Ruby, if you don't need a webapp framework). It's different from the "usual" suspects (C, C++, and "the Ps" -- PHP, Perl, and Python), and pleasantly so. If you judge your programming languages by the old adage "a programming language that doesn't change the way you think about programming isn't worth learning", Ruby will score well. I know it's helped me think about my programming differently already, especially my Python programming (and thanks to Anthony Baxter for answering all of my esoteric python questions at OSDC a couple of weeks ago).

24 December 2005

Matthew Palmer: My Alternate Career

I have decided, if I ever get tired of working in IT, that I'm going to open a swimwear shop, and call it "Swimmers 'Ere". Thankyou, I'm here all week.

21 December 2005

Matthew Palmer: Ubuntu is now a mature distribution

In my eyes, Ubuntu now has all of the pieces of a mature, well-rounded distribution. What was the missing piece, you ask, that Ubuntu has finally aquired? It's mailing lists now have the ability to sustain a long and pointless discussion, containing a signal-to-noise ratio low enough to cause me to actively add filters into my mail setup to get rid of it (instead of JHD).

16 December 2005

MJ Ray: Revision Control Systems

"All revision control systems suck. This one just sucks less."
That's roughly what I'll say when I find one worth it. I've used rcs, cvs, svn, prcs, tla, arx, monotone and probably some I've forgotten. They all suck, in different ways. I'm now really reluctant to install a new revision control system unless there's a clear benefit. Matthew Palmer:
"Subversion is the One True Revision Control System and we should all just Stop Worrying and Learn To Love The Handcuffs"
Current target of my wrath is subversion, the lardy cake of revision controls. Over 5 times the footprint of CVS gets you atomic commits, but similar design problems with centralised servers and corruptable roots. Server choice is either a pserver-look one or an apache server with all the trimmings. The licence isn't even GPL-compatible, so forget about neat integration into some editors and development tools. Finally, if CVS is "extremely dead" despite its last release in October 2005, then SVN must be buried and rotting because it hasn't released since August. I tend to prefer distributed systems, especially when done well with standard protocols so that I can copy the archive somewhere close to me and work with it at relatively high speed, or off-line. It also gives the benefit that I merge when I want to, rather than being forced to choose between commit and branch. Centralised systems seem to make branching needlessly fiddly. Beyond that, I strongly prefer a system which can generate tarballs and patches (as far as possible) so that the rest of the world doesn't have to install the binaries (even if they can). That's about the base level of compatibility for now and any new tool should at least try to support it, even if the export loses some information. (I'm currently using a small shell script which just automates tarballs and patches, to help me move between my two computers here. I know it's only a 90% solution, but it's one I understand and can put some faith in. I need to have faith in my RCS. I like little less than losing work. Next step is to automate updates and merges, rather than doing them by hand.)

15 December 2005

Gunnar Wolf: Moving between version control systems

As many people have expressed in their blogs after Bubulle's initial rant, I am also joining the game :)
Some weeks ago I decided to finally move my personal documents repository from CVS to SVN - Why SVN? Because I don't need a distributed system, I am the only person with write (or read) access to it... Besides, I'm too lazy - The one feature that made me start using SVN and not any other system is that you can use it just as if it were CVS, but without the ridiculous constraint placed by just integrating many individual files instead of managing the whole beast as a repository.
I had a problem, though, that made me lose good part of an evening - I think it might be related to #333105, but I'm not sure: I converted my repository using cvs2svn, which saved all my five years worth of commit history (whee!), grouping commits that seemed to belong together in single SVN transactions (whee!!)... But binary files were all corrupted. To make things worse, I didn't notice this until I had to present a talk in Peru - and my laptop's working copy was severely FUBAR.
Well... I managed to give my talk - And yesterday I finally decided to restore sanity to my life, reviving my doc_gwolf SVN tree. The stupid steps?
Phew :-/

14 December 2005

Benjamin Drieu: CVS rulez (Score:-1, Flamebait)

As it seems people are arguing about the revision systems hype, I just wanted to point that CVS rulez. Sure, it does not $some_obscure_witty_feature but, hey, is this feature really useful? I've been using CVS for ten years, coded around 500k source line of code and honestly, it suits all my needs. To tell the truth, I don't even use all of its capabilities. So, CVS can't keep history of a file when you move it. Big deal? After all, renaming a file is just like creating a brand new one. Leave a commit message stating previous name of foo is bar if you really need history and that is it. So far, I never stumbled upon a case where this "feature" limited me or made me loose more than 15 seconds. Same for distributed RCS. Sure, on the paper they look good. Call me a moron but I never managed to use one properly. Even a large but well managed project does not need such monstruosity. Matthew is right on one point: RCS are like languages, geeks advocate languages because of a specific subset of features. But they don't realize 90% of functionality of a language is present in all other languages and the 10 other percents can be achieved with method if you really need them. I personally find very discouraging to learn a brand new RCS for every project I contribute to if upstream has decided this one is cool. If you want users to contribute, use a standard RCS as well as a standard mailing-list system, common language, etc.

13 December 2005

Matthew Palmer: Diversity in Revision Control

Josselin Mouette has thrown down the gauntlet -- Subversion is the One True Revision Control System and we should all just Stop Worrying and Learn To Love The Handcuffs. In particular:
[...] just use subversion, and if you feel it's missing features, please contribute them. By standardizing on subversion, we lower the barrier for people wanting to contribute, instead of increasing it by asking them to install and understand new tools.
Quick thought experiment, Josselin: replace "subversion" with "Java". Or "Perl", or "C", or even "Python" or "Ruby". Or any other language. It doesn't matter which one. Even if the language you substitute is a good one, and one you happen to like, it's still a fairly obviously braindead idea -- that there can possibly be One True Programming Language for all problems, and that there can never be any improvement that can't be bolted into the existing OTPL. Revision control isn't so much different from programming languages. Different systems will provide different advantages and disadvantages. There's also incremental and revolutionary improvement that will take place over time -- machine code to symbolic to procedural to object oriented -- that can never take place within the established framework. I happen to really like the distributed model -- it reduces (though, naturally, cannot eliminate) the division between the Blessed and the Peons in a project (those with direct commit access vs. the rest of us). You can get disconnected operation for (almost) free. Also, despite the assertions contained in your article, the "barrier to entry", ironically, is actually lower with a good distributed RCS than with Subversion. The barrier isn't what you think, though -- sure, using an unfamiliar RCS is troublesome, but it's a lot less hassle than learning a new language, and people do that on occasion to hack on a particularly interesting problem. The real barrier to entry is forcing anyone who isn't blessed with direct access to The One And Only Repository to use inferior development support tools. "An example!" I hear you cry. Gladly. This morning (literally) I got enough of a handle on the internals of Ruby on Rails to actually track down a bug that was irritating the crap out of me. Being a good developer, I wanted to use revision control to track my changes. In the All Subversion, All The Time "utopia", that would involve getting an anonymous checkout, making a copy, hacking on the copy, then (when all was done) running diff -urN between the original and the copy, and sending it all upstream with a manually-created log message (assuming I could remember everything I'd done). You also need to manually remember (or encode it in your directory or something) the source of your tree, so upstream can merge it reliably (and compare it against other equivalent work that may have been done in the meantime). Doing it better, I could do an anonymous checkout, and then import it all into a new Subversion repository (or directory) of my very own, and hack on it in there. Benefit: revision control of my changes. But it's non-trivial to create a new repo and import everything into it, and there's still no automatic record made of the upstream source of my new repo. Wanting to make a second change is even worse -- I either have to make a whole new copy of my source tree (disk is cheap, but this is getting silly) or just keep forging ahead with changing my existing tree -- so this second set of changes can end up being dependent on the first (which is Not So Great if upstream don't merge your first patch). In the "new repo" scenario, you can branch from the root of your new repo and continue hacking on your newly created branch, which is a good start, but it's still icky. And good luck having the system track new commits from upstream while you're working, too. If the project was using a DRCS, in contrast, the problem would reduce to making a branch into your local archive, hacking (committing at will), updating with new upstream commits as you go along, and then publishing your changes to a public place for reintegration (or, in some cases, sending your changeset via e-mail). Oh, and before anyone starts screaming "if anyone can branch, it will encourage forking!", consider which is more likely to result in a permanent fork (rather than a temporary independent line of development): a local set of changes in a tarball or local subversion repo, both of which are hard for anyone else to collaborate on without major pain; or a branch in a simple-to-publish (or push) designed-to-be-shared DRCS archive, which automatically keeps all of your interesting metadata intact and coherent across archives, merges, time, and space (and possibly even dimensions). This utopia doesn't really exist, and is hampered by everybody having their own Pet DRCS, but the problem, I'm fairly sure, is transient, and my main point isn't even so much against the choice of Final Ultimate Solution, or even the problem space, but more about the attitude that everyone should get behind Any One System and stay there. I can't imagine the world of pain we'd be in if Josselin had posted his message a few years ago (but with s/subversion/CVS/i, naturally) and everyone had followed his advice -- can you imagine per-file changesets with no effective merge capability for the rest of eternity? <shudder />

11 December 2005

Matthew Palmer: FORTH: The One True Language

Just reading the comments associated with a post from the reddit.com people about a rewrite of their entire site from Common Lisp to Python. The Lispers are screaming "noooooo!", the Pythonistas are grinning smugly, and the Rubyolas are asking "why not us?". In the middle of it all, comes this gem (unfortunately, posted by "Anonymous", so no attribution):
Real men would design a custom ASIC and write a new FORTH system optimized for Reddit, complete with custom developent environment, web server, etc. It would multiply the development time-to-1.0 by about 2-4x, but the entire system would be smaller than the ethernet plug, would handle a saturated gigabit pipe with sub centisecond latency, never crash, and use less power than your toaster. Everyone would be too busy saying "WTF is FORTH?" to bitch about you not using Ruby on Rails. Then you'd lose to the guy who did it in PHP (*turn* *puke*), because it's not about the technology, stupid.

Matthew Palmer: Planet Saves the Day!

Never one to miss out on a good fad, I've recently been getting interested in Ruby on Rails. (OK, maybe it's not fair to call Rails a fad -- it looks really good -- but it is the Tech Of The Moment). What's the first thing you do when you hook onto a fad? You find the relevant blogs. Handily, RoR (as the in-crowd calls it) has a Planet-style aggregator, Planet Ruby on Rails. Less handily, the site is running a *very* half-arsed aggregator script that doesn't escape any of the HTML in the entries, so Liferea summarily spits the dummy at them all and I see nothing but titles in my viewing window. I sent a polite (yes, really!) e-mail to the site admin, asking if it might be possible to get an escaped version. I haven't had a response in a few days, and a lot of the entries look really interesting. So, I've installed my own local Planet RoR aggregator -- running The Real Planet. Planet is astonishly easy to install -- 3/4 of the work was writing the shell script to take the OPML from the original Planet RoR and massaging it into Planet config.ini format. So now I have Real Articles to read again. Life is good.

4 December 2005

Matthew Palmer: My Number One Travel Accessory

I'm currently in Sydney Airport, about to board a plane for Melbourne and OSDC 2005, and, as usual, I did the whole pointless security dance (even Amanda Vanstone agrees with me!). This time, however, was different -- I had all of my pocket-cruft in a new bumbag ("fanny pack" I think it is in American) instead of in my pockets. It was by far the fastest I've ever gone through a security checkpoint anywhere. I just whipped off the little baggie, slipped the lappie out of it's bag, stuffed all of the items on the conveyor, went through the metal detector unmolested, and grabbed my gear on the other side. I was off and running again in about 20 seconds. Now that I've posted this, of course, my trip through the security screening on the way home on Thursday will involve having my hemorrhoids aggrevated by a large man who has just been through a messy breakup and a triple shift...

Matthew Palmer: spellcheck.google.com

Don't know how to spell a word, but have Internet access? Just type your best guess into google and have it ask you if you meant the correct spelling. GoogleGuys, I expect a hefty commission check when you take the above URL live, BTW... <grin>

Matthew Palmer: "Average" skills in a resume

Just reading another painfully funny The Daily WTF[1] entry. Instead of a code snippet, this was a resume snippet instead. Apart from listing skills in such heavyweight corporate tools as Emule, Kazza, Paint, WordPad, Acrobat Reader, and Winzip, the candidate also listed "Average" knowledge in a very, very wide variety of skills. The important question is, over what collection of the population is this average taken? Considering the usual demonstration of these "Average" skills, I think that the average is taken over the entire mammalian population, including all of those dolphins who (thankfully) have never even heard of "Micro Soft Visuals: Basics", and that dog at puppy training this morning that spent most of the time licking it's own genitals. Self assessments are always bollocks. Nobody's seriously going to rate themselves "half-assed" at every programming language they know. I've seen one interesting way to describe your language proficiency, though -- group languages into "used in the last 6 months", "1 year", "3 years", and "dim, dark distant past". It gives a reasonable idea of what languages you might be useful in, either through current knowledge, a past knowledge that can be polished, or perhaps knowing a language similar to the one that the company needs skills in that you can be cross-trained into.
1. A site dedicated to archiving, for posterity, the worst of the code that controls the world. Scary and hilarious all at once.

2 December 2005

David Pashley: OOP Strikes Back

Steinar, you missed my point. I explicitly said not to get bogged down in my example. The point is that changing the internal details of your class shouldn't result in your users being forced to change their code. As I said, exposing your implementation tightly couples your code and your users. As Matthew pointed out, you shouldn't have sets and gets for every item in your class. You should have a clearly thought out api that isn't tied to the internal detail. Exposing internal, either through making data public or blindly creating gets and sets for private data members is just bad OO design. An addition to my example that makes things little cleared would be a subclass that validated the words you could use. With a public variable I couldn't enforce that, but I could override my setter to add validation.

Joe Wreschnig: Python, again

Accessors
Matt, Python has advanced tremendously and supports uniform access even more nicely than Ruby. You don’t need to play __getattr__ games at all. class Foo(object):
    def get_foo(self): return unmangle(self.__foo)
    def set_foo(self, value): self.__foo = mangle(value)
    def del_foo(self): ...
    foo = property(get_foo, set_foo, del_foo, "docstring goes here")
There’s actually a nicer syntax with the new decorators, but this will work with the Python in Debian. Unlike Ruby, this means you can un-wrap the attribute later if it turns out you don’t need mangling functions and do need speed. (Dick Davies pointed out I said this without anything to back me up. Timing these different methods, it turns out raw attribute access in Python is 30% faster than Ruby’s attr_*, which in turn is 50% faster than manual attribute setters in either language; non-property-ized Python get/sets are slightly faster than Ruby, but property-ized ones are slightly slower. There is a definite advantage to being able to expose the raw attributes.) Really, public get/set methods are a nasty hack, mostly restricted to C++/Java and Ruby/Python/etc. written by people who spent too much time around C++. Welcome
Michael Urman, co-developer of Quod Libet (and author of its sexiest parts), finally got a weblog. Currently there’s not much there, but he’s (hopefully) going to write about the metaprogramming he used to write an awesome Python ID3 reader/writer, and also some details on the Python interpreter bugs we keep turning up.

1 December 2005

Matthew Palmer: OOP and the Get/Set issue

Steinar, your comments on the limited utility of Get/Set methods both struck a chord and touched a nerve with me. On the one hand, I completely agree that people need to spend more time writing methods that do something useful to an object rather than just exposing public methods. For example, how often have you seen something like this (in faintly python-inspired syntax):
 obj.count += 1
 [...]
 obj.count -= 1
 [...]
 if obj.count == 0:
 	obj.destroy
Instead of the far more descriptive (and well-encapsulated):
 obj.register_user()
 [...]
 obj.unregister_user()
 [...]
 obj.destroy_if_unused()
(or any one of a thousand other similar idioms). This is a contrived example, of course, and a real example would involve doing at least a dozen operations on an object's public attributes from another class (which results in class-associated logic being located in other classes in the system) instead of putting it in a method and calling that (thus keeping all of the logic with the data it's manipulating -- which is the point of OOP). Anyone who writes code like the first example above and calls it OOP is kidding themselves. Of course, you could make the code even more ridiculous with getter/setters:
 obj.setCount(obj.getCount()+1)
 [...]
 obj.setCount(obj.getCount()-1)
 [...]
 if obj.GetCount() == 0:
 	obj.destroy
Incidentally, if you ever see anyone turn the first example into the last example and say they're "improving encapsulation", please do the programming world a favour and kill them. kthx. On the other hand, Steinar, you say "I'm not denying that getters and setters for a few variables might make sense", which clouds the issue immensely. The idea of routing attribute access through a method is immensely useful. It even has it's own name -- the Uniform Access Principle. A few examples are in order (you might already have thought of these, Steinar, but who knows who reads my dribblings!): In my real-life case, there were few enough places to change all of the calls to a method, and since it's all written in Python I could have played __getattr__ games to get back to a method if I'd had to, but it would have been messy. But imagine a system written in a language that doesn't (somehow) support the Uniform Access Principle, and which was widely deployed (possibly even used by programs outside of our direct control) so the users of the class couldn't be adapted easily. Nightmare. Now, the real solution to the problem is to only use languages which support the UAP (Python can be hacked to do it; Ruby is, IMHO, almost a case-study in How To Do It; and there are other good languages out there). But, in ass-backwards languages that can't transparently map attribute accesses to method calls, I'd rather deal with getX()/setX() everywhere than have to try and perform the necessary gymnastics to later support dynamic value generation from what-was-previously-an-attribute. If, on the other hand, your post was primarily targeted at said ass-backwards languages, or programmers who cargo-cult manual getter/setters everywhere, let me join you in your derision. <grin>

Next.

Previous.