comp.lang.ada
 help / color / mirror / Atom feed
From: "Arkady V.Belousov" <ark@belous.munic.msk.su>
Subject: Re: What's the best language to learn? [was Re: Should I learn C
Date: 1996/08/27
Date: 1996-08-27T00:00:00+00:00	[thread overview]
Message-ID: <AF_cdvr0BL@belous.munic.msk.su> (raw)
In-Reply-To: ACFVZuraG3@belous.munic.msk.su

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3204 bytes --]


Hello!

On 21-Aug-96 03:42 in <01bb8f12$6dbb5f00$32ee6fce@timhome2>
Tim Behrendsen (tim@airshields.com) wrote:
 > Szu-Wen Huang <huang@mnsinc.com> wrote in article
 > <4vdnod$5i8@news1.mnsinc.com>...
 > > Mark Wooding (mdw@excessus.demon.co.uk) wrote:

 > > :  char buf[...];
 > > :  char *p;
 > > :  ...
 > > :  while (buf[0]==' ')
 > > :  {
 > > :    for (p=buf;p[0]=p[1];p++)
 > > :      ;
 > > :  }
 > > :  while (buf[strlen(buf)-1]==' ')
 > > :    buf[strlen(buf)-1]=0
[]
 > > : Anyone who asks `what's wrong with that' will be shot.
 > > This code works, by the way, as far as I can tell.  It's even portable.
                                                              ^^^^^^^^^^^^^
 > > I suggest you show us somebody with equivalent experience in general
 > > computing as this individual but started on assembly language and see how
 > > this person fares with the problem.  Oh, and give them the same amount
 > > of time.
 > You're missing the point.  The point is how can *anyone* commit such
 > a monument to inefficient coding?  Yet, someone did.  That someone
 > obviously sees four lines of code, and therefore it must be OK.
 > Now, if that someone had an assembly background, and could see how
 > these statements were going to compile, they would instantly feel
 > the horror that a good and moral programmer should feel over this
 > code.

     Yes! Your words are balm for me.

______________O\_/_________________________________\_/O______________
// strrnspn like strspn scan a string for a segment that is a subset of
// a set of characters, but they reverse starting at specified position
// This code tested and optimized
size_t strrnspn(const char src[], const char sp[], size_t n){
        size_t pos = n;
        while(pos--){
                register char ch = src[pos];
                for(const char *ss = sp; *ss && *ss != ch; ss++);
                if(*ss != ch) break;
        }
        return (n - pos - 1);
}

// Remove border segments, which contain only characters from specified set
// This code not tested
void trim(char s[], const char sp[] = " \t"){
        size_t len = strlen(s);
        len -= strrnspn(s, sp, len);    // Remove "right" (last) border
        size_t cut = strspn(s, sp);
        memmove(s[0], s[cut], len -= cut); // Remove "left" border
        s[len] = '\0';                  // Terminate resulting string
}
_____________________________________________________________________
              O/~\                                 /~\O

     This code something more complicated, but they also "even portable" and
MUCH!!!! more efficient. (BTW. I think, first mentioned approach and codes
are used in the Borland and Microsoft judging by they products). %~(

P.S. Not much, but my (not showed there) trim function is more efficiency,
because they manipulate on instance of String class, which know they length.

 * When we hear - Jump, we ask - How far?
--
                Best regards! Sincerely yours, ������ ���������.
       ����̣���� ���� �������� ��������, � ���������� ������ ����������.





       reply	other threads:[~1996-08-27  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ACFVZuraG3@belous.munic.msk.su>
1996-08-27  0:00 ` Arkady V.Belousov [this message]
1996-08-27  0:00   ` Levels of abstraction (was Re: What's the best language to learn?) Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox