[DUG] Why re-use when you can duplicate!

Jeremy North jeremy.north at gmail.com
Mon Jun 4 13:57:09 NZST 2012


Most comments are stripped.

On Mon, Jun 4, 2012 at 11:52 AM, David Brennan
<dugdavid at dbsolutions.co.nz>wrote:

> I thought similarly but was too busy to reply.****
>
> ** **
>
> As the developers of the core library used by everyone one of
> Embarcadero’s goals is to keep the code efficient. Thus they have somewhat
> legitimate reasons to duplicate code so long as there are benefits and they
> avoid the corresponding downsides of code duplication, in particular
> divergence in different copies of the same code. Of course given the
> difference in the GetUnicodeCategory calls (as also pointed out by Jolyon)
> one has to wonder if the code hasn’t already diverged! But there could be a
> good reason for the copies being different too...****
>
> ** **
>
> One would also hope both copies of the routine were commented to point out
> there were two versions and the reason why – does anyone know if
> Embarcadero’s comments get stripped before the source goes out to us or do
> they just not comment their code? ;-)****
>
> ** **
>
> David.****
>
> ** **
>
> *From:* delphi-bounces at listserver.123.net.nz [mailto:
> delphi-bounces at listserver.123.net.nz] *On Behalf Of *Jolyon Smith
> *Sent:* Sunday, 3 June 2012 9:03 p.m.
> *To:* todd.martin.nz at gmail.com; NZ Borland Developers Group - Delphi List
> *Subject:* Re: [DUG] Why re-use when you can duplicate!****
>
> ** **
>
> Arguably it's an optimisation.  This isn't code that is likely to change
> and incurring an additional function call for such a small snippet of code
> for the kind of processing such checks might be involved in could be a
> significant overhead.****
>
> ** **
>
> They could have "inline"d it I guess, but there are all sorts of things
> that seem to break inlining in Delphi (as in "cause to be rejected by the
> compiler") and this might fall foul of those.****
>
> ** **
>
> Another explanation (perhaps also optimisation related) might lie in the
> fact that it isn't a perfect duplication... note the slight differences in
> the call that the first makes to INTERNALGetUnicodeCategory(UCS4Char),
> whilst the second uses GetUnicodeCategory(String, Index).  Then again, this
> might also be a sub-optimal variation.  Hard to say without probing deeper
> than is warranted at this point.
>
> :)****
>
> ** **
>
> On 3 June 2012 12:15, Todd <todd.martin.nz at gmail.com> wrote:****
>
> Is this a representative example of the code quality Embarcadero is
> producing today?
>
> class function TCharacter.IsNumber(C: Char): Boolean;
> begin
>  if not IsLatin1(C) then
>    Result := CheckNumber(InternalGetUnicodeCategory(UCS4Char(C)))
>  else if not IsAscii(C) then
>    Result := CheckNumber(InternalGetLatin1Category(C))
>  else
>    Result := (C >= '0') and (C <= '9');
> end;
>
> class function TCharacter.IsNumber(const S: string; Index: Integer):
> Boolean;
> var
>  C: Char;
> begin
>  CheckStringRange(S, Index);
>  C := S[Index];
>  if not IsLatin1(C) then
>    Result := CheckNumber(GetUnicodeCategory(S, Index))
>  else if not IsAscii(C) then
>    Result := CheckNumber(InternalGetLatin1Category(C))
>  else
>    Result := (C >= '0') and (C <= '9');
> end;
>
> Todd.
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at listserver.123.net.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
> Subject: unsubscribe****
>
> ** **
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at listserver.123.net.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
> Subject: unsubscribe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20120604/00535d5d/attachment.html 


More information about the Delphi mailing list