XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] parsing markup with Perl

On Tue, Feb 11, 2014 at 2:29 PM, Shlomi Fish <shlomif@shlomifish.org> wrote:
> Hi Ihe,
>
> thanks for your message.
>

Hello Shlomi

>
> Well, I meant DRY in the extreme sense of making sure your code is free of
> anti-patterns and repetitive things, not necessarily that you have two almost
> identical pieces of code lying around which can be easily extracted into a
> subroutine. Some languages give you more meta-lingual constructs to abstract
> them away, than just subroutines/procedures/functions/etc. up-to the macros of
> the Lisp family of languages.
>
> Here is an example for what I mean. Let's suppose you have these two methods:
>
> method foo(obj)
> {
>         obj.foo1();
>         obj.foo2();
>         obj.foo3();
>
>         return;
> }
>
> method bar(obj)
> {
>         obj.bar1();
>         obj.bar2();
>         obj.bar3();
>
>         return;
> }
>
> (I'm not proposing to call the methods "foo1", "foo2", etc. - they will have
> more meaningful names in production code).
>
> Now arguably, this cascade of method calls is a pattern and "obj." is
> duplicated and you may consider creating a higher-order-method (like higher
> order function) that will accept the names (assuming your language is symbolic)
> or references to methods and generate a new method that will call all these
> methods in succession. E.g:
>
> # [ ... ] is an array constructor
> method foo = make_succession( [ foo1,foo2,foo3 ] );
>
> That's exactly what I did in some object-oriented Perl 5 code, and now I think
> it's pretty evil, because it will make many people (including me) say "WTF?" at
> the code, and it didn't make it much shorter. I won't be surprised if you can
> do something similar in Haskell using meta-Monad operations and you can
> certainly do it in Common Lisp using a macro.
>
> Yet another case is abstracting this cascade of function calls:
>
> function my_func()
> {
>         return foo(bar(baz(quux(bagel())))); # Hope I didn't forget a parens.
> }
>
> These things can be seen quite often in less capable languages and Haskell has
> something to do already.
>
> One can argue that they do not really involve repeating yourself, but they
> still can be abstracted away in higher level and/or more capable languages.
>

(foo o bar o baz o quux o bagel) in SML?

FP and OOP are supposed to be two sides of the same coin but I find
OOP to be more complicated without being more powerful. Because the
instances where OOP is genuinely needed are limited, given the choice
I avoid it - ergo I am and intend to remain blissfully unaware of
pattern literature.

If I am wrong about that (on patterns not on OO being more
complicated) I plead Norvig on most OO design patterns being missing
language features.

>>
>> When you can come back to your code 6 months later and read it without
>> saying WTF you've got it right. I confess I'm not there yet -  more
>> especially with anything that contains a regex.
>
> What are you saying "WTF?" about.

WTF was I thinking when I wrote that.


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS