473,772 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"C vs java"

49 2911
Richard Tobin said:
In article <hO************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>>Obviously when comparing
languages you have to use words in a more general sense.
>>In which case you also have to move the discussion to a group where those
words won't be misinterpreted as having a more specific sense - i.e. not
comp.lang.c . My review was based on the theme of the newsgroup in which
the URL was posted.

Frankly, that's just silly.
Frankly, then, we disagree, and it appears that we disagree in a way that
is unlikely to be resolved. Such is life.

<snip>

--
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
Jun 27 '08 #11
On May 14, 9:54*am, Richard Heathfield <r...@see.sig.i nvalidwrote:
aark...@gmail.c om said:
Hi all,
See:- * * * * * *http://www.cs.princeton.edu/introcs/faq/c2java.html

The first obvious error is the confusion of implementations with the
language proper, in the "compilatio n" row. This error occurs again in each
of the following three rows.

Minor nit: the "hello, world" row doesn't show a "hello, world" program in
either C or Java.

The "integer types" row omits char, short, and unsigned types.

The "floating point types" row omits long double.

The "for loops" row doesn't demonstrate the full power of the for loop.

The "array declarations" row doesn't show how to declare an array. Instead,
it shows how to allocate memory for N objects. (Curiously, the author not
only gets the allocation right, but almost gets it *canonically* right.)

The "array size" row says that arrays don't know their own length, but in
fact it is trivially calculable from sizeof arr / sizeof arr[0].

The "strings" row incorrectly says that a string is a '\0'-terminated
character array. Consider: char foo[8] = "u\0v\0w\0x y"; this contains not
one string but six, and none of them is an array. Furthermore, the array
itself is not '\0'-terminated. It is 'y'-terminated!

The "accessing a library" row does not demonstrate how to access a library..
It demonstrates how to include a header.

The "accessing a library function" row shows two code fragments that cannot
coincide as if they did coincide, and makes a claim about the "global"
nature of function and variable names without making it clear what they
mean by "global". Whether "variables" are "global" depends not only on
what you mean by "global" and what you mean by "variable" but also on
whether the "variables" are auto-qualified (and remember that, within a
function, auto qualification is the /default/). If the author is referring
solely to functions and variables that are (a) contained in a library and
(b) visible to the caller - and this seems like a reasonable deduction -
then he ought to make this explicit.

The "printing to standard output" row shows example code that writes to a
stream that is line-buffered by default, without either terminating the
line or flushing the stream.

The "formatted printing" row is interesting insofar as it basically says
"look what Java stole from C".

The "reading from stdin" row shows broken example code, which fails to
check the result of the read.

The "memory address" row doesn't make it clear how a reference differs from
a pointer. It seems to me that a reference /is/ a pointer. A rose by any
other name, and all that.

The "pass-by-value" row suggests that non-primitive non-struct non-pointer
data types (e.g. unions) might /not/ be passed by value, whereas of course
the truth is that, in C, *everything* is passed by value.

Minor nit: the "accessing a data structure" row uses the term "numerator" ,
which seems rather strange in the context, as nothing is being numerated.

The "allocating memory" row focuses on malloc, ignoring not only calloc and
realloc but also static declaration syntax.

The "memory allocation of data structures and arrays" row confuses the
language with an implementation.

The "buffer overflow" row seems to suggest that crashing with a run-time
error exception is somehow preferable to crashing with a segfault, but it
isn't made clear why this is preferable.

The "declaring constants" row suggests that #define constitutes a
declaration, which it doesn't.

The "variable auto-initialization" row suggests, as someone has pointed out
elsethread, that C doesn't make any initialisation guarantees at all,
whereas static, external, and partially-initialised aggregate objects all
have well-defined and guaranteed initialisation rules.

The "casting" row says "anything goes", which is simply wrong.

The "polymorphi sm" row contains a spelling error. Now, I know it's a bit
infra dignitatis to point out spelling errors, but this one is a
misspelling of "inheritanc e" as "inheritenc e", which suggests either that
the author hasn't read a great deal about OOP or that he doesn't have a
very retentive memory. Neither of these possibilities is very reassuring.

Minor nit: the "overloadin g" row overlooks C's admittedly minor examples of
overloading, on operators such as +, ++, *, and so on.

The "variable declaration" row overlooks the fact that names declared at
file scope are not even /in/ a block, let alone at the start of one.

The "variable naming conventions" row is simply wrong. There are as many
conventions as there are programmers. No single convention is mandated by
the C language spec, implementations , or anything of the kind. (Project
managers, now - that's a different story. If only they could all agree on
one convention...)

The "file naming conventions" row confuses the language with the
implementation and even the file system!

The "callbacks" row suggests that "non-global" functions can't be used as
callbacks. Of course, static functions are a counter-example.

The "variable number of arguments" row mentions "varargs" under the C
column, but I have no idea why. The C Standard doesn't even mention this
term, and it is effectively meaningless without definition.

The "exit and return value to OS" row provides a very poor-style exit call
(value has no portable semantics), and fails to mention returning from
main.

If one is to attack a language, one had better start by learning it.

--
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
Jun 27 '08 #12
On May 14, 9:54*am, Richard Heathfield <r...@see.sig.i nvalidwrote:
aark...@gmail.c om said:
Hi all,
See:- * * * * * *http://www.cs.princeton.edu/introcs/faq/c2java.html
The "array size" row says that arrays don't know their own length, but in
fact it is trivially calculable from sizeof arr / sizeof arr[0].
I think it had dynamic arrays in mind. In that case the language
doesn't itself store the array size.

(In C it's not trivial to get the size of even an ordinary array,
despite your comment; imagine arr had a considerably longer name.
What /would/ have been trivial, but out of character for C, was
a .length property for such arrays.)

All in all this seems a good at-a-glance guide to the two languages,
even if had to simplify many things. Perhaps a reference to a more
detailed guide to C and Java could have been added.

[Apologies for the other post; google said "your post was successful",
even though I clicked no buttons; honest!]
--
Bartc

Jun 27 '08 #13
Richard Tobin wrote:
For example, when it says that you declare constants using #define,
this is perfectly true if you interpret it as "how do you accomplish
in C the task that would typically be described as declaring a
constant".
I guess if the question had been "create a constant", the answers could
be comparable.
The fact that you can't do this with a real C declaration
is a deficiency of C, not of the comparison.
Is it? why?

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Jun 27 '08 #14
Chris McDonald wrote:
Richard Heathfield <rj*@see.sig.in validwrites:
>aa*****@gmail.c om said:
>>See:- http://www.cs.princeton.edu/introcs/faq/c2java.html

[snip]
>If one is to attack a language, one had better start by learning it.


I didn't see any attempt to attack either language;
Come now; there were any number of statements which strongly implied the
writer preferred java and was listing what he felt were C's deficiencies.
I saw an attempt to summarize differences at a level suitable for
undergraduate students.
People attempting to do this without prejudice would

- not have stated unequivocally that Java code is portable without
discipline, instead they'd have noted that to make Java portable you
need to show the same discipline as for C - vis to stick to the standard
libraries you can guarantee to have present.

- have noted that C /code/ is portable, subject to the above.

- have noted that using a class library in Java requires it to be
installed on the host, breaking portability in its strictest sense.

- not have implied that java won't lose precision when demoting types
(of course it will - you can't take a 32-bit value and stuff it into 16
bits without losing /something/ ).
- have known both langages well enough not to have made a number of
glaring errors; or at least got a C expert to review it before publication.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Jun 27 '08 #15
Mark McIntyre wrote:
Richard Tobin wrote:
>For example, when it says that you declare constants using #define,
this is perfectly true if you interpret it as "how do you accomplish
in C the task that would typically be described as declaring a
constant".

I guess if the question had been "create a constant", the answers could
be comparable.
>The fact that you can't do this with a real C declaration
is a deficiency of C, not of the comparison.

Is it? why?
Because there's absolutely no practical reason why an integer constant
can't be a compile time constant.

--
Ian Collins.
Jun 27 '08 #16
Mark McIntyre <ma**********@s pamcop.netwrite s:
>Chris McDonald wrote:
>Richard Heathfield <rj*@see.sig.in validwrites:
>>aa*****@gmail.c om said:
>>>See:- http://www.cs.princeton.edu/introcs/faq/c2java.html

[snip]
>>If one is to attack a language, one had better start by learning it.


I didn't see any attempt to attack either language;
>Come now; there were any number of statements which strongly implied the
writer preferred java and was listing what he felt were C's deficiencies.
>I saw an attempt to summarize differences at a level suitable for
undergraduat e students.
>People attempting to do this without prejudice would
[list of 6 items snipped]
The statements (more likely) could have easily been made in ignorance
or a vacuum of knowledge; that's certainly an error, but it still does
not make the document an attack on either language.

Why do many posters in c.l.c take a confrontational stance?
The original document was intending to help undergraduates, and the
OP probably thought it a document in which readers of c.l.c would be
interested. The background facts may have been wrong, but the intentions
were genuine.

--
Chris.
Jun 27 '08 #17
Mark McIntyre wrote:
Ian Collins wrote:
>Mark McIntyre wrote:
>>Richard Tobin wrote:

The fact that you can't do this with a real C declaration
is a deficiency of C, not of the comparison.
Is it? why?
Because there's absolutely no practical reason why an integer constant
can't be a compile time constant.

Absolutely no practical reason (you can think of) on today's hardware,
you mean.

And why is that a deficiency?
Because we have to use hacks like enums and worse still (spit) macros
for compile time constants.

--
Ian Collins.
Jun 27 '08 #18
Chris McDonald wrote:
Mark McIntyre <ma**********@s pamcop.netwrite s:
>Chris McDonald wrote:
>>The background facts may have been wrong, but the intentions
were genuine.
>As were Richards. Perhaps you missed that point in your haste to complain.

Whoa! Nice try to get the last word,
You can have that.
but you'll find that I haven't complained,
Other than the point where you complained about Richard reading attacks
into stuff that you didn't think contained any.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Jun 27 '08 #19
Mark McIntyre <ma**********@s pamcop.netwrite s:
>Chris McDonald wrote:
>Mark McIntyre <ma**********@s pamcop.netwrite s:
>>Chris McDonald wrote:
>>>The background facts may have been wrong, but the intentions
were genuine.
>>As were Richards. Perhaps you missed that point in your haste to complain.

Whoa! Nice try to get the last word,
>You can have that.
>but you'll find that I haven't complained,
>Other than the point where you complained about Richard reading attacks
into stuff that you didn't think contained any.

OK; you win, you've made it tiresome by twisting words.

--
Chris.
Jun 27 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
20155
by: dmstn | last post by:
Is it possible to add those options in Notepad ++ ? Your help would be appreciated very much. Thanks in advance.
4
2705
by: devgupta01 | last post by:
Hi all, I have simple program- "HelloWorld.java" to run at eclipse. Java Version 1.4.2 Eclipse Version 3.2 class HelloWorld { public static void main(String aa) {
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.