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

S

santosh

Richard said:
santosh said:

The asctime function seems rather pointless to me, and gets is of course
unusable. But what is your objection to strncpy?

<snip>

Nothing. I should probably not have lumped it with the likes of gets.
However I have rarely found a use for it. In most cases I use plain strcpy,
and when required an implementation of strlcpy that I wrote myself.

Mostly I feel dodgy about using a string function that can sometimes fail to
produce a valid null-terminated string.
 
R

Richard Heathfield

santosh said:
Richard Heathfield wrote:


Nothing. I should probably not have lumped it with the likes of gets.
However I have rarely found a use for it.

Likewise. Nevertheless, just occasionally it is le mot juste.
In most cases I use plain
strcpy, and when required an implementation of strlcpy that I wrote
myself.

I have never used strlcpy. I do use strcpy on occasion, but mostly I use my
own dynamic string library, for what I hope are obvious reasons.
Mostly I feel dodgy about using a string function that can sometimes fail
to produce a valid null-terminated string.

Quite. Nevertheless, it does a reasonable job of substring handling on
occasion.
 
R

Richard

Martin Ambuhl said:
jacob navia wrote:
[...]
You are the typical example of many people here:

Arrogant and prone to verbal violence without any justification:


Ahhh how comic!


Of course not!

This group doesn't discuss C. It is just for people like you that
get their "kicks" by insulting others, being nasty, and just ignoring
the issues the OP raised!


Consider the above subjected to the analysis Jacod presents. We find
that Jacob's post shows arrogance. We find that it is "prone to
verbal violence without any justification". We find that this post
has no discussion of C. Many of Jacob's posts have no discussion of
C, but are, like this one, insulting and nasty. Amazingly, we find
that Jacob's post completely ignores "the issues the OP raised!"

Here's a clue, Jacob. Not everyone here is you. That you are
arrogant, insulting, prone to verbal violence without justification,
nasty, and ignore the issues the OP raised does not mean that is true
of the rest of us. I have rarely seen such an exercise in
self-criticism disguised as an attack for others.

Not all of us are as antisocial as you, Jacob. Accept it.

You have to be joking? I hate to tell you, but because Jacob disagrees
with you and some similar to you, it does not make him "nasty" in any
way whatsoever. I don't think there is a nicer poster in this
group. This type of thread didn't appear because of the wonderful job
you are doing - quite the opposite in fact. It raises its ugly head time
and time again. A core few make this news group a very unpleasant and
arrogant place. You know you they are. There are ways of correcting and
guiding people. And racing in to be first with "OT" is not one of them.
 
B

Ben Pfaff

Richard Heathfield said:
santosh said:

The asctime function seems rather pointless to me, and gets is of course
unusable. But what is your objection to strncpy?

There is occasionally a good reason to use strncpy(). However:

* Using strncpy() into a large buffer can be very inefficient.
strncpy() always writes to every byte in the destination
buffer, which can waste a lot of time if the destination
buffer is much longer than the source string.

* If the source string is longer than the size of the
destination buffer, then strncpy() doesn't write a
terminating null. So a call to strncpy() must be followed
by explicitly writing a null terminator at the end of the
destination buffer in most cases.
 
L

Laurent Deniau

How about
1) have spend much time on "real" OO languages
2) have found that's C++ not that OO-is
3) do dislike decisions done in C++ (virtual vs. non virtual
functions)
4) tried other OO languages not in the mainstream
5) found them more promising
6) used them but simply realized that they change too fast and need
extra work with every new release
7) appriciates that there do exist C libraries which work since
decades
8) has decided for himself that if OO and C then the way should be
Objective C ;-)

If OO and C is the right way, then I would use the C Object System
since it highlights that C is the next step after Objective-C ;-)
I really would like to see any serious comparison on
1) let's say GTK vs QT (or something similiar)
2) C and C++
3) C and C++ and Smalltalk
4) C and C++ and other languages (bee it statically typed like
Haskell, Ocaml etc,

C++ vs Haskell can be found in:

- DSL Implementation in MetaOCaml, Template Haskell, and C++
- A Comparative Study of Language Support for Generic Programming
or dynamically typed like most of the scripting languages.)
5) C + scripting language vs whatever

Then in the end the question still is open how much time is really
spend on the implementation and how much time on maintenance later or
work before implementation.

a+, ld.
 
R

Richard Heathfield

Richard said:
You have to be joking? I hate to tell you, but because Jacob disagrees
with you and some similar to you, it does not make him "nasty" in any
way whatsoever.

You're right, it doesn't. What makes Mr Navia's articles nasty is not the
fact that he disagrees with others - for lots of us here disagree with
each other, and yet we manage not to be nasty. No, his articles are nasty
because he injects nastiness into them. Martin hit the nail on the head.
I don't think there is a nicer poster in this group.

That is not the only way in which you are in a tiny minority here. Mr Navia
habitually strikes out at people rather than trying to understand what
they're telling him. If that is what you regard as "nicer" behaviour, then
that's up to you, but you will find few who agree with you.

<snip>
 
R

Richard Heathfield

Ben Pfaff said:

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.

<snip>
 
N

n3o

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.
I'm the only guy thinking that C is a great programming language and
that there is no need to program things object oriented.

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?

well, I believe that OOP and Procederal Programming is all a matter of
personal preference, or even the task at hand. Sometimes you, or the
company that you work for, may need an in-house function or tool that
will carry out a desird task. If that is the case, a really in-depth
OOP approach may not be the desired way to achieve the task.
Therefore, it is always best to carefully analyse what type of
approach to take when you begin to implement the program.

n3o
- "You can't consider the problem of defense without first
understanding the problem of attack." -
 
J

jacob navia

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?

No reason. I object to that and send a message saying to Mr Bluemel that
being nasty just doesn't cut it.

And then, the Ambuhlance steps in (he always does) saying that
(of course) *I* am the culprit ans starts sending insults...

Forget it guys!

Just keep me in your killfile.
 
S

santosh

jacob said:
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:

Try bathing occasionally...

Why this insult?

No reason. I object to that and send a message saying to Mr Bluemel that
being nasty just doesn't cut it.

Mark already gave his reasons.
And then, the Ambuhlance steps in

Now this _is_ insulting. If you don't want to see insults shouldn't you
refrain from insulting others?

<snip>
 
T

Tor Rustad

Joe said:
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.
I'm the only guy thinking that C is a great programming language and
that there is no need to program things object oriented.

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?

A "C vs C++" discussion, is a typical flame bate. :)

Bad code can be written regardless of language. My first programming
language was Simula, so OO techniques came naturally, still I ended up
as a C programmer.

My CS teacher said:

"Programming OO (Simula) is like driving a Volvo, while C programming is
driving a Ferrari."

Those days, Volvo was safe, but not very fast.
 
F

Francine.Neary

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:

Try bathing occasionally...

Why this insult?

No reason. I object to that and send a message saying to Mr Bluemel that
being nasty just doesn't cut it.

Why did you consider it an insult? It's clearly meant as a joke.
Perhaps it is your sense of humor that is at fault.
And then, the Ambuhlance steps in (he always does) saying that
(of course) *I* am the culprit ans starts sending insults...

On the other hand, "the Ambuhlance" comes across as something intended
to be gratuitously insulting, rather than playful or affectionate.
 
T

Tor Rustad

Richard said:
Ben Pfaff said:



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.

A well designed API, should be consistent and simple. There are quite
some years ago now, when I told c.l.c people, that the better
alternative for strncpy() and strncat(), was provided by OpenBSD
strlcpy() and strlcat().

Apparently, the standards people didn't agree, so now we have strcpy_s()
and strcat_s().
 
R

Richard Heathfield

jacob navia said:
Richard Heathfield wrote:

Nonsense. Since he doesn't read the answers I write, he misunderstands
everything from misquoted posts.

Actually, my filter is off at the moment, so I can see exactly what you are
writing, and no misquoting is involved. Furthermore, I have read a great
many of your articles in the past, so I know your style very well. That's
why I killfiled you in the first place. Once those two threads have died,
I'll be putting the filter back in place, and your bile can once more go
unsung. I can hardly wait.
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:

Try bathing occasionally...

Why this insult?

Try not to be so obtuse. It's A Joke. Duh. A well-crafted joke? No, not
really. Funny? Not terribly. Even so, the intent was clearly supposed to
be humorous.

<snip>
 
R

Richard Heathfield

Tor Rustad said:

alternative for strncpy() and strncat(), was provided by OpenBSD
strlcpy() and strlcat().

....which I don't need and don't use.
Apparently, the standards people didn't agree, so now we have strcpy_s()
and strcat_s().

I don't need or use those, either.
 
M

Malcolm McLean

Joe Mayo said:
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.
I'm the only guy thinking that C is a great programming language and that
there is no need to program things object oriented.

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.

By "object-oriented programming" we mean a program with abstracted entities
which enter into relationships with each other. Eg if a car, motorbike, and
truck in the program all have ways of being "driven", and that has a point
of commonality, then the program is object-oriented. The method is
independent of language, but in practise to write a non-trivial
object-oriented program in C ylou need to write an interpreter for another
lanauge, whilst in C++ it is easy.

I'd say that something like 80% of programs are naturally procedural, with
20% lend themselves to object-oriented design. Procedural design is easier
to do than object-oritented desing, and usually easier to document. However
object-oriented design is more tolerant of unpredicated extensions. Claims
that object-oriented programs are easier to debug or more reusable are in my
experience unfounded.

An adventure program, for example, has objects like swords, daggers, and
arrows, which are all "weapons", and object-oriented design is a powerful
competitor here. It is also very good for GUIs where all the windows work in
much the same way, but have little idiosyncracies that are better expressed
by code than by parameters. However object-oriented design can lead to
traps. For instance if you want to sort a list of strings using three or
four functions, it is a lot easier to pass the appropriate function to
qsort() than to override inequality operators. You also get subtle bugs
where the interface isn't quite adhered to, for instnace a light might have
colour, position and intensity. Which is fine, until you want to implement a
monochromatic yellow laser.

If you are not doing object-oriented desing, it is better to avoid C++. The
reason is that people are always tempted to play with the language. When you
embed a few C++ features in a basically procedural program the result is
almost always a kludge. C marks the program very clearly as a structured
program.

To be fair to C++, the projects that benefit from object-oriented design
also tend to be the larger ones.
 
T

Tor Rustad

Richard said:
Tor Rustad said:



...which I don't need and don't use.


If you *need* such functions, I can recommend "Standard C Library", by
P. J. Plauger.
 
C

Charlie Gordon

Richard Heathfield said:
Ben Pfaff said:



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.
 
M

Malcolm McLean

Charlie Gordon said:
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.
 
A

Al Balmer

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top