[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: parsing markup with Perl

  • From: Ihe Onwuka <ihe.onwuka@gmail.com>
  • To: Shlomi Fish <shlomif@shlomifish.org>
  • Date: Tue, 11 Feb 2014 14:56:45 +0000

Re:  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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.