C (functional programming) VS C++ (object oriented programming)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charlie Gordon

    #31
    Re: C (functional programming) VS C++ (object oriented programming)

    "Richard Heathfield" <rjh@see.sig.in valida écrit dans le message de news:
    NNWdnU-UbpD7HZ_aRVnyig A@bt.com...
    Ben Pfaff said:
    >
    <snip>
    >
    >There is occasionally a good reason to use strncpy().
    >
    Right. I'm aware of the issues that are raised by misuse of strncpy - but
    hey, any function can be misused. That doesn't necessarily make it a bad
    function.
    You are right, it is a matter of statistics. strncpy happens to be misused
    a lot, causing various kinds of inefficiencies or downright bugs that lurk
    in the dark corners of the code, waiting to bite at the least agreeable
    moment.

    Just don't use this stinking function, use strlcpy or equivalent instead,
    when appropriate.

    --
    Chqrlie.


    Comment

    • Malcolm McLean

      #32
      Re: C (functional programming) VS C++ (object oriented programming)


      "Charlie Gordon" <news@chqrlie.o rgwrote in message
      >
      You are right, it is a matter of statistics. strncpy happens to be
      misused a lot, causing various kinds of inefficiencies or downright bugs
      that lurk in the dark corners of the code, waiting to bite at the least
      agreeable moment.
      >
      Just don't use this stinking function, use strlcpy or equivalent instead,
      when appropriate.
      >
      The problem is that people think it is a general purpose safe or sub-string
      strcpy() replacement.
      It isn't. It is designed for copying strings to fixed length database fileds
      where there is no necessary terminating nul and no random padding characters
      are allowed. For that purpose it is exactly what you wnat.

      --
      Free games and programming goodies.


      Comment

      • Al Balmer

        #33
        Re: C (functional programming) VS C++ (object oriented programming)

        On Tue, 2 Oct 2007 21:35:31 +0200, "Charlie Gordon" <news@chqrlie.o rg>
        wrote:
        >"Richard Heathfield" <rjh@see.sig.in valida écrit dans le message de news:
        >NNWdnU-UbpD7HZ_aRVnyig A@bt.com...
        >Ben Pfaff said:
        >>
        ><snip>
        >>
        >>There is occasionally a good reason to use strncpy().
        >>
        >Right. I'm aware of the issues that are raised by misuse of strncpy - but
        >hey, any function can be misused. That doesn't necessarily make it a bad
        >function.
        >
        >You are right, it is a matter of statistics. strncpy happens to be misused
        >a lot, causing various kinds of inefficiencies or downright bugs that lurk
        >in the dark corners of the code, waiting to bite at the least agreeable
        >moment.
        >
        >Just don't use this stinking function, use strlcpy or equivalent instead,
        >when appropriate.
        Not available on any implementation I currently use. Use strncpy when
        appropriate. When it's not, I would rather write my own function than
        use strlcpy, which has different implementations on different
        platforms, leading to bad assumptions by programmers, among other
        problems. Even GCC decided not to add it :-)

        --
        Al Balmer
        Sun City, AZ

        Comment

        • Al Balmer

          #34
          Re: C (functional programming) VS C++ (object oriented programming)

          On Tue, 2 Oct 2007 20:07:57 +0100, "Malcolm McLean"
          <regniztar@btin ternet.comwrote :
          >Many people says also that they save more time by programming projects
          >object oriented, but I think its faster to program them in a good
          >structured functional way.
          >>
          >What do you think?
          >>
          >You mean "procedural ". Functional programming is what lisp does.
          You may be right about what he meant, but let's not forget that
          "functional " is a standard English word, and "functional way" may not
          refer to functional programming.

          --
          Al Balmer
          Sun City, AZ

          Comment

          • Tor Rustad

            #35
            Re: C (functional programming) VS C++ (object oriented programming)

            Al Balmer wrote:
            On Tue, 2 Oct 2007 21:35:31 +0200, "Charlie Gordon" <news@chqrlie.o rg>
            wrote:
            [...]
            >Just don't use this stinking function, use strlcpy or equivalent instead,
            >when appropriate.
            >
            Not available on any implementation I currently use.
            Same here, but I even so used these OpenBSD interfaces since year
            2000... go figure.

            Use strncpy when
            appropriate. When it's not, I would rather write my own function than
            use strlcpy, which has different implementations on different
            platforms, leading to bad assumptions by programmers, among other
            problems.
            Shouldn't be a problem for the implementations you use! :-)

            Even GCC decided not to add it :-)
            Did you follow the GNU discussion back then? IIRC, the main argument
            against it, was that few C programmers, demanded these functions and
            that rolling your own would be easy.

            Things are different now, hasn't even Gwyn put forward a safe
            replacement for gets()? Also we have, TR 24731 "Part I: Bounds-checking
            interfaces", recommending all those *_s functions.

            --
            Tor <torust [at] online [dot] no>

            "Life is full of shit, if you look at it"

            Comment

            • Charlie Gordon

              #36
              Re: C (functional programming) VS C++ (object oriented programming)

              "Al Balmer" <albalmer@att.n eta écrit dans le message de news:
              to85g3hid54ut58 pmdt04fsvsebodr 3s6r@4ax.com...
              On Tue, 2 Oct 2007 21:35:31 +0200, "Charlie Gordon" <news@chqrlie.o rg>
              wrote:
              >
              >>"Richard Heathfield" <rjh@see.sig.in valida écrit dans le message de
              >>news:
              >>NNWdnU-UbpD7HZ_aRVnyig A@bt.com...
              >>Ben Pfaff said:
              >>>
              >><snip>
              >>>
              >>>There is occasionally a good reason to use strncpy().
              >>>
              >>Right. I'm aware of the issues that are raised by misuse of strncpy -
              >>but
              >>hey, any function can be misused. That doesn't necessarily make it a bad
              >>function.
              >>
              >>You are right, it is a matter of statistics. strncpy happens to be
              >>misused
              >>a lot, causing various kinds of inefficiencies or downright bugs that lurk
              >>in the dark corners of the code, waiting to bite at the least agreeable
              >>moment.
              >>
              >>Just don't use this stinking function, use strlcpy or equivalent instead,
              >>when appropriate.
              >
              Not available on any implementation I currently use. Use strncpy when
              appropriate. When it's not, I would rather write my own function than
              use strlcpy, which has different implementations on different
              platforms, leading to bad assumptions by programmers, among other
              problems. Even GCC decided not to add it :-)
              I agree with you. That's what I meant by "or equivalent". I have my own
              implementation as well.
              strlcpy was not included in the GLIBC, because they are non-believers: there
              are many instances of strncpy in the GLIBC, most of which are wrong and
              could have been fixed with strlcpy.

              It's a shame the committee would not define a proper library function for
              limited string copy and concatenation, so everybody can safely rely on a
              standardized, well defined API. A revamped stream and string parsing API
              would also have helped more than VLAs.

              --
              Chqrlie.


              Comment

              • J. J. Farrell

                #37
                Re: C (functional programming) VS C++ (object oriented programming)

                On Oct 2, 7:04 pm, jacob navia <ja...@nospam.o rgwrote:
                Richard Heathfield wrote:
                >
                Nonsense. Since he doesn't read the answers I write, he misunderstands
                everything from misquoted posts.
                >
                The original poster says:
                >
                I think I become more and more alone...
                Everybody tells me that C++ is better, because once a project becomes
                very large, I should be happy that it has been written in C++ and not C.
                >
                Then, Mr Mark Bluemel answers:
                I think I become more and more alone...
                >
                Try bathing occasionally...
                >
                Why this insult?
                What insult?
                No reason. I object to that and send a message saying to Mr Bluemel that
                being nasty just doesn't cut it.
                Of course it doesn't, but where was he being nasty? This was obviously
                a joke.

                Comment

                • jacob navia

                  #38
                  Re: C (functional programming) VS C++ (object oriented programming)

                  J. J. Farrell wrote:
                  On Oct 2, 7:04 pm, jacob navia <ja...@nospam.o rgwrote:
                  >Richard Heathfield wrote:
                  >>
                  >Nonsense. Since he doesn't read the answers I write, he misunderstands
                  >everything from misquoted posts.
                  >>
                  >The original poster says:
                  >>
                  >I think I become more and more alone...
                  >Everybody tells me that C++ is better, because once a project becomes
                  >very large, I should be happy that it has been written in C++ and not C.
                  >>
                  >Then, Mr Mark Bluemel answers:
                  > I think I become more and more alone...
                  >>
                  >Try bathing occasionally...
                  >>
                  >Why this insult?
                  >
                  What insult?
                  >
                  >No reason. I object to that and send a message saying to Mr Bluemel that
                  > being nasty just doesn't cut it.
                  >
                  Of course it doesn't, but where was he being nasty? This was obviously
                  a joke.
                  >

                  Of course!

                  How FUNNY!

                  So you approve that when somebody asks a perfectly valid question
                  (or even a bad question who cares) the "regulars" in c.l.c have the
                  right to laugh at him and recommend him to "take a bath".

                  This is one of the basic tenants of group cohesion here: to laugh at the
                  beginner is used in all groups to solidify group cohesion against the
                  new participants, at the expense of the new ones that are
                  perceived as weaker and isolated.

                  Please do not answer any more. Just take a bath pal.
                  Even your emails stink.

                  --
                  jacob navia
                  jacob at jacob point remcomp point fr
                  logiciels/informatique

                  Comment

                  • Richard Heathfield

                    #39
                    Re: C (functional programming) VS C++ (object oriented programming)

                    Charlie Gordon said:

                    <snip>
                    there are many instances of strncpy in the GLIBC, most of which are wrong
                    I'm all for fixing incorrect usages of strncpy, but it's not strncpy's
                    fault if it's misused.

                    <snip>
                    It's a shame the committee would not define a proper library function for
                    limited string copy and concatenation,
                    Perhaps - but that is not what strncpy is for.

                    --
                    Richard Heathfield <http://www.cpax.org.uk >
                    Email: -http://www. +rjh@
                    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                    "Usenet is a strange place" - dmr 29 July 1999

                    Comment

                    • Richard Heathfield

                      #40
                      Re: C (functional programming) VS C++ (object oriented programming)

                      jacob navia said:
                      J. J. Farrell wrote:
                      >On Oct 2, 7:04 pm, jacob navia <ja...@nospam.o rgwrote:
                      <snip>
                      >> being nasty just doesn't cut it.
                      >>
                      >Of course it doesn't, but where was he being nasty? This was obviously
                      >a joke.
                      >
                      Of course!
                      >
                      How FUNNY!
                      >
                      So you approve that when somebody asks a perfectly valid question
                      (or even a bad question who cares) the "regulars" in c.l.c have the
                      right to laugh at him and recommend him to "take a bath".
                      Nobody was laughing *at* him. It was just a joke. Not a terribly good one,
                      I'll grant you, but that's all it was.
                      This is one of the basic tenants of group cohesion here: to laugh at the
                      beginner
                      I don't laugh at beginners. I *would* laugh at your Usenet articles,
                      though, if I were the kind of person to laugh at tragedy.

                      --
                      Richard Heathfield <http://www.cpax.org.uk >
                      Email: -http://www. +rjh@
                      Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                      "Usenet is a strange place" - dmr 29 July 1999

                      Comment

                      • Al Balmer

                        #41
                        Re: C (functional programming) VS C++ (object oriented programming)

                        On Tue, 02 Oct 2007 22:47:19 +0200, Tor Rustad
                        <tor_rustad@hot mail.comwrote:
                        >Al Balmer wrote:
                        >On Tue, 2 Oct 2007 21:35:31 +0200, "Charlie Gordon" <news@chqrlie.o rg>
                        >wrote:
                        >
                        >[...]
                        >
                        >
                        >Even GCC decided not to add it :-)
                        >
                        >Did you follow the GNU discussion back then? IIRC, the main argument
                        >against it, was that few C programmers, demanded these functions and
                        >that rolling your own would be easy.
                        Only sporadically, since I didn't have any strong feelings either way.
                        I remember claims that there was no evidence that they made things
                        safer, despite their long history in BSD, and that it's better for
                        programmers to be aware of how long their strings are, rather than
                        having to check whether data was truncated. I certainly agree with the
                        last, since programmers who can't properly handle strings are probably
                        among those who never check return values :-)
                        >
                        >Things are different now, hasn't even Gwyn put forward a safe
                        >replacement for gets()? Also we have, TR 24731 "Part I: Bounds-checking
                        >interfaces", recommending all those *_s functions.
                        A little while ago, I was asked to enhance a Windows program I wrote a
                        few years ago. An upgrade to the latest Visual Studio was required, as
                        well. One of our regular Windows programmers was happy to tell me how
                        to turn off the warnings about not using the *_s functions <G>.

                        --
                        Al Balmer
                        Sun City, AZ

                        Comment

                        • Mark McIntyre

                          #42
                          Re: C (functional programming) VS C++ (object oriented programming)

                          On Tue, 02 Oct 2007 15:31:50 +0100, in comp.lang.c , Mark Bluemel
                          <mark_bluemel@p obox.comwrote:
                          >I don't think that in general my postings in this group are about
                          >insulting people or being nasty. If I have given that impression, I'm
                          >rather disappointed.
                          Don't worry, they aren't and they don't.
                          --
                          Mark McIntyre

                          "Debugging is twice as hard as writing the code in the first place.
                          Therefore, if you write the code as cleverly as possible, you are,
                          by definition, not smart enough to debug it."
                          --Brian Kernighan

                          Comment

                          • Mark McIntyre

                            #43
                            Re: C (functional programming) VS C++ (object oriented programming)

                            On Tue, 02 Oct 2007 20:04:45 +0200, in comp.lang.c , jacob navia
                            <jacob@nospam.o rgwrote:
                            >Then, Mr Mark Bluemel answers:
                            >>Try bathing occasionally...
                            >
                            >Why this insult?
                            Its not an insult, its a joke. Your inability to detect them is on a
                            part with your inability to enter into friendly conversations and your
                            propensity to launch into verbal diatribes at the slightest pretext.
                            >Just keep me in your killfile.
                            Dream on.

                            --
                            Mark McIntyre

                            "Debugging is twice as hard as writing the code in the first place.
                            Therefore, if you write the code as cleverly as possible, you are,
                            by definition, not smart enough to debug it."
                            --Brian Kernighan

                            Comment

                            • Mark McIntyre

                              #44
                              Re: C (functional programming) VS C++ (object oriented programming)

                              On Tue, 02 Oct 2007 23:10:28 +0200, in comp.lang.c , jacob navia
                              <jacob@nospam.o rgwrote:
                              >J. J. Farrell wrote:
                              >>
                              >Of course it doesn't, but where was he being nasty? This was obviously
                              >a joke.
                              >>
                              >
                              >So you approve that when somebody asks a perfectly valid question
                              >(or even a bad question who cares) the "regulars" in c.l.c have the
                              >right to laugh at him and recommend him to "take a bath".
                              *sigh*

                              Try turning off your paranoia occasionally?
                              >Please do not answer any more. Just take a bath pal.
                              >Even your emails stink.
                              Talk about offensive and nasty.
                              --
                              Mark McIntyre

                              "Debugging is twice as hard as writing the code in the first place.
                              Therefore, if you write the code as cleverly as possible, you are,
                              by definition, not smart enough to debug it."
                              --Brian Kernighan

                              Comment

                              • Mark McIntyre

                                #45
                                Re: C (functional programming) VS C++ (object oriented programming)

                                On Tue, 02 Oct 2007 23:10:28 +0200, in comp.lang.c , jacob navia
                                <jacob@nospam.o rgwrote:
                                >Of course!
                                >
                                >How FUNNY!
                                >
                                >So you approve that when somebody asks a perfectly valid question
                                >(or even a bad question who cares) the "regulars" in c.l.c have the
                                >right to laugh at him and recommend him to "take a bath".
                                >
                                >This is one of the basic tenants of group cohesion here: to laugh at the
                                >beginner is used in all groups to solidify group cohesion against the
                                >new participants, at the expense of the new ones that are
                                >perceived as weaker and isolated.
                                >
                                >Please do not answer any more. Just take a bath pal.
                                >Even your emails stink.
                                Reading this and other posts made recently, I am reminded strongly of
                                some of the comment we got some years ago from the likes of Karl the
                                Chair and Bill. If my interpretation is correct and of course it may
                                be wildly wrong in which case I unreservedly apologise for any
                                distress and so forth, it would be unfair to respond as the poster may
                                not be entirely responsible. I'm therefore sticking JN into my
                                killfile indefinitely, and will deal similarly with any thread that
                                seems to be affected. This troubles me as I do still feel his
                                erroneous posts need correction. Undoubtedly however there will be
                                others who carry on that battle.
                                --
                                Mark McIntyre

                                "Debugging is twice as hard as writing the code in the first place.
                                Therefore, if you write the code as cleverly as possible, you are,
                                by definition, not smart enough to debug it."
                                --Brian Kernighan

                                Comment

                                Working...