Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > As a programmer of both languages...

Reply
Thread Tools

As a programmer of both languages...

 
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      12-12-2007
Nick Keighley <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

>> So my own point of view is that while C++ is the programming
>> language to be used today for PC's, game consoles and the like, C is
>> still the king when it comes to embedded systems, and that doesn't
>> seem like changing any time soon. And for the less-than-proficient
>> among us, there's Java for PC's, and Basic for micrcontrollers.

>
> Basic? Basic for microcontrollers? ug.



I'm doing an embedded systems project in college at the moment for
my degree. There was a finite number of projects to choose from, and
each had a description. In the description for the embedded systems
project, it mentioned using the Basic Stamp microcontroller and
programming it in Basic.

Before I chose which project I wanted to do, I approached the
embedded systems lecturer and asked him if I could code it in C and
use a proper microcontroller; thankfully he was more than happy to
accomodate me!

Another project choice was to write a webserver. The description
mentioned doing it in Java. I put my hand up and asked if I could do
it in C++... and I got a paragraph of non-information back. So then
I asked again "Just to clarify, can I do it in C++?". I got an
answer something to the effect of "we'll see" and so I went with the
embedded systems project. I'm actually quite glad I did because it's
quite interesting and exciting, plus I got to design my own printed
circuit board and have it sent off to be made. I get the circuit
board back after Christmas and then I can populate it with
components and finally try out my program on it

Plus I get to do the embedded systems project on my own, whereas the
webserver project was a group effort. I also asked the
aforementioned lecturer if I could write a webserver on my own but
the answer to that was No... which was a definite deal-breaker
considering I was the only person in the room who had more than
trivial understanding of any programming language. Electronic
Engineering for you.

--
Tomás Ó hÉilidhe
 
Reply With Quote
 
 
 
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      12-12-2007
"Tomás Ó hÉilidhe" <(E-Mail Removed)> wrote in
news:Xns9A04798A2CCA5toelavabitcom@194.125.133.14:

> I also asked the
> aforementioned lecturer if I could write a webserver on my own but
> the answer to that was No... which was a definite deal-breaker
> considering I was the only person in the room who had more than
> trivial understanding of any programming language.



Of course, "only person" doesn't encompass the lecturers

--
Tomás Ó hÉilidhe
 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      12-12-2007
jacob navia wrote:
> Ian Collins wrote:
>> jacob navia wrote:
>>> Ian Collins wrote:
>>>> jacob navia wrote:
>>>>
>>>>> The difference between C and C++ is the object orientation of C++.
>>>>> C is
>>>>> not object oriented.
>>>>>
>>>> Are you really dense, or just being obtuse? As you have been told many
>>>> times before, C++ is a multi paradigm language. You can *choose* to
>>>> write OO or procedural code in C++.
>>>>
>>> You can't program in C++ without using classes. Even if you define
>>> a simple structure it is actually a class.
>>>

>> Your ignorance continues to astound. Maybe you should take some time
>> out and learn C++ before slagging it off.
>>

>
> Yes Sir!
>
> struct A {
> int age;
> char *Name;
> };
>
> int main(void)
> {
> A jacob;
> }
>
> This is valid C++ but invalid C. In C++ each "structure" definition
> is just a CLASS where all members are PUBLIC by default. I see this
> explanation in all C++ books I read but in my ignorance I believe
> them. Stupid isn't it?



The ability to name a type using 'A' instead of 'struct A' is just
syntactic sugar, not object orientation. Note that this is also a valid
C++ program:

struct A {
int age;
char *Name;
};

int main(void)
{
struct A jacob;
}

Calling structs classes isn't what makes C++ more object oriented than
C. It's what you do with those structs that matters. C++'s object
orientation comes primarily from the fact that it supports member
functions; many other features of C++ help make object orientated code
easier to write, but it's the member functions that make it an object
oriented language.

When you define a struct with no member functions, whether it's called a
struct or a class, you're defining something that is no more object
oriented in C++ than the same code would be in C if you replace 'class'
with 'struct'.

C++ does implicitly define certain special member functions even for
classes with no explicitly declared or defined member functions. These
include things like the default constructor, destructor, copy
constructor, and copy assignment operator. However, C++'s special rules
for POD (Plain Old Data) types mean that the semantics of using the
special member functions for POD structs (such as A above) are identical
to the semantics of the corresponding code in C. They therefore do
nothing to make POD structs in C++ any more object-oriented than they
are in C.

>> C++ does nothing magical with structs, if a struct is valid C, it is
>> equally valid in C++, nothing is added. Otherwise how could we use C
>> libraries with C++?
>>

>
> Both languages are still compatible at many levels. But I am not getting
> crazy, the concept of CLASS is CENTRAL to the C++ language.


No, it's not. C++ classes and structs can support object orientation
more completely than C structs, and that's an important part of the
language, but it's built on top of C. You still have a language fully as
powerful as C even if you never use the object-oriented features of C++
classes that are not supported in C. And object orientation is just one
among several ways that C++ extends C. Generic programming is arguably
becoming far more important in modern C++ than object orientation.

>>> Of course you can write a hello world program without them but explain
>>> me how do you ignore classes in C++?
>>>

>> By not using them?
>>

>
> Of course. But then you are not using C++.
>
> If you write
>
> int main(void) { printf("hello\n");}
>
> you do not need classes but is it C++?


Of course it is. You can also any of the many C++ features that have
nothing to do with object orientation, such as templates and exceptions.
If that isn't C++, what is it?

> What I am saying is obvious. But you refuse to admit the obvious.
> C++ is centered around the class/inheritance concept and that is OO.

 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      12-12-2007
jacob navia wrote:
> Ian Collins wrote:
>> What's your point? The fact that struct is close to a synonym for class
>> is irrelevant. Your example struct is equally valid in both languages,
>> C++ treats it exactly the same as C. Saying you can't write anything
>> useful in C++ without classes is like saying you can't write anything
>> useful in C without using structs.

>
> I have never written anything serious in C without using data types and
> structures. Even a "hello world" program needs stdio.h that has (at
> least) the definition of FILE.
>
> Structures are central to C, as classes are to C++.
>
>> In both languages we represent
>> collections of data in structures.

>
> C++ uses inheritance. Didn't know that you can inherit from a C
> structure.


The fact that you can do more things with a C++ struct than you can do
with a C struct doesn't mean that you're forced to do them. Contrary to
your original objection, you can use C++ structs without writing a
single line of C++ code that is any more object oriented than
corresponding C code, and you can do that without giving up any valuable
feature of C.

....
> Exceptions are objects in C++. The exceptions I am proposing for C
> aren't objects but just integer error codes, what is quite different.


Integers are also stored in objects, both in C and in C++. C++
exceptions can be integers. The existence of objects isn't what makes
code object oriented, otherwise C would be an object-oriented language too.
 
Reply With Quote
 
Erik Trulsson
Guest
Posts: n/a
 
      12-12-2007
somenath <(E-Mail Removed)> wrote:
> On Dec 11, 11:52 pm, Richard Heathfield <(E-Mail Removed)> wrote:
>> Tomás Ó hÉilidhe said:
>>
>>
>>
>> > There seems to be constant vacuous debate about which is better or
>> > preferable, C or C++, and it looks like one of these discussions is on-
>> > going right now in this newsgroup.

>>
>> It is indeed a vacuous debate. Some problems fit better in C than in C++
>> and vice versa, and some programmers are better at C than at C++ and vice
>> versa. One's language choice depends partly on the program and partly on
>> the programmer.

>
>
> I would like to have some more inputs on the above point mentioned by
> you. You are indicating that "One's language choice depends partly on
> the program and partly on
> the programmer"
> Actually my doubt is how it can depend on program? Because we write
> program to solve one particular problem .Now before writing code we
> think about the algorithm which is independent of programming
> language.



Algorithms may be independent of programming languages in that any
algorithm *can* be implemented in any (Turing-complete) programming
language. Some algorithms can, however, be *much* easier to implement
in one programming language than in another.


>
> Could you give one small example where program decides the programming
> language?




Pick for example some algorithm that involves using a single-linked list.
You could implement this algorithm in FORTRAN 77, or older versions of BASIC,
but it would be quite painful since these languages lack several features
that are usually used when implementing linked lists (e.g. user-defined datatypes,
pointers and dynamic memory allocation.)

If you were to implement the same algorithm in, say, Standard ML it would
most likely be much easier since that language has single-linked lists as
one of the basic datatypes.


If on the other hand you were writing a program to do lots of calculations
involving matrices and vectors, the FORTRAN would seem a much better choice
than SML.


C++ (and to a somewhat lesser extent C) is somewhat unusual (but not unique)
among programming languages in that even if they seldom are the best tool
for any given job, they are also almost never a really bad choice.




>
> In my very small experience in programming I feel that choice of
> language depends upon the availability of compiler for the target
> system ,the availability of helper library and availability of the
> programmer of that particular language . (This observation is solely
> for choosing language between C and C ++)






--
<Insert your favourite quote here.>
Erik Trulsson
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      12-12-2007
On 12 Dec, 11:56, "Tomás Ó hÉilidhe" <(E-Mail Removed)> wrote:
> Nick Keighley <(E-Mail Removed)> wrote innews:(E-Mail Removed):
>
> >> So my own point of view is that while C++ is the programming
> >> language to be used today for PC's, game consoles and the like, C is
> >> still the king when it comes to embedded systems, and that doesn't
> >> seem like changing any time soon. And for the less-than-proficient
> >> among us, there's Java for PC's, and Basic for micrcontrollers.

>
> > Basic? Basic for microcontrollers? ug.

>
> I'm doing an embedded systems project in college at the moment for
> my degree. There was a finite number of projects to choose from, and
> each had a description. In the description for the embedded systems
> project, it mentioned using the Basic Stamp microcontroller and
> programming it in Basic.
>
> Before I chose which project I wanted to do, I approached the
> embedded systems lecturer and asked him if I could code it in C and
> use a proper microcontroller; thankfully he was more than happy to
> accomodate me!
>
> Another project choice was to write a webserver. The description
> mentioned doing it in Java. I put my hand up and asked if I could do
> it in C++... and I got a paragraph of non-information back. So then
> I asked again "Just to clarify, can I do it in C++?". I got an
> answer something to the effect of "we'll see" and so I went with the
> embedded systems project. I'm actually quite glad I did because it's
> quite interesting and exciting, plus I got to design my own printed
> circuit board and have it sent off to be made. I get the circuit
> board back after Christmas and then I can populate it with
> components and finally try out my program on it
>
> Plus I get to do the embedded systems project on my own, whereas the
> webserver project was a group effort. I also asked the
> aforementioned lecturer if I could write a webserver on my own but
> the answer to that was No... which was a definite deal-breaker
> considering I was the only person in the room who had more than
> trivial understanding of any programming language. Electronic
> Engineering for you.


sounds fun!

--
Nick Keighley
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-12-2007
James Kuyper <(E-Mail Removed)> writes:
> jacob navia wrote:

[...]
>> Exceptions are objects in C++. The exceptions I am proposing for C
>> aren't objects but just integer error codes, what is quite different.

>
> Integers are also stored in objects, both in C and in C++. C++
> exceptions can be integers. The existence of objects isn't what makes
> code object oriented, otherwise C would be an object-oriented language
> too.


We're getting into yet more confusion caused by multiple meanings of a
word, similar to the problems we've had with "byte" and "stack".

Both the C and C++ standards define the word "object". In C, an
object is a "region of data storage in the execution environment, the
contents of which can represent values". The C++ definition is quite
similar.

This meaning has little or nothing to do with the concept of
"object-oriented" programming.

Another meaning of "object" is, more or less, an instance of a class
type; this is the sense that's consistent with the idea of
"object-oriented" programming. (But the C++ standard does *not* use
the word *object* in this sense.)

C++ exceptions, as I understand it, are *typically* objects in the
latter sense (or perhaps they're values rather than objects?), but
they needn't be. For example, ``throw 42;'' is a legal C++ statement.

Note that the C++ standard also defines the concept of "POD" (which
stands for "Plain Old Data", I think). A POD class, for example, is a
class (a struct or union) that doesn't have any of the C++-specific
stuff (static members, destructor, etc.). C++ code that uses only POD
types is not object-oriented in the usual sense of the term.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
dj3vande@csclub.uwaterloo.ca.invalid
Guest
Posts: n/a
 
      12-12-2007
In article <(E-Mail Removed)>,
Erik Trulsson <(E-Mail Removed)> wrote:

>C++ (and to a somewhat lesser extent C) is somewhat unusual (but not unique)
>among programming languages in that even if they seldom are the best tool
>for any given job, they are also almost never a really bad choice.


And where they ARE a bad choice, you can probably at least use them to
implement a better one.


dave
(the world runs on languages whose implementations are written in C)

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      12-13-2007
Richard Heathfield wrote:
> jacob navia said:
>>

.... snip ...
>>
>> I have never written anything serious in C without using data
>> types and structures.


I have.

> A C program that did not use any data types would be astoundingly
> empty. But if you have *never* written anything serious in C that
> didn't use a structure, this says less about C than it does about
> the limits of your programming experience. Are you really sure
> that you meant to say that?
>
>> Structures are central to C, as classes are to C++.

>
> Structures are important, but I wouldn't say they were central.


You can write fairly elegant programs using only stdin and stdout,
with getc and putc. The fact that those are normally implemented
using such complicated items as FILEs and structures has nothing
essential to do with it. A suitable library can be written (for
that program) without those complications.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      12-13-2007
jacob navia wrote:
> Ian Collins wrote:
>
>> In both languages we represent
>> collections of data in structures.

>
> C++ uses inheritance. Didn't know that you can inherit from a C
> structure.
>

C++ offers the option of using inheritance to extend C structs, it
doesn't force one to use it.
>
> Exceptions are objects in C++. The exceptions I am proposing for C
> aren't objects but just integer error codes, what is quite different.
>

C++ exceptions can be integers as well as objects.
>>
>> All of the extensions to C you keep pushing are available in standard
>> C++, today.
>>

>
> Yes, and so what?
>

If I want them, I use C++, if I don't I use C. Same as if I want
reflection I use PHP. I don't push for reflection in C or C++ even
though it is a very useful addition, I use a language that supports it.

A programmer should build up a toolkit of languages and libraries and
know which one best fits the problems he or she encounters.

> Why wouldn't those extensions be acceptable then?
>
> Why must C be frozen for the benefit of C++?
>

I never said it should, the languages have lives of their own. They may
occasionally cross-pollinate (bits of C++ in C99, bits of C99 in C++
next) but one does not drive the other.

--
Ian Collins.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent positions: Sr Programmer Analyst (SPA) and Programmer Analyst(PRA)-06+month's- Carson City, NV. Isaac Java 0 12-08-2010 05:34 PM
Who gets higher salary a Java Programmer or a C++ Programmer? Sanny Java 391 01-06-2010 02:48 AM
Who gets higher salary a Java Programmer or a C++ Programmer? Sanny C++ 396 12-17-2008 06:13 PM
compilation error: file exists in both in both 'c:\WINNT\Microsoft.NET\Framework\v2.0.50727 ABCL ASP .Net 0 05-29-2008 04:59 PM
2 computers, both online, both invisible to each other ? b Computer Support 9 04-21-2006 04:06 AM



Advertisments