On Fri, 16 Jun 2006 14:00:42 +0300
ik <[EMAIL PROTECTED]> wrote:

>[...]
> > >>>> 7. Build in regex syntax like in Perl, Ruby Javascript.
> > >>>
> > >>> Replace it, by a library.
> > >>
> > >> Why ?!
> > >>  S := 'We are programming in Perl';
> > >>  S :=~ s/Perl/Pascal/s;
> > >>
> > >> Doesn't it nicer then to use something like:
> > >>
> > >> S := 'We are programming in Python';
> > >> Regex := TRegex.Create;
> > >> Regex.compile ('Python',S);
> > >> S := Regex.Replace ('Pascal', 's');
> > >>
> > >> Sure it's cool to use external functions, but it's useful to use it
> > >as > a syntax structure :)
> > >
> > > See ideintf/texttools.pas. Then the above would be
> > >
> > >  S := 'We are programming in Perl';
> > >  S := REReplace(S,'Perl','Pascal','s');
> > >
> > > IMHO this is better to read and better to understand for newbies, than
> > > the short but cryptic perl syntax.
> 
> So newbies does not need to use regex until they fully understand the
> way of using it...
> Personally I still find new things and ways in regex all of the time.
> How can I do the following with REReplace :
> 
> s/[^a-z]//gs;
> s/(dog|cat|parrot)/animole/g;
> s/<abc>(.*?)<\/abc>/$1/g;

The REReplace uses perl syntax for regular expressions:

  REReplace(S,'[^a-z]','',false,'gs');
  REReplace(S,'(dog|cat|parrot)','animole',false,'g');
  REReplace(S,'<abc>(.*?)</abc>','$1',true,'g');

 
> and the list of examples goes on and on ...

The only missing things are other charactersets like UTF-8 and some special
perl goodies.


> > Exactly.
> >
> 
> 
> >No way. Why completely change the pascal OO semantics for doing
> >something that can be done already in other ways and that can be done
> >on enviroments that was really meant for it (i.e. JavaScript) ?
> >Are You just fancy using 'begin..end' ? ;-)
> 
> >Almost all suggestions in this thread (and the previous one) reinforce
> >my opinion on why many people dislike Pascal: they are lazy bastards!
> >Most of my colleagues which prefer C++ or Java over Delphi complain
> >that in Pascal you have to write too much, but they don't accept that
> >this is straight laziness. But at last, last week a new guy in my
> >workplace cited as the first reason for him to adore C++ was it is a
> >nice language for lazy programmers/typers.
> >Obviously these guys don't care about code readability (not news) and
> >never had to care about code maintanability :-/ (I presume they don't
> >like to code at all =P )
> >>I have to admit that doing more typing probably must feel to some like
> >unnecessary and unneffective, but I absolutely positively doubt anyone
> >can be more productive in C++ or Java than in Object Pascal (or in
> >VisualStudio, Eclipse or JDeveloper than in Lazarus or Delphi).
> 
> Well a rule of thombs claims that the more code you are writing the
> more bugs you add to your program.
> 
> Personally I think that most of what I wrote was in order to add me
> more tools to need to invest more in the program I need to write and
> less on the tools to write such program.
> 
> Don't mix the need for tools with laziness, many programming languages
> such as Perl does not add support for functions such as "trim" because
> the idea is that you can write a regex that will do it, alto many
> times you need to repeat it, so at the end you will find 100 copies of
> "trim" like functions on many projects that where written in Perl.
> 
> You can write every repeated code on the place you need it, but you
> really need the time to do other things, you'll use a
> function/procedure to store such actions and you will call that
> function... it's not because you are lazzy, it's because you know it's
> the best way to use this functionallity..

Regular expressions are great for simple text conversions. I use them very
often, except when I need speed.
Under Perl you can create a Trim function easily, but because Perl's regex
are faster compared to other operations, your choice will be nearly always
to use a regex. This is not true for FPC. Here you can easily beat regular
expressions in speed and memory.

If you prefer some features of Perl (or any scripting language), then why
don't you create a unit with functions for your preferred operations? Add
regex, assoc. arrays, sort functions and the system function and you can
write small pascal programs as dirty and quick as perl. Your program will
still be easier to read, extend and maintain. 
I'm planning to write such a unit and write a wiki page or small article for
perl users.
 
>[...]


Mattias

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to