Re: <ctype.h> toLower()
From: Gavin Deane (deane_gavin_at_hotmail.com)
Date: 11/28/03
- Next message: Sean Ward: "help with a simple prob"
- Previous message: tom_usenet: "Re: What a translation unit is."
- In reply to: ellie fant: "Re: <ctype.h> toLower()"
- Next in thread: ellie fant: "Re: <ctype.h> toLower()"
- Reply: ellie fant: "Re: <ctype.h> toLower()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Nov 2003 05:20:49 -0800
"ellie fant" <pcrcutitout1000011@uko2.co.uk> wrote in message news:<1069977836.749494@news.minx.net.uk>...
> "Richard Heathfield" <invalid@address.co.uk.invalid> wrote in message
> news:3fc66297@news2.power.net.uk...
> > ellie fant wrote:
<snip>
> > > however this newsgroup is about
> > > learning the language and if we want to discuss our own implementations
> in
> > > an effort to understand the language better then we are allowed to.
> >
> > Of course, provided we don't try to recommend that other people use our
> > implementations in preference to existing, standard, portable solutions if
> > those solutions do in fact exist.
>
> We are here do discuss and learn the language and you recommend that the
> best way to do this is to always use library functions and to always write
> portable source code.
> Your the one who is trying to recommend what to use.
C and C++ are platform independent languages. Arguably, any code that
assumes an implementation detail like ASCII (ie any non-portable code)
is off-topic. If someone posts a question with code that assumes ASCII
it is appropriate to point out the non-portable nature of their code.
If someone posts a response with code that assumes ASCII it is
appropriate to point it out then too.
<snip>
> I didn't intend to create a fully implemented replacement for tolower, the
> code was only intended to handle uppercase letters.
> So you are obviously misinterpretating the intent of my posting in some way.
Your intent was clear. You stated that your code was not guaranteed to
work on non-ASCII character sets. What was initially questioned was
the validity of your intent within the context of this group. And its
relevance to the question.
The OP was not trying to learn how to do low level character
manipulation, so your argument about reimplementing library features
as a learning exercise does not apply. Suggesting rolling your own
version of a standard library function (even if you replicate _all_
the functionality) as anything other than a learning exercise is not
appropriate.
The question was how to use tolower, which is not ASCII-specific, and
you gave an ASCII-specific solution. Not helpful.
And your design was poor. You built in a huge restriction and, worse,
you failed to document that fact. Any user would be surprised to find
that a function for changing letters to lower case munges the '@'
character when they put their email address in. Sometimes it is
necessary to have such unexpected limitations (this is not such a
time). But whenever you do, that limitation must be documented.
In a commercial environment, there will be senior programmers around
to show you the light (for a first offence) or kick you out the door
(if you ever do it again). The point of posting in a learning
newsgroup is to achieve the same thing for the OP. Any solutions
posted are reviewed and mistakes are picked up. If you post a solution
you _must_ either not make this kind of mistake, or be prepared to
accept criticism when you do.
> > > If I wanted to discuss a string class in an effort to understand
> character
> > > arrays better , this cannot be dismissed as rubbish and non portable
> > > because there is a std string class which is better.
> >
> > In fact, there are quite a few things wrong with the string class (IMHO).
> > Who was managing /that/ project?
> >
>
> The point I was making is that there is more viewpoints and lots of
> noteworthy points about using strings which will not be covered when you
> simply use the std::string class.
> i.e: A person might be designing there own string class in an effort to
> learn more about the language and to simply dismiss it and say there are
> easier ways to do it is incorrect because it defeats the purpose of that
> persons discussion.
> You can't call the persons code 'flawed' because there is an easier way to
> do it. It simply points out that you do not understand the intent of the
> users code which in this example would be to aid his learning.
If someone says "I want to understand linked lists so I'm implementing
one, can you help me with what I've written so far?", they will get
lots of help. If someone says "I am trying to do xyz and I am storing
my data in a linked list. Can you help with this error?" and they are
using a list type other than std::list they will get a different
respose. They will get help with their problem and will also be
introduced to std::list.
Rolling your own version as a learning exercise is valuable. But once
you've done that, every time you use it is a missed opportunity to
gain familiarity with the standard library.
<snip>
> Here is a scenario:
> If someone posted a message that read something like:
> I have some code here it only works on ASCII platforms
> .... some code.
> What would you think of a person who would reply to such a post with
> something like this:
> The code you posted is wrong because it is not portable across non
> ASCII platforms.
>
> You'd think person who replied to this post is either a non english speaker,
> a joker, a complete idiot, an unreasonably ignorant sod or he doesn't have a
> brain.
A one-line response like that would be unhelpful. Fortunately, most
people are more helpful than that. Much better would be:
"Do you have a compelling reason to assume ASCII? If so please tell us
what it is (it might not be as compelling as you think). For now, look
how the standard library can help you do what you need without
building in unnecessary assumptions". Followed by the code rewritten
to take advantage of the library.
-- GJD
- Next message: Sean Ward: "help with a simple prob"
- Previous message: tom_usenet: "Re: What a translation unit is."
- In reply to: ellie fant: "Re: <ctype.h> toLower()"
- Next in thread: ellie fant: "Re: <ctype.h> toLower()"
- Reply: ellie fant: "Re: <ctype.h> toLower()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|