From: Thomas 'PointedEars' Lahn on
Alex Shabanov wrote:

> Thomas 'PointedEars' Lahn wrote:
>> I still do not see the problem this is supposed to solve; except perhaps
>> extensive method overloading, which is inherently flawed and so should be
>> designed out of an API to begin with.
>
> This is exactly the case I dealt with.

So you worked around a problem by creating a lot of other problems.
That does not sound like a viable strategy to me.

> I needed to write a sort of print function that takes one parameter
> and prints it in a way that depends on type and structure of the
> object given. E.g. strings shall be printed as is, objects with expr
> and value properties shall be represented as two differently colored
> elements, the object with snippet property shall be represented within
> an expandable element, etc.

Unless host objects are involved, in which case this function should never
be exposed to them, this problem is much better solved with polymorphism.

> Of course, most of the real life problems are trivial and can be best
> expressed with just built-in means but not all of them.

ISTM this one can.

> It is funny - I never ever needed to use regular expressions during my
> professional career though I wrote literally hundreds of them in
> academic years.
> I wouldn't say that regular expressions are useless but I've just
> never encountered a task that'd require them.

Chances are that you are doing something wrong, then.

Please trim your quotes to the relevant minimum, do not quote signatures.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
From: nick on
On May 14, 3:29 pm, Alex Shabanov <avshaba...(a)gmail.com> wrote:

> It is funny - I never ever needed to use regular expressions during my
> professional career though I wrote literally hundreds of them in
> academic years.

That's quite a statement! Maybe you haven't been doing anything that
requires processing text, or you've using them without really noticing
it?

I probably use at /least/ one regex a day for work or just everyday
stuff... Think how often tools like grep and sed come in handy, even
for non-programming related tasks? I'm sure I type "grep" at least
once a day, and I use sed or similar techniques fairly often when
refactoring code.

> I wouldn't say that regular expressions are useless but I've just
> never encountered a task that'd require them.

I can think of a few useful real-world applications off the top of my
head...

- For scanners / parsers (think syntax highlighting)
- For URL rewriting (mod_rewrite and co.)
- For input validation (that's not a valid email address!)
- For text munging (e.g. find a URL in a block of text, create a
hyperlink)

Seems to me regex is the way to go when you need to search/filter/
replace text in all but the simplest cases. I'm curious how you've
managed to avoid them so thoroughly in your professional career? ;)
From: Alex Shabanov on
On May 14, 11:49 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> ...
> So you worked around a problem by creating a lot of other problems.
> That does not sound like a viable strategy to me.
> ...
> ISTM this one can.

Could you please clarify what strategy is acceptable from your point
of view?
To introduce lots of if+typeof+in?
Too error prone, from my point of view.
From: Alex Shabanov on
On May 15, 2:39 am, nick <nick...(a)fastmail.fm> wrote:
> ...
> Seems to me regex is the way to go when you need to search/filter/
> replace text in all but the simplest cases. I'm curious how you've
> managed to avoid them so thoroughly in your professional career? ;)

Well, I'm surprised too :)
I'm not alone who writes code so text filtering tasks always assigned
to solve to someone else.
And yes, I wrote regex for grep and sed though I didn't take them into
an account :)
From: Thomas 'PointedEars' Lahn on
Alex Shabanov wrote:

> Thomas 'PointedEars' Lahn wrote:
>> So you worked around a problem by creating a lot of other problems.
>> That does not sound like a viable strategy to me.
>> ...
>> ISTM this one can.

Trimming quotes means to trim the quotes you are not referring to, and to
summarize, if necessary, those which you are referring to. It does not mean
to completely destroy the context of a quotation.

<http://jibbering.com/faq/#posting> pp.

> Could you please clarify what strategy is acceptable from your point
> of view?

AISB, polymorphism, unless host objects are involved. Let the (values
converted into) objects have a method with the same name that does the
serialization.

> To introduce lots of if+typeof+in?

No.

> Too error prone, from my point of view.

As for error-proneness, your approach beats almost everything else by
inches.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)