(One of) Perl's mottos is, There's More Than One Way To Do It.

An often fruitful brainstorming technique is to look at some attribute, assert the opposite, and then stress it to an extreme.

As a thought experiment in language design, consider a highly structured language in which There Are Few Ways To Do It, or even There Is Exactly One Way To Do It, TIEOWTTI.

I have some ideas, but I would like to hear others before contaminating yours. This is not a troll or a homework. I'm thinking about what are the benefits and costs of languages with complicated syntaxes versus other sorts of languages.

Assume there exist perfect tools which compile to perfect do-what-I-mean code, regardless of syntax.

- Mitch

Replies are listed 'Best First'.
Re: TIEOWTTI
by Ovid (Cardinal) on Apr 15, 2002 at 20:27 UTC

    The difference between the "one way" and "multiple ways" is often a matter of the power behind the language. From what I have seen, languages that boast "one way" tend to be easier to learn and are often a better environment for programmers of low to medium skill. However, advanced programmers often get frustrated when encountering an implementation obstacle generated by the "one way" paradigm.

    With Perl, "multiple ways" tend to offer much more power and flexibility, but at the cost of added danger. From what I have seen, programmers need to have a higher skill level to tackle tough projects in Perl, but the reward is fewer obstacles.

    For example, I've never seen an AUTOLOAD type of functionality in Java. I can't do multiple inheritance if I think I need to. I can't do closures with Python. Most of the time, we shouldn't be allowed to even dream of doing some of those things, but if we need to, it's nice to know that we can.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      The difference between the "one way" and "multiple ways" is often a matter of the power behind the language. From what I have seen, languages that boast "one way" tend to be easier to learn and are often a better environment for programmers of low to medium skill. However, advanced programmers often get frustrated when encountering an implementation obstacle generated by the "one way" paradigm.

      While I fully adhere to the There Is More Than One Way To Do It philosophy of Perl, I do have some experience which marks a more concrete benefit of the There Is Exactly One Way To Do It. While a more structured language may be easier to learn, more importantly (I think) it offers benefits in automatic/compile-time optimization.

      While in college, I took a high performance computing class where we learned all manner of ways to exploit architectural differences in various platforms as well as ways to exploit code structures to gain an increasing number of performance enhancements from particular pieces of code. We did most of our work in C and would use all the compile time options for optimizing compililation that the compiler offered. Generally we got pretty good results. However, when the problem was rewritten in Fortran using the same techniques and compile time options, it was much much faster. The reason being that Fortran's data typing and control structures require that they are strictly adhered to. Because of there being exactly one way to do it, the compiler can make optomizing assumptions that it just can't do in C (having to cover all of its potential bases).

      I love Perl and I think its benefits outwiegh any problems. In fact, I am happy with its performance, finding it to be a lot faster than I expected. It just seems that TIMTOWTDI may hamper its ultimate performance.

      On the other hand, writing a C program that can do the same complex manipulations that the average Perl program does can be very time consuming. Seen in that light, Perl gains its optimization benefits on the front end of a project.

      Then again, I could be wrong -- cascadefx

Re: TIEOWTTI
by tachyon (Chancellor) on Apr 15, 2002 at 21:27 UTC

    Perl is like rope and what a long rope it gives you. Like rope you can use it to tie things together or.....hang yourself so you can die horribly. Is rope inherently evil? Inherently good? Useful? Dangerous? Is it easy to learn the ropes? Should rope be kept out of the hands of children and minors?

    compile to perfect do-what-I-mean code

    No computer does what you mean. Computers are dumb as a box of hammers and do exactly what you say, no matter what the language (unless there are bugs in the compiler in which case they generally core dump :-)

    See Also

    SNAFU-principle
    KISS-Principle
    Zero-One-Infinity-Rule

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: TIEOWTTI
by tadman (Prior) on Apr 15, 2002 at 22:37 UTC
    To use a metaphor: A programming language is like a toolbox. Inside it are many different tools you can use to get the job done. Some languages choose to have but a single hammer. Perhaps it is a small hammer good for hanging pictures, or a very large hammer good for removing derelict office buildings, or a hammer that is precisely the right size for most of the jobs you are likely to encounter.

    By the same analogy, Perl gives you about five hammers of varying size, from small to large, some easy to hold and comfortable for long periods of use, while others are big and heavy and tricky to use properly. There are even a few things that can work like a hammer, either in a pinch, or by design. On top of that there are things that do hammering quite well but aren't even hammers. There are even things that can be made to hammer, even though they aren't supposed to and people are often shocked that they can.

    So where a normal toolbox would have the usual implements, Perl seems to throw in some tools that can't be described in terms of regular tools. There are some "Swiss Army" type tools, and there are some very specific tools for that rare occasion when you need them, but when you do, you'll be glad that they're there.

    The great thing about TMTOWTDI is that you can choose which way you want To Do It. Maybe you're only used to working with hammers and screwdrivers and the other things frighten you, which is certainly likely given some of the truly abstract tools found in Perl. Nothing forces you to use all the other ways, of course, excepting the natural urge to explore, and perhaps a good dose of Laziness, Impatience or Hubris.

    If anything, Perl could stand to have a few more things thrown in for good measure. With Perl 6 I'm sure there will be a lot of new toys in the toolbox, and Even More Ways To Do It.
Re: TIEOWTTI
by brianarn (Chaplain) on Apr 15, 2002 at 21:41 UTC
    One of the things that impressed me the most when I came to know Perl was the fact that TIMTOWDTI. I'd recently been forced to write a 2000+ line web application in ADP (think ASP but using TCL instead of VB, ADP is part of the AOLserver offered at http://www.aolserver.com).

    This was utterly disgusting to have to do, as I didn't know TCL at all and had to learn the language. The company I worked for was really big on TCL, even though I wanted to use any other language, like Perl or PHP.

    After learning TCL and then learning Perl (which by no means am I done doing, there's still SO much to learn), I've noticed that TCL was much more simplistic. It wasn't exactly TIEOWTTI, but TAFWTDI (there are few ways to do it). In that sense, it was much more straightforward for a new coder.

    I later discovered that this simplicity in TCL was why the company chose it over a language with more ways to do it (and hang yourself doing it). The code that I was working on would be put into production, and I'd be moved onto another project, another site, whatever - and someone would come along later to maintain it.

    I'm not saying that someone else's Perl is necessarily less maintainable than someone's TCL code, but to be honest, it seems that languages with fewer ways to do things are good for cases where multiple people will be maintaining the code over the span of some years.

    Just a few thoughts as to why fewer ways are sometimes nicer.

    ~Brian
Re: TIEOWTTI
by grinder (Bishop) on Apr 16, 2002 at 10:01 UTC
    The only other language I use these days apart from Perl on a fairly regular basis is Visual Basic. It's very much a TIETOWTDI language. The debugging environment is pretty nice though, you can edit your code in the debugger while the program is running, which can come in handy.

    What is difficult is mapping your problem domain to the language. I often find myself wanting to attack a problem in a certain way, and after frustrating myself for an hour or two, come to the conclusion that it's not possible, so I have to throw away the code and start off on a different tack. It comes down to second-guessing the language designer, thinking how they thought, trying and come up with an approach that will fit in with the language.

    In this sense, it's a much more constraining experience. You're not actually expressing yourself, you're just trying to get a job completed by trying to slot your square pegs into the language's round holes.

    Another aspect of this debate is orthogonality. The word gets bandied about a lot, and I'm not sure everyone agrees on what it means, I'm not sure I even understand it myself. But what it means for me is that something you pick up in one corner of the language can successfully be applied to another part of the language... and it will work! Perl excels at this sort of thing, like the notion of the last expression in a block is returned, and lazy evaluation and what not.

    Visual Basic is an utterly unorthogonal language. It has a sort of object dot notation syntax, so you can say

    a = obj.foo.bar.blot(22)

    ... but, in some instances, that doesn't work. For reasons that escape me (no doubt due to the evolution of the language over the years (god only knows what the parser source looks like)), you come across strange cases, where you have to do something like

    dim otmp as some_obj otmp = obj.foo.bar a = otmp.blot(22)

    And that is the only way to do it! Okay, it's a bit of a pathological case, but I think you get the picture. Languages that let you do the same thing in different ways by definition tend to stay out of your way, so that you can concentrate on the task, and not have to keep adjusting to the tool.

    update: missing "from" noted by tye. Thanks :)
    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
Re: TIEOWTTI
by stephen (Priest) on Apr 15, 2002 at 21:10 UTC
    In stranger moments, I've considered an XML programming language:
    <program main="print_hello"> <routine name="print_hello"> <print>hello</print> </routine> </program>

    Of course, this isn't TOO different from XSLT, just a change in emphasis really. But still, practically any human-usable language will have MTOWTDI. We are creatures of ambiguity.

    stephen

Re: TIEOWTTI
by Sweeper (Pilgrim) on Apr 16, 2002 at 05:44 UTC
    Consider biology: there is more than one way to build living creatures. And if a catastrophe occurs (the Cambrian catastrophe and the extinction of dinosaurs), still some living creatures continue to live and prosper.

    Consider societies: which societies are the most prosperous? Societies with a single political party or societies with More Than One Way To Think?

Re: TIEOWTTI
by BUU (Prior) on Apr 15, 2002 at 21:26 UTC
    Well sure, tieowtti would be fine if there was only one programmer, and he wrote the language. Bottom line = no two people think the same. Thus user 1's 'paradign' != user 2's 'paradign'