EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

Quickie Poll -- C vs. C++

elektroda.net NewsGroups Forum Index - Electronics Design - Quickie Poll -- C vs. C++

Goto page Previous  1, 2, 3, 4, 5

Phil Hobbs
Guest

Sun Aug 29, 2010 7:29 pm   



JosephKK wrote:
Quote:
On Fri, 27 Aug 2010 11:04:39 -0400, Phil Hobbs
pcdhSpamMeSenseless_at_electrooptical.net> wrote:

Warren wrote:
Phil Hobbs expounded in news:4C76E962.9070508_at_electrooptical.net:

...
What is your _preferred_ programming language for smallish (1000
lines of code) projects? C? C++? Something else? What?
REXX or C++, except when programming microcontrollers.
...
Phil Hobbs
REXX on a MCU would be perverse indeed.

Warren
I don't know--the statically linked executable is about 393k on Windows,
so if you built it for an ARM Cortex M3, say, you could probably slim
it down to below 256k, which is less than half the flash available.

Of course scripting usually needs a bunch of I/O, so it usually won't
make sense without a disk.

I used to really love HP Basic on the HP9816--it had really great
built-in GPIB support, which made instrument control a breeze.

Cheers

Phil Hobbs

I got my introduction to Rocky Mountain BASIC for instrument control
on the HP 9845B, the predecessor to the 9816, in 1978.

I even had a FP accelerator board that came with a RMB-compatible
*compiler*. For the time, that one _flew_. IIRC it used some obscure
Intel iapx432 or i860 floating point chip, not a 68881.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058
hobbs at electrooptical dot net
http://electrooptical.net

Tauno Voipio
Guest

Sun Aug 29, 2010 7:43 pm   



On 29.8.10 9:23 , Rune Allnor wrote:
Quote:
On 27 Aug, 20:08, Randy Yates<ya...@ieee.org> wrote:
spop...@speedymail.org (Steve Pope) writes:
Randy Yates<ya...@ieee.org> wrote:

Tim Wescott<t...@seemywebsite.com> writes:

What is your _preferred_ programming language for smallish (1000 lines
of code) projects? C? C++? Something else? What?

C.

Why?

Simpler.

With some familiarization, C++ feels simpler now to me. If it's
code I'm writing myself. If I'm analyzing/applying someone else's
code, all bets are off.

Of course it's subjective, but I don't see how it could possibly be
simpler to have to make decisions on class layout as well as
structuring/organizing functions within a class as opposed to
structuring a small group of functions. Even if you are only using one
class, just carrying around the class baggage is a negative, in my
opinion.

You need to see this from the right angle: A class is a type.
This allows you, the programmer, to cooperate with the
compiler in very powerful ways.

You *might* want to expand the class ito a hierarchy, using
all sorts of inheritance, virtual functions and all kinds of
stuff that add a lot of overhead, but you don't need to.

Once you, the programmer, is free to declare your own
types - classes - you all of a sudden get access to the
most powerful featiures of C++ right now: Templates.
This means that you can use the standard functionality of
the STL merely by ensuring that your custom data type - the
class - has some basic functionality.

As long as you make sure your class has a operator<() function
(and maybe a couple of other detail regarding constructors),
you can immediately use the std::sort functions from the STL.

You need to try it to see the power. Forget about OO. Classes
in C++ today is at least as much about types.


For small projects (as the OP asked) it is often very important
how transparent the compilation process is. For small embedded
targets, I nearly always read the generated assembly code to
see that the result is satisfactory.

The more powerful abstractions are used, the less transparent
the translation process is.

Properly used, C++ can at times produce nearly as good code as C,
but it will be more tedious to tune the source. Also, the minimum
run-time overhead is larger with most compilers.

--

Tauno Voipio
tauno voipio (at) iki fi

Nico Coesel
Guest

Sun Aug 29, 2010 8:00 pm   



Tim Wescott <tim_at_seemywebsite.com> wrote:

Quote:
So, I'm working on a spare-time project that's off the back burner for
at least a day. It's a trainer, and I'd _like_ to be able to set it up
so that advanced students can do their own programming. Hence, the poll.

So, since anyone who responds to a dippy poll on USENET is obviously
100% representative of the embedded software engineering public, I know
that your responses will accurately reflect reality.

If you answer this poll you will _not_ be entered into a contest to win
an iPod, or a free smokeless cigarette, or anything else. So do it for
the glory, and to advance the state of the species.

Please don't fire up the C vs. C++ flame war -- we all know that Forth
is the best language in the world next to Python, so C vs. C++ is really
moot anyway.

What is your _preferred_ programming language for smallish (1000 lines
of code) projects? C? C++? Something else? What?

On Linux or Windows C++. STL and objects make life a lot easier. I
looked into C++ for microcontrollers. IMHO C++ should be useful there
as well. A lot of programmers emulate objects in C nowadays. Why not
have the compiler deal with it and reduce the chance on bugs?

Quote:
What size processor(s) do you most often find yourself using? 8 bit?
16? 32?

32

Quote:
What size of memory space do you most often find yourself using? Less
than 1kbyte? 1 to 8kbyte? 8 to 64kbyte? More than 64kbyte?

Depends on the project. Some of my projects need less than 1kB some
need >500kB. In some cases the memory is limited. Clever coding can
perform miracles.

Quote:
If you had to use someone's library code in your smallish project and
knew nothing about it other than the language it's written in, would you
be happier knowing it was in C, C++ or some other language?

I'd be happier to know how it was tested and with what optimisation
setting it was compiled.

--
Failure does not prove something is impossible, failure simply
indicates you are not using the right tools...
nico_at_nctdevpuntnl (punt=.)
--------------------------------------------------------------

Randy Yates
Guest

Sun Aug 29, 2010 8:21 pm   



Rune Allnor <allnor_at_tele.ntnu.no> writes:

Quote:
On 27 Aug, 20:08, Randy Yates <ya...@ieee.org> wrote:
spop...@speedymail.org (Steve Pope) writes:
Randy Yates  <ya...@ieee.org> wrote:

Tim Wescott <t...@seemywebsite.com> writes:

What is your _preferred_ programming language for smallish (1000 lines
of code) projects?  C?  C++?  Something else?  What?

C.

Why?

Simpler.

With some familiarization, C++ feels simpler now to me.  If it's
code I'm writing myself.  If I'm analyzing/applying someone else's
code, all bets are off.

Of course it's subjective, but I don't see how it could possibly be
simpler to have to make decisions on class layout as well as
structuring/organizing functions within a class as opposed to
structuring a small group of functions. Even if you are only using one
class, just carrying around the class baggage is a negative, in my
opinion.

You need to see this from the right angle: A class is a type.
This allows you, the programmer, to cooperate with the
compiler in very powerful ways.

You *might* want to expand the class ito a hierarchy, using
all sorts of inheritance, virtual functions and all kinds of
stuff that add a lot of overhead, but you don't need to.

Once you, the programmer, is free to declare your own
types - classes - you all of a sudden get access to the
most powerful featiures of C++ right now: Templates.
This means that you can use the standard functionality of
the STL merely by ensuring that your custom data type - the
class - has some basic functionality.

As long as you make sure your class has a operator<() function
(and maybe a couple of other detail regarding constructors),
you can immediately use the std::sort functions from the STL.

You need to try it to see the power. Forget about OO. Classes
in C++ today is at least as much about types.

I don't disagree with anything you've stated except perhaps the main
point. There are just some projects that don't need the power, and thus
the complexity, of C++. Simpler is better. Always.
--
Randy Yates % "She's sweet on Wagner-I think she'd die for Beethoven.
Digital Signal Labs % She love the way Puccini lays down a tune, and
mailto://yates_at_ieee.org % Verdi's always creepin' from her room."
http://www.digitalsignallabs.com % "Rockaria", *A New World Record*, ELO

Rune Allnor
Guest

Sun Aug 29, 2010 9:23 pm   



On 27 Aug, 20:08, Randy Yates <ya...@ieee.org> wrote:
Quote:
spop...@speedymail.org (Steve Pope) writes:
Randy Yates  <ya...@ieee.org> wrote:

Tim Wescott <t...@seemywebsite.com> writes:

What is your _preferred_ programming language for smallish (1000 lines
of code) projects?  C?  C++?  Something else?  What?

C.

Why?

Simpler.

With some familiarization, C++ feels simpler now to me.  If it's
code I'm writing myself.  If I'm analyzing/applying someone else's
code, all bets are off.

Of course it's subjective, but I don't see how it could possibly be
simpler to have to make decisions on class layout as well as
structuring/organizing functions within a class as opposed to
structuring a small group of functions. Even if you are only using one
class, just carrying around the class baggage is a negative, in my
opinion.

You need to see this from the right angle: A class is a type.
This allows you, the programmer, to cooperate with the
compiler in very powerful ways.

You *might* want to expand the class ito a hierarchy, using
all sorts of inheritance, virtual functions and all kinds of
stuff that add a lot of overhead, but you don't need to.

Once you, the programmer, is free to declare your own
types - classes - you all of a sudden get access to the
most powerful featiures of C++ right now: Templates.
This means that you can use the standard functionality of
the STL merely by ensuring that your custom data type - the
class - has some basic functionality.

As long as you make sure your class has a operator<() function
(and maybe a couple of other detail regarding constructors),
you can immediately use the std::sort functions from the STL.

You need to try it to see the power. Forget about OO. Classes
in C++ today is at least as much about types.

Rune

Randy Yates
Guest

Sun Aug 29, 2010 10:14 pm   



spope33_at_speedymail.org (Steve Pope) writes:

Quote:
Randy Yates <yates_at_ieee.org> wrote:

Rune Allnor <allnor_at_tele.ntnu.no> writes:

[snip]

I don't disagree with anything you've stated except perhaps the main
point. There are just some projects that don't need the power, and thus
the complexity, of C++. Simpler is better. Always.

But since C is a subset of C++, there's nothing preventing you
from writing just as simple a program in C++.

That's (pretty much) true. However, there is more to it than just the
syntax. The C compiler itself is simpler and I believe more robust, and
error messages are easier to understand.

Quote:
If you're using some C++ feature that is not in C, you are
doing so for a reason. In a not insignificant number of
cases, the reason is that the C++ feature makes the program
even simpler. (e.g. not having to use function pointers,
having complex number already in the language standard, etc.)

That is certainly possible. I still would jump on C for a
simple project. I am much more familiar with it than C++,
and it's simpler. Sometimes even having the ability to do
something fancy can be a distraction, e.g., it gives you
a choice you must decide.
--
Randy Yates % "How's life on earth?
Digital Signal Labs % ... What is it worth?"
mailto://yates_at_ieee.org % 'Mission (A World Record)',
http://www.digitalsignallabs.com % *A New World Record*, ELO

Steve Pope
Guest

Sun Aug 29, 2010 10:46 pm   



Rune Allnor <allnor_at_tele.ntnu.no> wrote:

[snip C++ previous comments]

Quote:
You need to see this from the right angle: A class is a type.
This allows you, the programmer, to cooperate with the
compiler in very powerful ways.

You *might* want to expand the class ito a hierarchy, using
all sorts of inheritance, virtual functions and all kinds of
stuff that add a lot of overhead, but you don't need to.

Once you, the programmer, is free to declare your own
types - classes - you all of a sudden get access to the
most powerful featiures of C++ right now: Templates.
This means that you can use the standard functionality of
the STL merely by ensuring that your custom data type - the
class - has some basic functionality.

As long as you make sure your class has a operator<() function
(and maybe a couple of other detail regarding constructors),
you can immediately use the std::sort functions from the STL.

You need to try it to see the power. Forget about OO. Classes
in C++ today is at least as much about types.

Very well stated.

A statement one frequently hears, that is misleading, is
that one isn't doing true OO unless one uses inheritance,
and in particular virtual functions, and therefore one is
not utilizing the advantages of C++. This perspective is
really only valid in certain very large software engineering
projects. For the average engineer doing signal processing
or communications, there is a large advantage to using
the encapsulation and polymorphism aspects of C++, without
even touching these "true OO" features.

C has weak encapsulation: a program is a flat set of function
definitions and external variables. The "static" keyword
can provide only one level of limited encapsulation. In C++,
functions can be encapsulated within classes (e.g. they
can be methods), and there are namespaces. There are the
private/public feature of class membership; and you have
the "friend" keyword, and while both of these are arguably
blunt instruments, they are very useful and they are missing from C.

(All members of a "struct" in C are public, and while you
can include function pointers -- messy -- you can't include
functions.)

C has almost no polymorphism. In C++, there are templates,
and there is generalized operator overloading.

The neat thing (for me) about C++ is that the above features
allow you to organize your programs in a vastly better, and
ultimately simpler fashion; yet it still maintains the model
of separate compilation; it is still very efficient.
You do not have to give up entirely, and go to an interpreted model,
just to get OO-style programming language features.

Steve

Steve Pope
Guest

Sun Aug 29, 2010 11:14 pm   



Randy Yates <yates_at_ieee.org> wrote:

Quote:
Rune Allnor <allnor_at_tele.ntnu.no> writes:

[snip]

I don't disagree with anything you've stated except perhaps the main
point. There are just some projects that don't need the power, and thus
the complexity, of C++. Simpler is better. Always.

But since C is a subset of C++, there's nothing preventing you
from writing just as simple a program in C++.

If you're using some C++ feature that is not in C, you are
doing so for a reason. In a not insignificant number of
cases, the reason is that the C++ feature makes the program
even simpler. (e.g. not having to use function pointers,
having complex number already in the language standard, etc.)

Steve

Boudewijn Dijkstra
Guest

Tue Aug 31, 2010 1:22 pm   



Op Wed, 25 Aug 2010 23:50:17 +0200 schreef Tim Wescott
<tim_at_seemywebsite.com>:
Quote:
So, I'm working on a spare-time project that's off the back burner for
at least a day. It's a trainer, and I'd _like_ to be able to set it up
so that advanced students can do their own programming. Hence, the poll.

So, since anyone who responds to a dippy poll on USENET is obviously
100% representative of the embedded software engineering public, I know
that your responses will accurately reflect reality.

If you answer this poll you will _not_ be entered into a contest to win
an iPod, or a free smokeless cigarette, or anything else. So do it for
the glory, and to advance the state of the species.

Please don't fire up the C vs. C++ flame war -- we all know that Forth
is the best language in the world next to Python, so C vs. C++ is really
moot anyway.

What is your _preferred_ programming language for smallish (1000 lines
of code) projects? C? C++? Something else? What?

Depending on the task at hand: Korn shell, C, Java.

Quote:
Why?

Shell is good for simple things on a high level, C allows better control
over I/O and program flow, Java allows the same control but with much
richer libraries.

Quote:
Would you describe yourself as being competent in both C and C++? If
only one, which?

I would describe myself as being competent. I find it comforting to know
that until now I never did have to know the intricate details of both C
and C++; just C is enough.

Quote:
What size processor(s) do you most often find yourself using? 8 bit?
16? 32?

32. Assuming you mean the size of its ALU.

Quote:
What size of memory space do you most often find yourself using? Less
than 1kbyte? 1 to 8kbyte? 8 to 64kbyte? More than 64kbyte?

16 kiB and up.

Quote:
If you had to use someone's library code in your smallish project and
knew nothing about it other than the language it's written in, would you
be happier knowing it was in C, C++ or some other language?

I would be happier knowing the quality of the code and the description of
its interface. If I knew nothing other than the language, I would be
happier knowing that somebody internal could debug it if necessary.

Quote:
Are you comfortable reading schematics of digital circuits?

Yes.

Quote:
Are you comfortable reading schematics of mixed analog and digital
circuits?

Usually.

Quote:
If you can't read schematics, can you find your way around a block
diagram? Can you understand explanations of circuit behavior given by a
sympathetic hardware engineer?

Yes, sympathetic hardware engineers do exist. But unfortunately they can
be so enthusiastic about their design that it becomes hard to follow them.



--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/
(remove the obvious prefix to reply by mail)

JosephKK
Guest

Thu Sep 02, 2010 5:06 am   



On Sun, 29 Aug 2010 14:29:02 -0400, Phil Hobbs
<pcdhSpamMeSenseless_at_electrooptical.net> wrote:

Quote:
JosephKK wrote:
On Fri, 27 Aug 2010 11:04:39 -0400, Phil Hobbs
pcdhSpamMeSenseless_at_electrooptical.net> wrote:

Warren wrote:
Phil Hobbs expounded in news:4C76E962.9070508_at_electrooptical.net:

...
What is your _preferred_ programming language for smallish (1000
lines of code) projects? C? C++? Something else? What?
REXX or C++, except when programming microcontrollers.
...
Phil Hobbs
REXX on a MCU would be perverse indeed.

Warren
I don't know--the statically linked executable is about 393k on Windows,
so if you built it for an ARM Cortex M3, say, you could probably slim
it down to below 256k, which is less than half the flash available.

Of course scripting usually needs a bunch of I/O, so it usually won't
make sense without a disk.

I used to really love HP Basic on the HP9816--it had really great
built-in GPIB support, which made instrument control a breeze.

Cheers

Phil Hobbs

I got my introduction to Rocky Mountain BASIC for instrument control
on the HP 9845B, the predecessor to the 9816, in 1978.

I even had a FP accelerator board that came with a RMB-compatible
*compiler*. For the time, that one _flew_. IIRC it used some obscure
Intel iapx432 or i860 floating point chip, not a 68881.

Cheers

Phil Hobbs

Could it have been the Weitek 1167(?)?

Phil Hobbs
Guest

Thu Sep 02, 2010 2:45 pm   



JosephKK wrote:
Quote:
On Sun, 29 Aug 2010 14:29:02 -0400, Phil Hobbs
pcdhSpamMeSenseless_at_electrooptical.net> wrote:

JosephKK wrote:
On Fri, 27 Aug 2010 11:04:39 -0400, Phil Hobbs
pcdhSpamMeSenseless_at_electrooptical.net> wrote:

Warren wrote:
Phil Hobbs expounded in news:4C76E962.9070508_at_electrooptical.net:

...
What is your _preferred_ programming language for smallish (1000
lines of code) projects? C? C++? Something else? What?
REXX or C++, except when programming microcontrollers.
...
Phil Hobbs
REXX on a MCU would be perverse indeed.

Warren
I don't know--the statically linked executable is about 393k on Windows,
so if you built it for an ARM Cortex M3, say, you could probably slim
it down to below 256k, which is less than half the flash available.

Of course scripting usually needs a bunch of I/O, so it usually won't
make sense without a disk.

I used to really love HP Basic on the HP9816--it had really great
built-in GPIB support, which made instrument control a breeze.

Cheers

Phil Hobbs
I got my introduction to Rocky Mountain BASIC for instrument control
on the HP 9845B, the predecessor to the 9816, in 1978.
I even had a FP accelerator board that came with a RMB-compatible
*compiler*. For the time, that one _flew_. IIRC it used some obscure
Intel iapx432 or i860 floating point chip, not a 68881.

Cheers

Phil Hobbs

Could it have been the Weitek 1167(?)?

Found it--Infotek. This is an announcement of the second version of the
compiler. IEEE Computer Society News, February 1986.

Infotek Systems,
BC204 Basic Compiler Compiler The BC 204 is compatible with HP 9000
Series 200/300 technical workstations and compiles Hewlett-Packard Basic
version 4.0. Compiled programs operate with Infotek's FP 200 or FP 210
floating-point coprocessors and the HP 98635 floating-point coprocessor.
Cost: $880. Infotek Systems, 1400 N. Baxter St., Anaheim, CA 92806;
(714) 956-9300.

A company history is at http://www.hp9825.com/html/infotek.html.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058
hobbs at electrooptical dot net
http://electrooptical.net

Phil Hobbs
Guest

Thu Sep 02, 2010 2:46 pm   



JosephKK wrote:
Quote:
On Sun, 29 Aug 2010 14:29:02 -0400, Phil Hobbs
pcdhSpamMeSenseless_at_electrooptical.net> wrote:

JosephKK wrote:
On Fri, 27 Aug 2010 11:04:39 -0400, Phil Hobbs
pcdhSpamMeSenseless_at_electrooptical.net> wrote:

Warren wrote:
Phil Hobbs expounded in news:4C76E962.9070508_at_electrooptical.net:

...
What is your _preferred_ programming language for smallish (1000
lines of code) projects? C? C++? Something else? What?
REXX or C++, except when programming microcontrollers.
...
Phil Hobbs
REXX on a MCU would be perverse indeed.

Warren
I don't know--the statically linked executable is about 393k on Windows,
so if you built it for an ARM Cortex M3, say, you could probably slim
it down to below 256k, which is less than half the flash available.

Of course scripting usually needs a bunch of I/O, so it usually won't
make sense without a disk.

I used to really love HP Basic on the HP9816--it had really great
built-in GPIB support, which made instrument control a breeze.

Cheers

Phil Hobbs
I got my introduction to Rocky Mountain BASIC for instrument control
on the HP 9845B, the predecessor to the 9816, in 1978.
I even had a FP accelerator board that came with a RMB-compatible
*compiler*. For the time, that one _flew_. IIRC it used some obscure
Intel iapx432 or i860 floating point chip, not a 68881.

Cheers

Phil Hobbs

Could it have been the Weitek 1167(?)?

Found it--Infotek. This is an announcement of the second version of the
compiler. IEEE Computer Society News, February 1986.

Infotek Systems,
BC204 Basic Compiler Compiler The BC 204 is compatible with HP 9000
Series 200/300 technical workstations and compiles Hewlett-Packard Basic
version 4.0. Compiled programs operate with Infotek's FP 200 or FP 210
floating-point coprocessors and the HP 98635 floating-point coprocessor.
Cost: $880. Infotek Systems, 1400 N. Baxter St., Anaheim, CA 92806;
(714) 956-9300.

A company history is at http://www.hp9825.com/html/infotek.html.

Foggy memory is clearing up: the first coprocessor board was a 432, but
the second one was a 68881.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058
hobbs at electrooptical dot net
http://electrooptical.net

Goto page Previous  1, 2, 3, 4, 5

elektroda.net NewsGroups Forum Index - Electronics Design - Quickie Poll -- C vs. C++

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony