Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: K&R2, exercise 5-4, strend(s,t) |
| Date | 2011-06-28 16:03 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <kfnvcvp8son.fsf@x-alumni2.alumni.caltech.edu> (permalink) |
| References | (1 earlier) <itvds4$nr9$1@dont-email.me> <kfnoc1lalgf.fsf@x-alumni2.alumni.caltech.edu> <iu9dn8$onq$1@dont-email.me> <kfnoc1j85vd.fsf@x-alumni2.alumni.caltech.edu> <iubv9c$42i$1@dont-email.me> |
Mark Bluemel <mark_bluemel@pobox.com> writes:
> On 06/27/2011 07:51 PM, Tim Rentsch wrote:
>> Mark Bluemel<mark_bluemel@pobox.com> writes:
>>
>>> On 06/25/2011 06:07 PM, Tim Rentsch wrote:
>>>
>>>> An alternative offered for everyone's reading pleasure
>>>> and/or amusement (as each may individually determine).
>>>>
>>>>
>>>> /* Return 1 if 'tail' occurs at the end of 'whole', or 0 if not. */
>>>>
>>>> int
>>>> strend( const char *whole, const char *tail ){
>>>> size_t w, t;
>>>>
>>>> return
>>>> whole&& tail
>>>> && (w = strlen( whole ))>= (t = strlen( tail ))
>>>> && strcmp( whole+w -t, tail ) == 0
>>>> ;
>>>> }
>>>
>>> Now if you'd used 'lo1' for "whole", "l0l" for "tail", "lol" for "w"
>>> and "l01" for "t", it would have been even more perfect...
>>
>> Personally I think the single character identifiers do just fine
>> here, considering the length of the function, and their obvious
>> relationship to identifiers 'whole' and 'tail'. But if you think
>> longer variable names would be helpful, by all means feel free.
>>
>> If there are some other reservations or objections, please do
>> the group a favor and try to articulate what they are and why.
>
> No objections or reservations. My posting was decidedly facetious.
Oh okay. I missed the intended tone then.
> I very much like your solution, but it's terseness somehow made me
> think of the IOCC and hence led me to suggest some obvious
> obfuscations.
I know some people think code being terse automatically makes
it obfuscated, but I don't share that opinion. Writing code
compactly sometimes gives good code and sometimes bad, depending
on the particulars. I do think that some aesthetic judgment
is required: choices that work well in short functions often
fall down in longer functions, and vice versa. Being exposed
to different styles is IMO a benefit, and that's a large part
of why I posted this alternative.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
K&R2, exercise 5-4, strend(s,t) arnuld <sunrise@invalid.address> - 2011-06-23 10:56 +0000
Re: K&R2, exercise 5-4, strend(s,t) Ian Collins <ian-news@hotmail.com> - 2011-06-23 23:03 +1200
Re: K&R2, exercise 5-4, strend(s,t) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-06-23 13:28 +0100
Re: K&R2, exercise 5-4, strend(s,t) Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-23 14:08 +0100
Re: K&R2, exercise 5-4, strend(s,t) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-06-24 02:22 +0300
Re: K&R2, exercise 5-4, strend(s,t) Gene <gene.ressler@gmail.com> - 2011-06-23 18:14 -0700
Re: K&R2, exercise 5-4, strend(s,t) Ike Naar <ike@sverige.freeshell.org> - 2011-06-24 06:18 +0000
Re: K&R2, exercise 5-4, strend(s,t) Ike Naar <ike@sverige.freeshell.org> - 2011-06-24 06:58 +0000
Re: K&R2, exercise 5-4, strend(s,t) Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-25 10:07 -0700
Re: K&R2, exercise 5-4, strend(s,t) arnuld <sunrise@invalid.address> - 2011-06-27 08:02 +0000
Re: K&R2, exercise 5-4, strend(s,t) Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-27 10:13 +0100
Re: K&R2, exercise 5-4, strend(s,t) Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-27 11:54 -0700
Re: K&R2, exercise 5-4, strend(s,t) Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-27 09:07 +0100
Re: K&R2, exercise 5-4, strend(s,t) Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-27 11:51 -0700
Re: K&R2, exercise 5-4, strend(s,t) Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-28 08:19 +0100
Re: K&R2, exercise 5-4, strend(s,t) Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-28 16:03 -0700
csiph-web