Tuple Madness 65

Posted by tottinger Tue, 13 Feb 2007 18:07:16 GMT

If there is a downside to modern OO languages like Python and Ruby it is the great built-in list types. They’re wonderful, but they’re tempting.

Today I had my fourth or fifth encounter with tuple madness. It seems that the siren song of “free” data structures with unnamed members is just too much to resist. I’ve decided to call it Tuple Madness. An example is: x = (2,3,-1) Could one be less descriptive? Probably not.

I came across some code which uses two-tuples where both values are encoded integer values. It’s a pain to figure out.

In a previous job, a coworker would write his python entirely as filters on n-tuples so that figuring out what his code was doing was really painful. A function would take a sequence of n-tuples, and return a sequence of n-tuples where some of the values were preserved (though reordered) from the input, and the rest were transformations on the input + some local data. It was really tough to read a program where the data structures had unnamed elements and only existed between the return of one function and the invocation of the next.

At least one of my colleagues has blogged about suffering from Tuple Madness as well.

I don’t think that “magic tuples” are always evil, only that they’re no substitute for proper objects and meaningful data structures.

Trackbacks

Use the following link to trackback from your own site:
http://blog.objectmentor.com/articles/trackback/169

Comments

Leave a response

  1. Avatar
    Michel about 1 hour later:

    As an old scheme/lisper where tuple/list like structures is the core abstraction and being taught programming by reading “Structure and Incterpretation of Computer Programs” by Abelson and Sussman. You learn its a good idea to write accessors to your tuple structures to raise the level of abstraction and enhance readability.

  2. Avatar
    YAChris about 2 hours later:

    As another old Lisper, when I saw XML my first thought was “Named Parentheses!” My second thought was “GREAT!”

  3. Avatar
    Samuel A. Falvo II 5 months later:

    I prefer Io’s structures—they’re much more readable than XML. But I digress.

    It sounds like the Python coder has a strong functional programming background. You’ll need to become more familiar with functional programming to understand more clearly the reasons why he did things the way he did (and that will, in turn, help elucidate the code and make it substantially more maintainable).

    Still, taken to the extremes, writing ML code in Python is generally considered bad form by all parties around, including other ML coders. :)

  4. Avatar
    Tim 12 months later:

    No, I don’t think so. I understand the appeal of functional programming, and my problem is with the parade of obscure intermediate forms, all produced by obscure functions. Realize that I love “clear” and despise “clever”. I found this program to be very clever in its use of primitive structures, and not very clear at all.

    I don’t have the actual code, and it was very, very, very long, but it looked mostly like this (strawman):

    def t23(x):
            if x[7] == 'a':
               g = 8
            else:
               g = 4
            return  (x[0], x[9], x[4], x[5], x[3], g, x[1])
    

    Clearly, it rearranges some of the input elements, drops some, and adds a new derived value. It does so without any real reference to the meanings of the input, transformation, or output.

    Was there a meaning to that transformation? I would revisit it a few times, and still not know. It seemed to be arbitrarily decomposed and recomposed, as if the goal were to multiply intermediate forms. I suspect that Occam would have vomited.

    The issue is not with the use of filters, but that the function and the data it operates on are completely non-self-describing, and can only be understood by grasping the entirety of this absurd parade of intermediate forms, from program start to program end.

    A parade of meaningful forms, produced by meaningfully-named functions, operating on named variables, would have been quite welcome.

    Indeed, it seemed to me that some transformations only existed to rearrange the elements of the array to an order expected by the next filter, which rearranged the elements for uncertain reasons. Considering that all the transformations were local, non-reused, purpose-built, that seemed mad to me. Why not keep the smallest number of functions on the most consistent forms?

    Also realize the application was not number-crunching, was not parallel, and was not being run as a unix text filter. It was purpose built to manage mostly-textual structured data.

    The python programmer had just learned lisp a bit earlier. It may be that he was trying to write lisp in python. I may be wrong, but I don’t think that’s how it’s supposed to look. He once bragged about how deeply he’d nested his lambdas, so maybe it was a brand of cool built out of complexity for complexity’s sake.

    Python gives us unpacking syntax, so this could have been more clear, even if nothing was done to make it more simple:
    def reorderForSorting(x):
         first_name, last_name, birth_date, address = x
         return ( birth_date, last_name, first_name, address )
    

    Maybe I’m a piker here, but it seems that there should be a way to make any code more clear, so that it can be adapted and maintained. Is that not a goal?

  5. Avatar
    hermes replica watches over 4 years later:

    situation is improving.”Call volume replica hermes scarves volume has been very high due to hermes h enamel bracelet to two days of airport closures and burberry nova check bowling bag and flight cancellations,”

  6. Avatar
    Criminal Records over 4 years later:

    The issue is not with the use of filters, but that the function and the data it operates on are completely non-self-describing, and can only be understood by grasping the entirety of this absurd parade of intermediate forms, from program start to program end.

  7. Avatar
    Tenant Screening over 4 years later:

    A parade of meaningful forms, produced by meaningfully-named functions, operating on named variables, would have been quite welcome.

  8. Avatar
    SEO Firm India over 4 years later:

    Thanks for this post, I have searching this kind of information for how many times, this is really great… hope that you will continue sharing for your knowledge, I’ll be back again to read some of your post…

  9. Avatar
    Robert Schlee over 4 years later:

    Identified your website on del.icio.us today and really liked it.. I bookmarked it and can be again to verify it out some a lot more later on ..

  10. Avatar
    okey oyunu oyna over 4 years later:

    Thanks a lot it is very useful for us…

    Dünyan?n en büyük online okey oyunu bu sitede sizleri bekliyor. Gerçek ki?ilerle sohbet ederek Okey Oyunu Oyna ve internette online oyun oynaman?n zevkini ç?kar

  11. Avatar
    clip in hair extensions uk over 4 years later:

    Whoa! This is a long one! I’ll have to read the whole thing when I finaly get home because the topics seem interesting.

  12. Avatar
    UGG Winter Boots over 4 years later:

    Thanks for this article.I learned a lot of knowledge from this post.I hope you keep sharing your knowledge with us.If you want to buy boots you can contact me.I will do my best for you .

  13. Avatar
    cheap Juicy Couture over 4 years later:

    I am so glad that I have found this your article because I have been searching for some information about various recipes from pig meat almost an hour. You helped me a lot indeed and reading this your entry I have found many new and useful information about this question. Well, I will definitely bookmark your website and wait for other useful and detailed posts like this one in the future. Regards

  14. Avatar
    Pickourstyle over 4 years later:

    Thank you so much for the English translation! I love this shawl and will be making is soon.

  15. Avatar
    takewatch over 4 years later:

    This shawl just jumped to the top of my project list! Very pretty indeed. Thanks for sharing the pattern with us.

  16. Avatar
    toppuma over 4 years later:

    very interesting article,and i am so happy to see this,thanks to lovely share

  17. Avatar
    Tory Burch outlet online over 5 years later:

    Your blog is a great one. What really impresses me is that you are correctly mentioned that there are thousands of tools that are available to create a website or launch one but what matters is that you choose the right one, the one that gives you all that is actually needed

    Well good to read about this thanks.

    Awesome…It’s nice share that, thanks very much!

  18. Avatar
    longchamp online store over 5 years later:

    Thanks for posting some great ideas and I’ll try to return back with a completely different browser to check things out! Also, I put a link to your blog at my site, hope you dont mind?

    I am about to begin a blog and this will help me tremendously. Of course it has given me many things to consider as I update my website too. I appreciate it much.

    good post as always man

  19. Avatar
    juicy couture on sale over 5 years later:

    You have a cool web site. It is almost the first time I encounter something like that.

  20. Avatar
    juicy couture on sale over 5 years later:

    That Post is Full of informative. Thanks for that kind of sharing. Hope u will again share with us.

  21. Avatar
    Womens true religion crops jeans over 5 years later:

    Well, if anyone can shed some light on how genius does work, it’s people like Paul Simon, Frank Gehry, Tim Burton and Sarah Ruhl. Gathering together some of the most respected names in a Mens True Religion Straight Leg Jeans Buy Mens True Religion Bootcut Jeans Buy Mens True Religion Flare Jeans variety of the arts, The Atlantic has a got a series of first-person essays on the creative process of some of today’s most brilliant minds.

  22. Avatar
    beats by dre store over 5 years later:

    compressed package, damn the system tray did not integrate winrar, Heidengxiahuocheap beats by dre beats by dre store one by one to ask dorm brothers finally have a brother that he computer memory yet, and immediately use U disk to copy to, The results found winrar370.rar … ...

  23. Avatar
    burberry wallets for men over 5 years later:

    The “it” bag has become the decisive accessory for young twenty something girls partying every night on. Another attraction to using the big bag is the skinnier illusion it creates of the carrier adding much need excitement to any sort of unexciting outfit.

  24. Avatar
    beats by dr dre over 5 years later:

    night on. Another attraction to using the big bag is the skinnier illusion it createsbeats by dr dre beats by dre sale of the carrier adding much need excitement to any sort of unexciting outfit.

  25. Avatar
    Marc Jacobs Outlet online over 5 years later:

    This blog details are very much interested to the customers and frequently visit this website. Thank you very much for proving the wonderful services.

  26. Avatar
    Zara leather Jackets over 5 years later:

    Thank you to share with me for something

  27. Avatar
    Zara leather Jackets over 5 years later:

    thank you ! I like this news, I also have information to share, here is my message http://www.fashtogo.com

  28. Avatar
    /dev/urandom over 5 years later:

    Named tuples: http://docs.python.org/library/collections.html#collections.namedtuple

  29. Avatar
    footycall over 5 years later:

    This is very exciting article, read it with deep feeling. http://www.footycall.com/

  30. Avatar
    FM TRANSMITTER over 5 years later:

    Do you know something about t FM TRANSMITTER, are you looking for it for yourself. Today I will introduce it to you. it is a 25 W FM transmitter, the 25W FM transmitter have a lot of Advantages.First: the 25W FM transmitter is a handy and portable device which you can plug into the headphone jack or in an output port of portable audio and video device for instance, a portable media player, CD player or satellite radio system. The sound is broadcasted through the transmitter which plays through an FM broadcast band frequency. The use of 25 W is to play music on the go such as driving through a car, while using stereo and through radio. It plugs into the audio output of the devices and converts the audio output into an 20W FM TRANSMITTER signal which can be caught by the electrical device attached in the car or portable radios.Second: with a 25 W you can listen to your favourite songs without any problem.

  31. Avatar
    iPhone contacts backup over 5 years later:

    It is true. I agree with what you’ve said and you can really give me advice in programming. To realize this idea. we need do more practice.

  32. Avatar
    http://www.mydubstep.co.uk/category/dubstep-artists/ over 5 years later:

    it seems that you have strong grip on the topic. i really liked your site. great job.

  33. Avatar
    hunza over 5 years later:

    viagra High-fructose corn syrup (HFCS) is a popular sweetener because it is chemically different from sugar—it has a longer shelf life and mixes better into beverages. Yet the corn industry likes to downplay these differences, pointing out that sugar is 50 percent fructose and 50 percent glucose, while…

  34. Avatar
    iPod Touch Converter over 5 years later:

    When I originally commented I clicked the Notify me when new comments are added checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks! , convert all video to ipod touch format

  35. Avatar
    sha1 vs md5 over 5 years later:

    I had really like it very much for the great technology in this blog and the great technology in this blog. This info is gathered for this info in the different websites that to helpful info in this blog

  36. Avatar
    viagra over 5 years later:

    Your blog page is excellent. Thank you truly for sharing a huge amount of powerful ideas. I will bookmark your web site and will be without a doubt coming back. Again, I appreciate all your work and supplying much priceless info for the many people.

  37. Avatar
    louboutin sales over 5 years later:

    Tuple Madness 36 hoo,good article!!I like the post!12

  38. Avatar
    bladeless fans over 5 years later:

    Tuple Madness 37 good post174

  39. Avatar
    laptop over 5 years later:

    I have unit converter pages online, would you please be interested in placing my website’s link (code below) on your page with the unit conversion tables? Thank you very much.

  40. Avatar
    essay help UK over 5 years later:

    I found your website perfect according to my needs. It contains wonderful and helpful posts. Thanks for it.

  41. Avatar
    Viagra over 5 years later:

    oakley radar range Such a horrible wound, Dr Tam has no fear, concentrate on the treatment, so stand Zheng moved. ry32cvb

  42. Avatar
    Baseball umpire over 5 years later:

    well, this is really a nice post.I really like the way you start and conclude your thoughts. Thank you so much for this information. keep posting such good stuff

  43. Avatar
    http://www.primelogodesign.com/ over 5 years later:

    hey mates,this is one of the best posts that I’ve ever seen; you may include some more ideas in the same theme. I’m still waiting for some interesting thoughts from your side in your next post. Best of luck

  44. Avatar
    College Sluts In Panties over 5 years later:

    Thanks for sharing the idea there would be some apprehensions from segment but i am up for it.

  45. Avatar
    Computer Repair Henderson over 5 years later:

    Thanks for sharing the idea there would be some apprehensions from segment but i am up for it. (www.doctorsoftechnology.com)

  46. Avatar
    Las Vegas Magician over 5 years later:

    Great to know the—in depth from this blog.This will really help for my forward steps to be taken.

  47. Avatar
    Henderson Web Design over 5 years later:

    Thanks a lot for blogging this, it was unbelieveably informative and helped me tons.

  48. Avatar
    MAC insturt over 5 years later:

    I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will locate that extremely useful

  49. Avatar
    Jewelry los angeles over 5 years later:

    Great to know the—in depth from this blog.This will really help for my forward steps to be taken.

  50. Avatar
    hermes light over 5 years later:

    Biodegradable bags have become popular these days?

  51. Avatar
    webcam sluts over 5 years later:

    Great to know the—in depth from this blog.This will really help for my forward steps to be taken.

  52. Avatar
    webcam sluts over 5 years later:

    Great to know the—in depth from this blog.This will really help for my forward steps to be taken.

  53. Avatar
    California estate planning attorney over 5 years later:

    Thanks for sharing the idea there would be some apprehensions from segment but i am up for it.

  54. Avatar
    diya over 5 years later:

    click here</> Hi, I thought I would drop you a line and inform you that your page layout is really messed up on the Firefox browser. Seems to work fine in Internet Explorer however. Anyways keep up the good work.

  55. Avatar
    Hotels in Galway over 5 years later:

    Great to know the—in depth from this blog.This will really help for my forward steps to be taken.

  56. Avatar
    suppplements2n4health over 5 years later:

    A mind blowing article is provided here. And it is written with great skill and the words directly explain the thought of author and it is nice to know the information provided around the Earth and really it is great topic of interest.

  57. Avatar
    Accommodation in Galway over 5 years later:

    Thanks for sharing the idea there would be some apprehensions from segment but i am up for it.

  58. Avatar
    Orange county living trusts over 5 years later:

    Great to know the—in depth from this blog.This will really help for my forward steps to be taken.

  59. Avatar
    essay editing services over 5 years later:

    I see the player piano as the grandfather of the computer, the ancestor of the entire nightmare we live in, the birth of the binary world where there is no option other than yes or no and where there is no refuge.

  60. Avatar
    Hair Salon Las Vegas over 5 years later:

    I wanted to thank you for this excellent read!! I definitely loved every little bit of it.Cheers for the info!!!! & This is the perfect blog for anyone who wants to know about this topic. You know so much its almost hard to argue with you …...... thanksHair Salon Las Vegas

  61. Avatar
    Hair Salon Las Vegas over 5 years later:

    Great to know the—in depth from this blog.This will really help for my forward steps to be taken.

  62. Avatar
    Privathospitaler over 5 years later:

    Imagination grows by exercise, and contrary to common belief, is more powerful in the mature than in the young.

  63. Avatar
    saad.waqar007@gmail.com over 5 years later:

    It has been a fine source of information for me in my study. Thanks for your piece of writing it have been very beneficial.

    ” rel=”follow”> psykologhus i Aarhus

  64. Avatar
    psykologhus i Aarhus over 5 years later:

    Every one were at there best, great story and great performance by your team, keep up the good work, it is a great resources for the all members for recruit no doubt.

    ” rel=”follow”> psykologhus i Aarhus

  65. Avatar
    amazon.com/How-To-Plan-Wedding-ebook/dp/B008JFM0UQ/ over 5 years later:

    Thanks for sharing the idea there would be some apprehensions from segment but i am up for it.

Comments