From: Adam Kellas on
On Mar 2, 1:07 pm, J rgen Exner <jurge...(a)hotmail.com> wrote:
> BTW: $substr is an awful name considering there is a function substr()

Granted, changed.

> and capitalized names ($Variables) normally indicate file handles.

OT I know, but I thought ALLCAPS names indicated file handles (as in
STDOUT) and CamelCase indicated global (or more properly "widely
scoped") variables?

AK
From: Uri Guttman on
>>>>> "AK" == Adam Kellas <adam.kellas(a)gmail.com> writes:

AK> On Mar 2, 8:04�pm, "Uri Guttman" <u...(a)StemSystems.com> wrote:
>> why the strange use of % for a delimiter? it is impossible to
>> read. actually one of the worst choices you can make IMO. besides you
>> don't need to do that as / is fine since you have no / in your regex.

AK> Style ... aesthetics ... religion ... I decided years ago that my
AK> personal style guide would be to always use m%% and s%%%. It may be
AK> ugly but it's consistent; I can always find patterns in my code by
AK> searching for m% or s%. Try that with //! The other problem with // is
AK> that half the time there are slashes in the pattern, and often the
AK> pattern changes in such a way that you either can or have to change
AK> the delimiter. I've never regretted adding this convention to my style
AK> guide, though I'm sure a case could be made for preferring some other
AK> inert character like s,,,.

this isn't religion. there are plenty of religious wars on the net. this
is about quality code. readability matters. it makes your code easier to
understand, maintain, modify, etc. you may think this is cute and your
style but most others don't. someone else posted the same thing. as for
having / in the data, there is no way it is used that often. and regexes
don't usually change on the fly too often. finally the best (and this
comes from damian conway, among many others) alternate delimiter is
{}. it allows nested pairs of {} inside without escaping, it is easy to
see, it doesn't hide the regex itself. and you can even split the two
parts of s{} {} with spaces and it works.


>> � AK> � � for (keys %MakeVars) {
>>
>> use a named variable for loops. it is cleaner and easier to read. $_ can
>> be easily clobbered or some action at a distance can happen. my vars are
>> lexical to the loop and much safer

AK> Use of $_ was deliberate here because I gather it's marginally faster
AK> and I was trying to tune the loop for speed. But in general I agree
AK> that named variables are preferable.

not fast enough to be worth it. we are talking minute speedups and your
code has other issues. readibility and safety easily trump the miniscule
speedup you may get in this case.

>> � AK> � � � �my $name = $MakeVars{$_};
>> � AK> � � � �$text =~ s%$_%$name%g;
>>
>> again with the % delimiter. i would go blind reading that. and there is
>> no need for the temp $name as you can put that hash lookup directly in
>> the replacement string.

AK> Style ... aesthetics ... religion ...

wrong, wronger and wrongest.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: C.DeRykus on
On Mar 2, 8:22 pm, Adam Kellas <adam.kel...(a)gmail.com> wrote:
> On Mar 2, 8:04 pm, "Uri Guttman" <u...(a)StemSystems.com> wrote:
>
> > why the strange use of % for a delimiter? it is impossible to
> > read. actually one of the worst choices you can make IMO. besides you
> > don't need to do that as / is fine since you have no / in your regex.
>
> Style ... aesthetics ... religion ... I decided years ago that my
> personal style guide would be to always use m%% and s%%%. It may be
> ...


You know of course religious threads will go on and on :)

The non-denominational /x switch can help with 's' pattern
readability:

$text =~ s% $_ %$name%gx;

And bracketing delimiters such as (),<>,{},[] can help in
seeing pattern/replacement parts if you're ever tempted to
stray from The True Way:


$test =~ s{ $_ } {$name}gx;

and can even be on multiple lines:

$test =~ s[ really long pattern ]
[some_replacement]gx;

--
Charles DeRykus
From: Adam Kellas on
On Mar 3, 12:12 am, "Uri Guttman" <u...(a)StemSystems.com> wrote:

> this isn't religion. there are plenty of religious wars on the net. this
> is about quality code. readability matters. it makes your code easier to
> understand, maintain, modify, etc. you may think this is cute and your
> style but most others don't. someone else posted the same thing. as for
> having / in the data, there is no way it is used that often. and regexes
> don't usually change on the fly too often. finally the best (and this
> comes from damian conway, among many others) alternate delimiter is
> {}. it allows nested pairs of {} inside without escaping, it is easy to
> see, it doesn't hide the regex itself. and you can even split the two
> parts of s{}  {} with spaces and it works.

I don't consider it cute, I consider it a convention. The value of a
convention or standard is independent of its objective right-ness.
Perhaps if I could go back in time I'd make some different choices,
but wouldn't we all? Though how you can argue that % is ugly while /
is not while explicitly rejecting the notion that it's an aesthetic
disagreement - and that "quality code" belongs to your side - is
beyond me. You might as well argue that yellow is uglier than blue.

I don't object to this line of discussion though. Perhaps you will
save some naive young person from the horrors of addiction to percent
signs. For me it's 15 years and thousands of lines of maintained code
too late.

>   AK> Use of $_ was deliberate here because I gather it's marginally faster
>   AK> and I was trying to tune the loop for speed. But in general I agree
>   AK> that named variables are preferable.
>
> not fast enough to be worth it. we are talking minute speedups and your
> code has other issues. readibility and safety easily trump the miniscule
> speedup you may get in this case.

Really, we have no disagreement here. It's just that when one is
trying desperately to speed something up it's reasonable to try
everything you know of. What I posted was not a published, supported
piece of code, it was the result of a tuning exercise.

AK
From: Uri Guttman on
>>>>> "AK" == Adam Kellas <adam.kellas(a)gmail.com> writes:

AK> On Mar 3, 12:12�am, "Uri Guttman" <u...(a)StemSystems.com> wrote:
>> this isn't religion. there are plenty of religious wars on the net. this
>> is about quality code. readability matters. it makes your code easier to
>> understand, maintain, modify, etc. you may think this is cute and your
>> style but most others don't. someone else posted the same thing. as for
>> having / in the data, there is no way it is used that often. and regexes
>> don't usually change on the fly too often. finally the best (and this
>> comes from damian conway, among many others) alternate delimiter is
>> {}. it allows nested pairs of {} inside without escaping, it is easy to
>> see, it doesn't hide the regex itself. and you can even split the two
>> parts of s{} �{} with spaces and it works.

AK> I don't consider it cute, I consider it a convention. The value of a
AK> convention or standard is independent of its objective right-ness.
AK> Perhaps if I could go back in time I'd make some different choices,
AK> but wouldn't we all? Though how you can argue that % is ugly while /
AK> is not while explicitly rejecting the notion that it's an aesthetic
AK> disagreement - and that "quality code" belongs to your side - is
AK> beyond me. You might as well argue that yellow is uglier than blue.

but convention implies many people doing it. you are the only one i have
ever seen (and i see tons of code) using % for a delimiter. so you are
not conventional but instead out of the norm. it is your convention and
others find it hard to read. you write code for others, not
yourself. get over yourself with this. you are wrong in conventional
ways.

AK> I don't object to this line of discussion though. Perhaps you will
AK> save some naive young person from the horrors of addiction to percent
AK> signs. For me it's 15 years and thousands of lines of maintained code
AK> too late.

you can always change style. i have many times over my career as i learn
better ways to code.

>> � AK> Use of $_ was deliberate here because I gather it's marginally faster
>> � AK> and I was trying to tune the loop for speed. But in general I agree
>> � AK> that named variables are preferable.
>>
>> not fast enough to be worth it. we are talking minute speedups and your
>> code has other issues. readibility and safety easily trump the miniscule
>> speedup you may get in this case.

AK> Really, we have no disagreement here. It's just that when one is
AK> trying desperately to speed something up it's reasonable to try
AK> everything you know of. What I posted was not a published, supported
AK> piece of code, it was the result of a tuning exercise.

desperation is not a reason to try everything under the sun for
speedups. just applying the benchmark module is a saner way to find out
what is actually faster and by how much.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------